23 |
23 |
24 |
24 |
25 import urllib |
25 import urllib |
26 from functools import partial |
26 from functools import partial |
27 from decimal import Decimal |
27 from decimal import Decimal |
28 #import copy |
28 import copy |
29 |
29 |
30 from ..config import Option |
30 from ..config import Option |
31 from ..model.status import Status |
31 from ..model.status import Status |
32 from .provider import Provider, providers |
32 from .provider import Provider, providers |
33 from ..error import RejectRecipient, ExternalException |
33 from ..error import RejectRecipient, ExternalException |
66 """Class that represents the output of one smstrade request.""" |
66 """Class that represents the output of one smstrade request.""" |
67 def __init__(self,code, exID=None, costs=Decimal("0.0"), count=0): |
67 def __init__(self,code, exID=None, costs=Decimal("0.0"), count=0): |
68 self.code = code |
68 self.code = code |
69 |
69 |
70 self.exID = exID |
70 self.exID = exID |
71 self.costs = Decimal(costs) |
71 try: |
|
72 self.costs = Decimal(costs) |
|
73 except: |
|
74 if not costs.strip(): |
|
75 self.costs = Decimal("0.0") |
|
76 else: |
|
77 raise |
72 self.count = int(count) |
78 self.count = int(count) |
73 |
79 |
74 def __str__(self): |
80 def __str__(self): |
75 if self.code in statusCodes.keys(): |
81 if self.code in statusCodes.keys(): |
76 return "%i: %s"%(self.code, statusCodes[self.code]) |
82 return "%i: %s"%(self.code, statusCodes[self.code]) |
119 |
125 |
120 if recipient.land != '49' and route == "basic": |
126 if recipient.land != '49' and route == "basic": |
121 raise RejectRecipient(recipient) |
127 raise RejectRecipient(recipient) |
122 |
128 |
123 to ='00'+recipient.land+recipient.number |
129 to ='00'+recipient.land+recipient.number |
124 |
130 |
125 s = self.__send(route, to, sms) |
131 s = self.__send(route, to, sms) |
|
132 s.costs = Decimal('0.0728') |
126 if int(s) in (100,): |
133 if int(s) in (100,): |
127 return Status(self,route, exID=s.exID, costs=s.costs, count=s.count) |
134 return Status(self,route, exID=s.exID, costs=s.costs, count=s.count) |
128 elif int(s) in (70,71,): |
135 elif int(s) in (70,71,): |
129 raise RejectRecipient(recipient, status=s) |
136 raise RejectRecipient(recipient, status=s) |
130 else: |
137 else: |
169 ps[p]=int(bool(parameters[p])) |
176 ps[p]=int(bool(parameters[p])) |
170 else: |
177 else: |
171 ps[p] = parameters[p] |
178 ps[p] = parameters[p] |
172 |
179 |
173 params = urllib.urlencode(ps) |
180 params = urllib.urlencode(ps) |
174 #dp=copy.deepcopy(ps) |
181 dp=copy.deepcopy(ps) |
175 #dp["key"]="<KEY>" |
182 dp["key"]="<KEY>" |
176 #print 'smstrade._send-parameters:%s\n\t->%s'%(str(dp), urllib.urlencode(dp)) |
183 print 'smstrade._send-parameters:%s\n\t->%s'%(str(dp), urllib.urlencode(dp)) |
177 |
184 |
178 response = urllib.urlopen(self.url, params) |
185 response = urllib.urlopen(self.url, params) |
179 data = response.readlines() |
186 data = response.readlines() |
|
187 print "result:%s"%(data) |
180 if len(data) == 1: |
188 if len(data) == 1: |
181 return StatusCode(int(data[0])) |
189 return StatusCode(int(data[0])) |
182 return StatusCode(int(data[0]),exID=data[1],costs=data[2],count=data[3]) |
190 return StatusCode(int(data[0]),exID=data[1].strip(),costs=data[2],count=data[3]) |
183 |
191 |
184 def getSendFunc(self, typ, route): |
192 def getSendFunc(self, typ, route): |
185 """returns a partial :meth:`send` methed with bounded route, if typ and route is valid.""" |
193 """returns a partial :meth:`send` methed with bounded route, if typ and route is valid.""" |
186 |
194 |
187 Provider.getSendFunc(self, typ, route) |
195 Provider.getSendFunc(self, typ, route) |