Skip to content

Commit

Permalink
Fixed xml message retention bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Rune Hansen committed Feb 9, 2012
1 parent 6375c80 commit 1888f80
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pswinclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,29 @@ def __init__(self, template, username, password, multi=False):
self._xml = []

def buildxml(self, kwargs):
"""Legacy API"""
self.xml = kwargs

@property
def xml(self):
try:
return "".join(self.tpl.format(SMSMessage="\n".join(self._xml).encode('utf-8')))
finally:
del self.xml

@xml.setter
def xml(self, kwargs):
_msg = self.smsmessage.format(**kwargs)
if self.multi:
_msg = self.messagecontainer.format(SMSMessage=_msg).encode('utf-8')
self._xml.append(_msg)
self._xml.append(_msg)
else:
self._xml = [_msg]

@property
@xml.deleter
def xml(self):
return "".join(self.tpl.format(SMSMessage="\n".join(self._xml).encode('utf-8')))

self._xml = []

class SOAPClient(object):
"""Sets up SOAP communication"""
Expand Down Expand Up @@ -186,10 +200,10 @@ def _multi_soapenvelope(self):
sms_message = EnvelopeBuilder(SendSingleMessage, "<PSWinCom-username>", "<PSWinCom-Password>")
sms_message.buildxml(dict(reciever="47<phone number>",
sender="<Your ref>",
message="<Your message string>",
message=u"<Your message string>",
reciept="false"))

soap_client = SOAPClient('sms.pswin.com','/SOAP/SMS.asmx', sms_message.xml)
statuscode, envelope_response = soap_client.send()

#
print statuscode, envelope_response

0 comments on commit 1888f80

Please sign in to comment.