Browse files

Initial support for MessageMedia engine

  • Loading branch information...
1 parent 0359afb commit e8d503d5348dd19696b7db12ec0517ed2096cadb @mludvig committed Feb 16, 2012
Showing with 64 additions and 0 deletions.
  1. +23 −0 Sms/Engines/GenericSoap.py
  2. +41 −0 Sms/Engines/MessageMedia.py
View
23 Sms/Engines/GenericSoap.py
@@ -0,0 +1,23 @@
+## Michal Ludvig <mludvig@logix.net.nz>
+## http://www.logix.cz/michal/devel/sms-cli
+## License: GPL Version 2
+
+import os
+import logging
+from Sms.Exceptions import *
+from Sms.GenericSmsDriver import GenericSmsDriver
+
+try:
+ from suds.client import ObjectCache
+except ImportError, e:
+ raise SmsError("Module 'suds' not found. Please install python-suds package.")
+
+class SmsDriver(GenericSmsDriver):
+ cache = None
+ def __init__(self, options = {}):
+ GenericSmsDriver.__init__(self, options)
+ self.cache = ObjectCache()
+ self.cache.setlocation(location = "/tmp/sms-cli.suds.%d" % os.getuid())
+ self.cache.setduration(days = 10)
+
+# vim:et:ts=4:sts=4:ai
View
41 Sms/Engines/MessageMedia.py
@@ -0,0 +1,41 @@
+## Michal Ludvig <mludvig@logix.net.nz>
+## http://www.logix.cz/michal/devel/sms-cli
+## License: GPL Version 2
+
+from Sms.Logger import *
+from Sms.Exceptions import SmsError
+import GenericSoap
+
+from suds.client import Client
+
+class SmsDriver(GenericSoap.SmsDriver):
+ url = 'http://soap.m4u.com.au/?wsdl'
+
+ def send(self, message, recipient):
+ client = Client(self.url, cache = self.cache)
+
+ # Authentication
+ auth = client.factory.create('AuthenticationType')
+ auth.userId = self.options['username']
+ auth.password = self.options['password']
+
+ # Message Type
+ message_t = client.factory.create("MessageType")
+ message_t.content = message
+ message_t.deliveryReport = True
+ message_t.recipients.recipient.append(client.factory.create("RecipientType"))
+ message_t.recipients.recipient[-1].value = recipient
+ # message_t.recipients.recipient[-1]._uid = recipient + rand()
+
+ # Container for multiple messages
+ send_messages_t = client.factory.create("SendMessagesBodyType")
+ send_messages_t.messages.message.append(message_t)
+
+ print send_messages_t
+
+ # Send it out
+ ret = client.service.sendMessages(auth, send_messages_t)
+
+ print ret
+
+# vim:et:ts=4:sts=4:ai

0 comments on commit e8d503d

Please sign in to comment.