def get_notification_by_to_field(template_id, api_key, sent_to, statuses=None): client = NotificationsAPIClient(base_url=config['notify_api_url'], api_key=api_key) resp = client.get('v2/notifications') for notification in resp['notifications']: t_id = notification['template']['id'] to = notification['email_address'] or notification['phone_number'] if t_id == template_id and to == sent_to and ( not statuses or notification['status'] in statuses): return notification['body'] return ''
def get_notification_via_api(service_id, template_id, api_key, sent_to): client = NotificationsAPIClient(base_url=Config.NOTIFY_API_URL, service_id=service_id, api_key=api_key) resp = client.get("notifications", params={"include_jobs": True}) for notification in resp["notifications"]: t_id = notification["template"]["id"] to = notification["to"] status = notification["status"] if t_id == template_id and to == sent_to and status in ["sending", "delivered"]: return notification["body"] message = "Could not find notification with template {} to {} with a status of sending or delivered".format( template_id, sent_to ) raise RetryException(message)
class ServiceApiClient: def __init__(self): self.api_client = None def init_app(self, application): self.api_client = NotificationsAPIClient(base_url=application.config['API_HOST_NAME'], api_key='a' * 75) self.api_client.service_id = application.config['ADMIN_CLIENT_USER_NAME'] self.api_client.api_key = application.config['ADMIN_CLIENT_SECRET'] def get_service(self, service_id): """ Retrieve a service. """ return self.api_client.get('/service/{0}'.format(service_id))