2015-12-04 14:40:16 +00:00
|
|
|
from __future__ import unicode_literals
|
2016-01-14 14:55:07 +00:00
|
|
|
from client.notifications import NotificationsAPIClient
|
2015-12-04 14:40:16 +00:00
|
|
|
|
|
|
|
|
|
2016-01-14 14:55:07 +00:00
|
|
|
class NotificationsAdminAPIClient(NotificationsAPIClient):
|
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
# Fudge assert in the super __init__ so
|
|
|
|
|
# we can set those variables later.
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(NotificationsAdminAPIClient, self).__init__("api_url",
|
|
|
|
|
"client",
|
|
|
|
|
"secret")
|
|
|
|
|
|
|
|
|
|
def init_app(self, application):
|
2016-01-20 09:46:48 +00:00
|
|
|
self.base_url = application.config['API_HOST_NAME']
|
2016-01-15 15:15:35 +00:00
|
|
|
self.client_id = application.config['NOTIFY_API_CLIENT']
|
|
|
|
|
self.secret = application.config['NOTIFY_API_SECRET']
|
|
|
|
|
|
|
|
|
|
def create_service(self, service_name, active, limit, restricted, user_id):
|
2016-01-14 14:55:07 +00:00
|
|
|
"""
|
|
|
|
|
Create a service and return the json.
|
|
|
|
|
"""
|
|
|
|
|
data = {
|
|
|
|
|
"name": service_name,
|
|
|
|
|
"active": active,
|
|
|
|
|
"limit": limit,
|
2016-01-15 15:15:35 +00:00
|
|
|
"users": [user_id],
|
2016-01-14 14:55:07 +00:00
|
|
|
"restricted": restricted
|
|
|
|
|
}
|
|
|
|
|
return self.post("/service", data)
|
|
|
|
|
|
|
|
|
|
def delete_service(self, service_id):
|
|
|
|
|
"""
|
|
|
|
|
Delete a service.
|
|
|
|
|
"""
|
|
|
|
|
endpoint = "/service/{0}".format(service_id)
|
|
|
|
|
return self.delete(endpoint)
|
|
|
|
|
|
2016-01-19 10:23:08 +00:00
|
|
|
def get_service(self, service_id, *params):
|
|
|
|
|
"""
|
|
|
|
|
Retrieve a service.
|
|
|
|
|
"""
|
|
|
|
|
return self.get(
|
|
|
|
|
'/service/{0}'.format(service_id))
|
|
|
|
|
|
|
|
|
|
def get_services(self, *params):
|
|
|
|
|
"""
|
|
|
|
|
Retrieve a list of services.
|
|
|
|
|
"""
|
|
|
|
|
return self.get('/service', *params)
|
|
|
|
|
|
2016-01-14 14:55:07 +00:00
|
|
|
def update_service(self,
|
|
|
|
|
service_id,
|
|
|
|
|
service_name,
|
|
|
|
|
active,
|
|
|
|
|
limit,
|
2016-01-15 15:15:35 +00:00
|
|
|
restricted,
|
|
|
|
|
users):
|
2016-01-14 14:55:07 +00:00
|
|
|
"""
|
|
|
|
|
Update a service.
|
|
|
|
|
"""
|
|
|
|
|
data = {
|
|
|
|
|
"id": service_id,
|
|
|
|
|
"name": service_name,
|
|
|
|
|
"active": active,
|
|
|
|
|
"limit": limit,
|
2016-01-15 15:15:35 +00:00
|
|
|
"restricted": restricted,
|
|
|
|
|
"users": users
|
2016-01-14 14:55:07 +00:00
|
|
|
}
|
|
|
|
|
endpoint = "/service/{0}".format(service_id)
|
|
|
|
|
return self.put(endpoint, update_dict)
|
|
|
|
|
|
|
|
|
|
def create_service_template(self, name, type_, content, service_id):
|
|
|
|
|
"""
|
|
|
|
|
Create a service template.
|
|
|
|
|
"""
|
|
|
|
|
data = {
|
|
|
|
|
"name": name,
|
|
|
|
|
"template_type": type_,
|
|
|
|
|
"content": content,
|
|
|
|
|
"service": service_id
|
|
|
|
|
}
|
|
|
|
|
endpoint = "/service/{0}/template".format(service_id)
|
|
|
|
|
return self.post(endpoint, data)
|
|
|
|
|
|
2016-01-20 09:46:48 +00:00
|
|
|
def update_service_template(self, id_, name, type_, content, service_id):
|
|
|
|
|
"""
|
|
|
|
|
Update a service template.
|
|
|
|
|
"""
|
|
|
|
|
data = {
|
|
|
|
|
'id': id_,
|
|
|
|
|
'name': name,
|
|
|
|
|
'template_type': type_,
|
|
|
|
|
'content': content,
|
|
|
|
|
'service': service_id
|
|
|
|
|
}
|
|
|
|
|
endpoint = "/service/{0}/template/{1}".format(service_id, id_)
|
|
|
|
|
return self.put(endpoint, data)
|
|
|
|
|
|
2016-01-19 10:23:08 +00:00
|
|
|
def get_service_template(self, service_id, template_id, *params):
|
|
|
|
|
"""
|
|
|
|
|
Retrieve a service template.
|
|
|
|
|
"""
|
|
|
|
|
endpoint = '/service/{service_id}/template/{template_id}'.format(
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
template_id=template_id)
|
|
|
|
|
return self.get(endpoint, *params)
|
|
|
|
|
|
|
|
|
|
def get_service_templates(self, service_id, *params):
|
|
|
|
|
"""
|
|
|
|
|
Retrieve all templates for service.
|
|
|
|
|
"""
|
|
|
|
|
endpoint = '/service/{service_id}/template'.format(
|
|
|
|
|
service_id=service_id)
|
|
|
|
|
return self.get(endpoint, *params)
|
|
|
|
|
|
2016-01-14 14:55:07 +00:00
|
|
|
def delete_service_template(self, service_id, template_id):
|
|
|
|
|
"""
|
|
|
|
|
Delete a service template.
|
|
|
|
|
"""
|
|
|
|
|
endpoint = "/service/{0}/template/{1}".format(service_id, template_id)
|
|
|
|
|
return self.delete(endpoint)
|
2016-01-15 15:15:35 +00:00
|
|
|
|
|
|
|
|
# The implementation of these will change after the notifications-api
|
|
|
|
|
# functionality updates to include the ability to send notifications.
|
|
|
|
|
def send_sms(self,
|
|
|
|
|
mobile_number,
|
|
|
|
|
message,
|
|
|
|
|
job_id=None,
|
|
|
|
|
description=None):
|
2016-01-20 09:46:48 +00:00
|
|
|
self.send_sms_notification(mobile_number, message)
|
2016-01-15 15:15:35 +00:00
|
|
|
|
|
|
|
|
def send_email(self,
|
|
|
|
|
email_address,
|
|
|
|
|
message,
|
|
|
|
|
from_address,
|
|
|
|
|
subject,
|
|
|
|
|
job_id=None,
|
|
|
|
|
description=None):
|
|
|
|
|
pass
|