Inherit don’t duplicate API client constructor

This removes some code which is duplicative and obscure (ie it’s not
very clear why we do `"a" * 73` even though there is a Very Good Reason
for doing so).
This commit is contained in:
Chris Hill-Scott
2019-01-29 11:12:33 +00:00
parent eae0a5a632
commit 1d3a4e5043
22 changed files with 8 additions and 63 deletions

View File

@@ -16,6 +16,9 @@ class NotifyAdminAPIClient(BaseAPIClient):
redis_client = RedisClient()
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
self.base_url = app.config['API_HOST_NAME']
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']

View File

@@ -7,8 +7,6 @@ KEY_TYPE_TEST = 'test'
class ApiKeyApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_api_keys(self, service_id):
return self.get(url='/service/{}/api-keys'.format(service_id))

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class BillingAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_billable_units_ft(self, service_id, year):
return self.get(

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class ComplaintApiClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_all_complaints(self, page=1):
params = {'page': page}

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, cache
class EmailBrandingClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
@cache.set('email_branding-{branding_id}')
def get_email_branding(self, branding_id):
return self.get(url='/email-branding/{}'.format(branding_id))

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class EventsApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def create_event(self, event_type, event_data):
data = {

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class InboundNumberClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_available_inbound_sms_numbers(self):
return self.get(url='/inbound-number/available')

View File

@@ -6,8 +6,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class InviteApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)

View File

@@ -18,9 +18,6 @@ class JobApiClient(NotifyAdminAPIClient):
NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {'scheduled', 'cancelled'}
def __init__(self):
super().__init__("a" * 73, "b")
@staticmethod
def __convert_statistics(job):
results = defaultdict(int)

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class LetterBrandingClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_letter_branding(self):
return self.get(url='/dvla_organisations')

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class LetterJobsClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def submit_returned_letters(self, references):
return self.post(
url='/letters/returned',

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class NotificationApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_notifications_for_service(
self,

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class OrgInviteApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class OrganisationsClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_organisations(self):
return self.get(url='/organisations')

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class PlatformStatsAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_aggregate_platform_stats(self, params_dict=None):
return self.get("/platform-stats", params=params_dict)

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class ProviderClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_all_providers(self):
return self.get(

View File

@@ -3,10 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class ServiceAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
@cache.delete('user-{user_id}')
def create_service(

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class StatusApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_status(self, *params):
return self.get(url='/_status', *params)

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient, cache
class TemplateFolderAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__('a' * 73, 'b')
@cache.delete('service-{service_id}-template-folders')
def create_template_folder(

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class TemplateStatisticsApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_template_statistics_for_service(self, service_id, limit_days=None):
params = {}

View File

@@ -18,8 +18,6 @@ ALLOWED_ATTRIBUTES = {
class UserApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)