Implemented the post email notifications endpoint for v2

This commit is contained in:
Rebecca Law
2016-11-14 13:56:09 +00:00
parent eb17822564
commit b0ee09a9f6
7 changed files with 262 additions and 28 deletions

View File

@@ -7,16 +7,16 @@ post_sms_request = {
"title": "POST v2/notifications/sms",
"properties": {
"reference": {"type": "string"},
"phone_number": {"type": "string", "format": "sms"},
"phone_number": {"type": "string", "format": "phone_number"},
"template_id": uuid,
"personalisation": personalisation
},
"required": ["phone_number", "template_id"]
}
content = {
sms_content = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "POST sms notification response schema",
"description": "content schema for SMS notification response schema",
"type": "object",
"title": "notification content",
"properties": {
@@ -29,7 +29,7 @@ content = {
# this may belong in a templates module
template = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "POST sms notification response schema",
"description": "template schema",
"type": "object",
"title": "notification content",
"properties": {
@@ -48,7 +48,50 @@ post_sms_response = {
"properties": {
"id": uuid,
"reference": {"type": "string"},
"content": content,
"content": sms_content,
"uri": {"type": "string"},
"template": template
},
"required": ["id", "content", "uri", "template"]
}
post_email_request = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "POST email notification schema",
"type": "object",
"title": "POST v2/notifications/email",
"properties": {
"reference": {"type": "string"},
"email_address": {"type": "string", "format": "email_address"},
"template_id": uuid,
"personalisation": personalisation
},
"required": ["email_address", "template_id"]
}
email_content = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Email content for POST email notification",
"type": "object",
"title": "notification email content",
"properties": {
"from_email": {"type": "string", "format": "email_address"},
"body": {"type": "string"},
"subject": {"type": "string"}
},
"required": ["body"]
}
post_email_response = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "POST sms notification response schema",
"type": "object",
"title": "response v2/notifications/email",
"properties": {
"id": uuid,
"reference": {"type": "string"},
"content": email_content,
"uri": {"type": "string"},
"template": template
},
@@ -62,7 +105,27 @@ def create_post_sms_response_from_notification(notification, body, from_number,
"content": {'body': body,
'from_number': from_number},
"uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)),
"template": {"id": notification.template_id,
"version": notification.template_version,
"uri": "{}/v2/templates/{}".format(url_root, str(notification.template_id))}
"template": __create_template_from_notification(notification=notification, url_root=url_root)
}
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root):
return {
"id": notification.id,
"reference": notification.reference,
"content": {
"from_email": email_from,
"body": content,
"subject": subject
},
"uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)),
"template": __create_template_from_notification(notification=notification, url_root=url_root)
}
def __create_template_from_notification(notification, url_root):
return {
"id": notification.template_id,
"version": notification.template_version,
"uri": "{}/v2/templates/{}".format(url_root, str(notification.template_id))
}