Permalink
Browse files

Support MessageMedia.sendMulti()

  • Loading branch information...
1 parent 5829a63 commit 7c94d3e2eb7f29999349dfe6522a12927ec24079 @mludvig committed Feb 17, 2012
Showing with 15 additions and 13 deletions.
  1. +15 −13 Sms/Engines/MessageMedia.py
@@ -12,24 +12,22 @@
class SmsDriver(GenericSoap.SmsDriver):
url = 'http://soap.m4u.com.au/?wsdl'
- def send(self, message, recipient):
+ def sendMulti(self, message, recipients):
client = Client(self.url, cache = self.cache)
# Authentication
auth = client.factory.create('AuthenticationType')
auth.userId = self.options['username']
auth.password = self.options['password']
- # Message ID
- message_id = random.randint(100000000, 999999999)
-
# 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 = message_id
+ for recipient in recipients:
+ message_t.recipients.recipient.append(client.factory.create("RecipientType"))
+ message_t.recipients.recipient[-1].value = recipient
+ message_t.recipients.recipient[-1]._uid = random.randint(100000000, 999999999)
# Container for multiple messages
send_messages_t = client.factory.create("SendMessagesBodyType")
@@ -38,10 +36,14 @@ def send(self, message, recipient):
# Send it out
ret = client.service.sendMessages(auth, send_messages_t)
- if ret._sent > 0:
- info("SMS(MessageMedia) sent to %s with ID: %s" % (recipient, message_id))
- return message_id
- if ret._failed > 0:
- warning("SMS(MessageMedia) failed to %s: %s" % (recipient, ret.errors.error[0]._code))
+ error_recipients = []
+ for error in ret.errors.error:
+ for recipient in error.recipients.recipient:
+ warning("SMS(MessageMedia) failed to %s: %s" % (recipient.value, error._code))
+ error_recipients.append(recipient.value)
+
+ for recipient in message_t.recipients.recipient:
+ if recipient.value not in error_recipients:
+ info("SMS(MessageMedia) sent to %s with ID: %s" % (recipient.value, recipient._uid))
-# vim:et:ts=4:sts=4:ai
+# vim:et:sw=4:sts=4:ai:sta

0 comments on commit 7c94d3e

Please sign in to comment.