Pass notification ID to fire text as our reference

- also handle fire text errors, non-zero response code means error.
This commit is contained in:
Martyn Inglis
2016-03-10 13:22:45 +00:00
parent 209244ff19
commit c580b9c084
3 changed files with 44 additions and 11 deletions

View File

@@ -203,8 +203,9 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
)
client.send_sms(
notification['to'],
template.replaced
to=notification['to'],
content=template.replaced,
notification_id=notification_id
)
except FiretextClientException as e:
current_app.logger.exception(e)

View File

@@ -11,7 +11,12 @@ logger = logging.getLogger(__name__)
class FiretextClientException(SmsClientException):
pass
def __init__(self, response):
self.code = response['code']
self.description = response['description']
def __str__(self):
return "Code {} description {}".format(self.code, self.description)
class FiretextClient(SmsClient):
@@ -28,7 +33,7 @@ class FiretextClient(SmsClient):
def get_name(self):
return self.name
def send_sms(self, to, content):
def send_sms(self, to, content, notification_id=None):
data = {
"apiKey": self.api_key,
@@ -37,13 +42,21 @@ class FiretextClient(SmsClient):
"message": content
}
if notification_id:
data.update({
"reference": notification_id
})
start_time = monotonic()
try:
start_time = monotonic()
response = request(
"POST",
"https://www.firetext.co.uk/api/sendsms",
"https://www.firetext.co.uk/api/sendsms/json",
data=data
)
firetext_response = response.json()
if firetext_response['code'] != 0:
raise FiretextClientException(firetext_response)
response.raise_for_status()
except RequestException as e:
api_error = HTTPError.create(e)