Permalink
Browse files

More user-friendly cofig for Clickatell

Instead of specifying the url_pattern it now requires
the api_id, user and password options
  • Loading branch information...
1 parent 62c53b8 commit 5829a63b93328b9a95b40e697817f28b76705fa0 @mludvig committed Feb 17, 2012
Showing with 39 additions and 7 deletions.
  1. +3 −1 Sms/Engines/Clickatell.py
  2. +20 −3 Sms/Engines/GenericHttp.py
  3. +16 −3 sms-cli.conf.template
@@ -7,8 +7,10 @@
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 send(self, message, recipient):
- ret = super(self.__class__, self).send(message, recipient)
+ ret = GenericHttp.SmsDriver.send(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]))
View
@@ -7,13 +7,30 @@
from Sms.Exceptions import *
from Sms.GenericSmsDriver import GenericSmsDriver
+from Sms.Logger import *
class SmsDriver(GenericSmsDriver):
+ url_pattern = None
+
+ def __init__(self, options):
+ ret = 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 send(self, message, recipient):
- url = self.options['url_pattern'].strip('"\'') % { 'message' : urllib.quote(message), 'recipient' : recipient }
+ all_options = { 'message' : urllib.quote(message), 'recipient' : recipient }
+ all_options.update(self.options)
+ url = self.url_pattern % all_options
+ debug("GenericHttp: url: %s" % url)
u = urllib2.urlopen(url)
+ debug("GenericHttp: ret_code: %s" % u.code)
if u.code != 200:
raise SmsError("HTTP Return code = %d" % u.code)
- return u.read()
+ ret_data = u.read()
+ debug("GenericHttp: ret_data: %s" % ret_data)
+ return ret_data
-# vim:et:ts=4:sts=4:ai
+# vim: et:sw=4:sts=4:sta:ai:
View
@@ -1,10 +1,23 @@
+## Template for sms-cli configuration file.
+## Copy it to ~/.sms-cli.conf and fill in
+## your login details.
+
+[default]
+## Generic HTTP-based API
+engine = GenericHttp
+url_pattern = "https://sms.provider.com/http/sendmsg?user=XXXXX&password=XXXXX&to=%(recipient)s&text=%(message)s"
+
[clickatell]
-# Clickatell gateway - http://clickatell.com
+## Clickatell gateway - http://clickatell.com
engine = "Clickatell"
-url_pattern = "https://api.clickatell.com/http/sendmsg?api_id=XXXXX&user=XXXXX&password=XXXXX&from=XXXXX&to=%(recipient)s&text=%(message)s&concat=3"
+user = "XXXXX"
+password = "XXXXX"
+api_id = "XXXXX"
+## Optional parameters
+#extras = "from=XXXXX&concat=3&..."
[messagemedia]
-# Message Media gateway - http://message-media.com
+## Message Media gateway - http://message-media.com
engine = "MessageMedia"
username = "XXXXX"
password = "XXXXX"

0 comments on commit 5829a63

Please sign in to comment.