Permalink
Browse files

Properly report failures for Clickatell

  • Loading branch information...
1 parent 794982a commit 05dcb609ce8ff4a7646320b213d21759a3fd14a6 @mludvig committed Feb 17, 2012
Showing with 11 additions and 8 deletions.
  1. +5 −4 Sms/Engines/Clickatell.py
  2. +2 −2 Sms/Engines/GenericHttp.py
  3. +3 −0 Sms/Engines/MessageMedia.py
  4. +1 −2 Sms/Sender.py
@@ -2,19 +2,20 @@
## http://www.logix.cz/michal/devel/sms-cli
## License: GPL Version 2
-from logging import debug, info
+from Sms.Logger import *
from Sms.Exceptions import SmsError
import GenericHttp
class SmsDriver(GenericHttp.SmsDriver):
url_pattern = "https://api.clickatell.com/http/sendmsg?api_id=%(api_id)s&user=%(user)s&password=%(password)s&to=%(recipient)s&text=%(message)s"
def sendOne(self, message, recipient):
+ debug("Clickatell.sendOne(%s)" % recipient)
ret = GenericHttp.SmsDriver.sendOne(self, message, recipient)
arr = ret.split("\n")[0].split(" ", 1)
if arr[0].startswith("ID"):
info("SMS(Clickatell) sent to %s with ID: %s" % (recipient, arr[1]))
- return arr[1]
- raise SmsError("SMS(Clickatell): %s" % arr[1])
+ else:
+ warning("SMS(Clickatell) failed to %s: %s" % (recipient, ret))
-# vim:et:ts=4:sts=4:ai
+# vim: et:sw=4:sts=4:sta:ai:
@@ -13,14 +13,15 @@ class SmsDriver(GenericSmsDriver):
url_pattern = None
def __init__(self, options):
- ret = GenericSmsDriver.__init__(self, options)
+ GenericSmsDriver.__init__(self, options)
if not self.url_pattern:
try:
self.url_pattern = self.options['url_pattern'].strip('"\'')
except KeyError, e:
raise SmsConfigError("GenericHttp driver requires 'url_pattern' option")
def sendOne(self, message, recipient):
+ debug("GenericHttp.sendOne(%s)" % recipient)
all_options = { 'message' : urllib.quote(message), 'recipient' : recipient }
all_options.update(self.options)
url = self.url_pattern % all_options
@@ -31,7 +32,6 @@ def sendOne(self, message, recipient):
raise SmsError("HTTP Return code = %d" % u.code)
ret_data = u.read()
debug("GenericHttp: ret_data: %s" % ret_data)
- raise
return ret_data
# vim: et:sw=4:sts=4:sta:ai:
@@ -13,6 +13,9 @@ class SmsDriver(GenericSoap.SmsDriver):
url = 'http://soap.m4u.com.au/?wsdl'
def sendMulti(self, message, recipients):
+ debug("MessageMedia.sendMulti([%s])" % ", ".join(recipients))
+
+ # Soap Client
client = Client(self.url, cache = self.cache)
# Authentication
View
@@ -41,7 +41,6 @@ def send(self, message = None, recipients = []):
try:
self._driver.sendMulti(message, recipients)
except AttributeError:
- raise
for recipient in recipients:
self._driver.sendOne(message, recipient)
except SmsError, e:
@@ -50,4 +49,4 @@ def send(self, message = None, recipients = []):
return True
-# vim:et:ts=4:sts=4:ai
+# vim: et:sw=4:sts=4:sta:ai:

0 comments on commit 05dcb60

Please sign in to comment.