Extract phone parsing method

git-svn-id: https://svn.erp5.org/repos/experimental@2126 bc57dcba-3610-0410-ab4f-dc20bb96b918
parent 0875a117
...@@ -102,7 +102,7 @@ class EssendexGateway(XMLObject): ...@@ -102,7 +102,7 @@ class EssendexGateway(XMLObject):
subresult = {} subresult = {}
for part in parts: for part in parts:
data = part.split('=') data = part.split('=')
result[data[0]] = urllib.unquote(data[1].replace('\r','').replace('\n','')) subresult[data[0]] = urllib.unquote(data[1].replace('\r','').replace('\n',''))
result[index] = subresult result[index] = subresult
#Increment index for next #Increment index for next
index += 1 index += 1
...@@ -117,6 +117,11 @@ class EssendexGateway(XMLObject): ...@@ -117,6 +117,11 @@ class EssendexGateway(XMLObject):
assert not(phone.startswith('99000')) assert not(phone.startswith('99000'))
return phone return phone
security.declarePrivate("_parsePhoneNumber")
def _parsePhoneNumber(self,number):
"""Convert phone number for erp5 compliance"""
return "+%s(%s)-%s" % (number[0:2],0,number[2:])
security.declareProtected(Permissions.ManagePortal, 'send') security.declareProtected(Permissions.ManagePortal, 'send')
def send(self, text,recipient,sender=None, sender_title=None, def send(self, text,recipient,sender=None, sender_title=None,
message_type="text",test=False,**kw): message_type="text",test=False,**kw):
...@@ -271,19 +276,11 @@ class EssendexGateway(XMLObject): ...@@ -271,19 +276,11 @@ class EssendexGateway(XMLObject):
virtual number of the esendex account in use)}</To> virtual number of the esendex account in use)}</To>
</InboundMessage> </InboundMessage>
""" """
#Convert phone as erp5 compliant
def parsePhoneNumber(number):
#XXX: Should register well formatted number or brut number ?
#return number
return "+%s(%s)-%s" % (number[0:2],0,number[2:])
#Create the new sms in activities #Create the new sms in activities
self.activate(activity='SQLQueue').SMSTool_pushNewSMS( self.activate(activity='SQLQueue').SMSTool_pushNewSMS(
message_id=xml['MessageId'], message_id=xml['MessageId'],
sender=parsePhoneNumber(xml['From']), sender=self._parsePhoneNumber(xml['From']),
recipient=parsePhoneNumber(xml['To']), recipient=self._parsePhoneNumber(xml['To']),
text_content=xml['MessageText'], text_content=xml['MessageText'],
message_type='text/plain', message_type='text/plain',
reception_date=DateTime()) reception_date=DateTime())
...@@ -341,19 +338,18 @@ class EssendexGateway(XMLObject): ...@@ -341,19 +338,18 @@ class EssendexGateway(XMLObject):
if result['Result'] == "OK": if result['Result'] == "OK":
#Push all message #Push all message
type_mapping = {'Text': 'text/plain'} type_mapping = {'Text': 'text/plain'}
for key, value in result: for key, value in result.items():
if type(key) == int: if type(key) == int:
self.activate(activity='SQLQueue').SMSTool_pushNewSMS( self.activate(activity='SQLQueue').SMSTool_pushNewSMS(
message_id=value['ID'], message_id=value['ID'],
sender=parsePhoneNumber(value['Originator']), sender=self._parsePhoneNumber(value['Originator']),
recipient=parsePhoneNumber(value['Recipient']), recipient=self._parsePhoneNumber(value['Recipient']),
text_content=value['Body'], text_content=value['Body'],
message_type=type_mapping[value['Type']], message_type=type_mapping[value['Type']],
#To take in case value['ReceivedAt'], equal to "2011-05-03 10:23:16Z" #To take in case value['ReceivedAt'], equal to "2011-05-03 10:23:16Z"
reception_date=DateTime()) reception_date=DateTime())
elif result['Result'] == "Test": elif result['Result'] == "Test":
#Do nothing, we have log params LOG("EssendexGateway", INFO, result)
pass
elif result['Result'] == "Error": elif result['Result'] == "Error":
#we get an error when call the gateway #we get an error when call the gateway
raise SMSGatewayError, urllib.unquote(result.get('Message', "Impossible to get last message list")) raise SMSGatewayError, urllib.unquote(result.get('Message', "Impossible to get last message list"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment