From aff22e51d82953d8b9ef131aa8bbad29c8a02d3b Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Mon, 12 Sep 2011 17:37:37 -0700 Subject: [PATCH] use string status codes instead of integers --- server/php/KalSMS.php | 19 +++++++++++--- server/php/example/outgoing_sms/.gitignore | 1 + src/org/envaya/kalsms/App.java | 6 ++--- .../envaya/kalsms/MessageStatusNotifier.java | 25 +++++++++---------- 4 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 server/php/example/outgoing_sms/.gitignore diff --git a/server/php/KalSMS.php b/server/php/KalSMS.php index 3c9a39d..bc11040 100755 --- a/server/php/KalSMS.php +++ b/server/php/KalSMS.php @@ -13,9 +13,9 @@ class KalSMS const ACTION_SEND_STATUS = 'send_status'; const ACTION_TEST = 'test'; - const STATUS_QUEUED = 1; - const STATUS_FAILED = 2; - const STATUS_SENT = 3; + const STATUS_QUEUED = 'queued'; + const STATUS_FAILED = 'failed'; + const STATUS_SENT = 'sent'; static function new_from_request() { @@ -29,7 +29,18 @@ class KalSMS return htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } + private $request_action; + function get_request_action() + { + if (!$this->request_action) + { + $this->request_action = $this->_get_request_action(); + } + return $this->request_action; + } + + private function _get_request_action() { switch (@$_POST['action']) { @@ -171,7 +182,7 @@ class KalSMS_Action_SendStatus extends KalSMS_Action function __construct($type) { $this->type = KalSMS::ACTION_SEND_STATUS; - $this->status = (int)$_POST['status']; + $this->status = $_POST['status']; $this->id = $_POST['id']; } } \ No newline at end of file diff --git a/server/php/example/outgoing_sms/.gitignore b/server/php/example/outgoing_sms/.gitignore new file mode 100644 index 0000000..94a2dd1 --- /dev/null +++ b/server/php/example/outgoing_sms/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file diff --git a/src/org/envaya/kalsms/App.java b/src/org/envaya/kalsms/App.java index 7300214..3388ee5 100755 --- a/src/org/envaya/kalsms/App.java +++ b/src/org/envaya/kalsms/App.java @@ -31,9 +31,9 @@ public class App { public static final String ACTION_SEND_STATUS = "send_status"; public static final String ACTION_TEST = "test"; - public static final int STATUS_QUEUED = 1; - public static final int STATUS_FAILED = 2; - public static final int STATUS_SENT = 3; + public static final String STATUS_QUEUED = "queued"; + public static final String STATUS_FAILED = "failed"; + public static final String STATUS_SENT = "sent"; public static final String LOG_NAME = "KALSMS"; public static final String LOG_INTENT = "org.envaya.kalsms.LOG"; diff --git a/src/org/envaya/kalsms/MessageStatusNotifier.java b/src/org/envaya/kalsms/MessageStatusNotifier.java index f059a80..b4b6da0 100755 --- a/src/org/envaya/kalsms/MessageStatusNotifier.java +++ b/src/org/envaya/kalsms/MessageStatusNotifier.java @@ -15,20 +15,20 @@ public class MessageStatusNotifier extends BroadcastReceiver { private App app; - public void notifyStatus(String serverId, int status, String errorMessage) + public void notifyStatus(String serverId, String status, String errorMessage) { String logMessage; - switch (status) + if (status.equals(App.STATUS_SENT)) { - case App.STATUS_SENT: - logMessage = "sent successfully"; - break; - case App.STATUS_FAILED: - logMessage = "could not be sent (" + errorMessage + ")"; - break; - default: - logMessage = "queued"; - break; + logMessage = "sent successfully"; + } + else if (status.equals(App.STATUS_FAILED)) + { + logMessage = "could not be sent (" + errorMessage + ")"; + } + else + { + logMessage = "queued"; } String smsDesc = serverId == null ? "SMS reply" : ("SMS id=" + serverId); @@ -37,9 +37,8 @@ public class MessageStatusNotifier extends BroadcastReceiver { app.log("Notifying server " + smsDesc + " " + logMessage); new HttpTask(app).execute( - new BasicNameValuePair("from", app.getPhoneNumber()), new BasicNameValuePair("id", serverId), - new BasicNameValuePair("status", "" + status), + new BasicNameValuePair("status", status), new BasicNameValuePair("error", errorMessage), new BasicNameValuePair("action", App.ACTION_SEND_STATUS) );