Matthew Schinckel avatar Matthew Schinckel committed c20c9e7

Add support for 5centsms.com.au API

Comments (0)

Files changed (2)

sms/models/gateway.py

             message.status_message = status_msg.split(': ')[1]
         else:
             message.status = "Sent"
-            message.gateway_message_id = re.match(self.success_format, status_msg).groupdict()['gateway_message_id'].strip()
+            parsed_response = re.match(self.success_format, status_msg).groupdict()
+            if 'gateway_message_id' in parsed_response and parsed_response['gateway_message_id']:
+                message.gateway_message_id = parsed_response['gateway_message_id'].strip()
+            if 'status_code' in parsed_response and parsed_response['status_code']:
+                message.status = self.status_mapping.get(parsed_response['status_code'])
+            if 'status_message' in parsed_response and parsed_response['status_message']:
+                message.status_message = parsed_response['status_message']
             logging.debug("Gateway MSG ID %s [%i]" % (message.gateway_message_id, len(message.gateway_message_id)))
             message.send_date = datetime.datetime.now()
         
         msg.status = gateway.status_mapping[data.get(gateway.status_status)]
     logger.debug("Updated status to %s" % msg.status)
     if msg.status == "Delivered":
-        if gateway.status_date_format:
-            msg.delivery_date = datetime.datetime.strptime(
-                data.get(gateway.status_date),
-                gateway.status_date_format,
-            )
+        if gateway.status_date:
+            if gateway.status_date_format:
+                msg.delivery_date = datetime.datetime.strptime(
+                    data.get(gateway.status_date),
+                    gateway.status_date_format,
+                )
+            else:
+                msg.delivery_date = datetime.datetime.fromtimestamp(
+                    float(data.get(gateway.status_date))
+                )
         else:
-            msg.delivery_date = datetime.datetime.fromtimestamp(
-                float(data.get(gateway.status_date))
-            )
+            msg.delivery_date = datetime.datetime.now()
         logger.debug("Message was delivered at %s" % msg.delivery_date)
     else:
         msg.status_message = data.get(gateway.status_error_code)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.