2017-06-22 15:56:05 +01:00
|
|
|
from app.notify_client import _attach_current_user, NotifyAdminAPIClient
|
2016-03-02 13:52:05 +00:00
|
|
|
|
|
|
|
|
|
2016-11-30 17:01:44 +00:00
|
|
|
class NotificationApiClient(NotifyAdminAPIClient):
|
2016-09-12 12:14:57 +01:00
|
|
|
def __init__(self):
|
2017-07-26 10:23:39 +01:00
|
|
|
super().__init__("a" * 73, "b")
|
2016-03-02 13:52:05 +00:00
|
|
|
|
|
|
|
|
def init_app(self, app):
|
|
|
|
|
self.base_url = app.config['API_HOST_NAME']
|
2017-07-26 12:03:14 +01:00
|
|
|
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
|
|
|
|
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
2016-03-02 13:52:05 +00:00
|
|
|
|
2016-09-21 09:28:06 +01:00
|
|
|
def get_notifications_for_service(
|
|
|
|
|
self,
|
|
|
|
|
service_id,
|
|
|
|
|
job_id=None,
|
|
|
|
|
template_type=None,
|
|
|
|
|
status=None,
|
|
|
|
|
page=None,
|
|
|
|
|
page_size=None,
|
2016-09-21 09:32:20 +01:00
|
|
|
limit_days=None,
|
|
|
|
|
include_jobs=None,
|
2017-04-20 14:57:31 +01:00
|
|
|
include_from_test_key=None,
|
2017-05-30 12:55:13 +01:00
|
|
|
format_for_csv=None,
|
|
|
|
|
to=None,
|
2016-09-21 09:28:06 +01:00
|
|
|
):
|
2016-03-02 13:52:05 +00:00
|
|
|
params = {}
|
|
|
|
|
if page is not None:
|
|
|
|
|
params['page'] = page
|
2016-04-19 11:45:36 +01:00
|
|
|
if page_size is not None:
|
|
|
|
|
params['page_size'] = page_size
|
2016-04-04 16:34:06 +01:00
|
|
|
if template_type is not None:
|
|
|
|
|
params['template_type'] = template_type
|
|
|
|
|
if status is not None:
|
|
|
|
|
params['status'] = status
|
2016-09-21 09:32:20 +01:00
|
|
|
if include_jobs is not None:
|
|
|
|
|
params['include_jobs'] = include_jobs
|
|
|
|
|
if include_from_test_key is not None:
|
|
|
|
|
params['include_from_test_key'] = include_from_test_key
|
2017-04-20 14:57:31 +01:00
|
|
|
if format_for_csv is not None:
|
|
|
|
|
params['format_for_csv'] = format_for_csv
|
2017-05-30 12:55:13 +01:00
|
|
|
if to is not None:
|
|
|
|
|
params['to'] = to
|
2016-03-02 13:52:05 +00:00
|
|
|
if job_id:
|
|
|
|
|
return self.get(
|
|
|
|
|
url='/service/{}/job/{}/notifications'.format(service_id, job_id),
|
|
|
|
|
params=params
|
|
|
|
|
)
|
|
|
|
|
else:
|
2016-04-28 15:50:05 +01:00
|
|
|
if limit_days is not None:
|
|
|
|
|
params['limit_days'] = limit_days
|
|
|
|
|
|
2016-03-02 13:52:05 +00:00
|
|
|
return self.get(
|
|
|
|
|
url='/service/{}/notifications'.format(service_id),
|
|
|
|
|
params=params
|
|
|
|
|
)
|
2017-05-24 13:19:31 +01:00
|
|
|
|
2017-06-26 17:09:51 +01:00
|
|
|
def send_notification(self, service_id, *, template_id, recipient, personalisation):
|
2017-06-22 15:56:05 +01:00
|
|
|
data = {
|
|
|
|
|
'template_id': template_id,
|
|
|
|
|
'to': recipient,
|
|
|
|
|
'personalisation': personalisation,
|
|
|
|
|
}
|
|
|
|
|
data = _attach_current_user(data)
|
|
|
|
|
return self.post(url='/service/{}/send-notification'.format(service_id), data=data)
|
|
|
|
|
|
2017-06-19 12:31:14 +01:00
|
|
|
def get_notification(self, service_id, notification_id):
|
2017-06-12 17:21:25 +01:00
|
|
|
return self.get(url='/service/{}/notifications/{}'.format(service_id, notification_id))
|