Add process_mmg_responses

Refactor process_firetext_responses
Removed the abstract ClientResponses for firetext and mmg. There is a map for each response to handle the status codes sent by each client.
Since MMG has about 20 different status code, none of which seem to be a pending state (unlike firetext that has 3 status one for pending - network delay).
For MMG status codes, look for 00 as successful, everything else is assumed to be a failure.
This commit is contained in:
Rebecca Law
2016-04-06 14:31:33 +01:00
parent f2ee8f3eb7
commit 4806123d5c
11 changed files with 343 additions and 191 deletions

View File

@@ -6,34 +6,34 @@ from app.clients.sms import (
)
from flask import current_app
from requests import request, RequestException, HTTPError
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
from app.clients import STATISTICS_DELIVERED, STATISTICS_FAILURE
logger = logging.getLogger(__name__)
firetext_responses = {
'0': {
"message": 'Delivered',
"notification_statistics_status": STATISTICS_DELIVERED,
"success": True,
"notification_status": 'delivered'
},
'1': {
"message": 'Declined',
"success": False,
"notification_statistics_status": STATISTICS_FAILURE,
"notification_status": 'failed'
},
'2': {
"message": 'Undelivered (Pending with Network)',
"success": False,
"notification_statistics_status": None,
"notification_status": 'sent'
}
}
class FiretextResponses(ClientResponse):
def __init__(self):
ClientResponse.__init__(self)
self.__response_model__ = {
'0': {
"message": 'Delivered',
"notification_statistics_status": STATISTICS_DELIVERED,
"success": True,
"notification_status": 'delivered'
},
'1': {
"message": 'Declined',
"success": False,
"notification_statistics_status": STATISTICS_FAILURE,
"notification_status": 'failed'
},
'2': {
"message": 'Undelivered (Pending with Network)',
"success": False,
"notification_statistics_status": None,
"notification_status": 'sent'
}
}
def get_firetext_responses(status):
return firetext_responses[status]
class FiretextClientException(SmsClientException):

View File

@@ -1,33 +1,27 @@
from flask import current_app
from monotonic import monotonic
from requests import (request, RequestException, HTTPError)
from app.clients import (ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE)
from app.clients import (STATISTICS_DELIVERED, STATISTICS_FAILURE)
from app.clients.sms import (SmsClient, SmsClientException)
mmg_response_map = {
'00': {
"message": 'Delivered',
"notification_statistics_status": STATISTICS_DELIVERED,
"success": True,
"notification_status": 'delivered'
},
'default': {
"message": 'Declined',
"success": False,
"notification_statistics_status": STATISTICS_FAILURE,
"notification_status": 'failed'
}
}
class FiretextResponses(ClientResponse):
def __init__(self):
ClientResponse.__init__(self)
self.__response_model__ = {
'0': {
"message": 'Delivered',
"notification_statistics_status": STATISTICS_DELIVERED,
"success": True,
"notification_status": 'delivered'
},
'1': {
"message": 'Declined',
"success": False,
"notification_statistics_status": STATISTICS_FAILURE,
"notification_status": 'failed'
},
'2': {
"message": 'Undelivered (Pending with Network)',
"success": False,
"notification_statistics_status": None,
"notification_status": 'sent'
}
}
def get_mmg_responses(status):
return mmg_response_map.get(status, mmg_response_map.get('default'))
class MMGClientException(SmsClientException):