iro/offer/smstrade.py
changeset 312 42fd5075a5d1
parent 310 352850d4fb4b
equal deleted inserted replaced
311:81916344c63b 312:42fd5075a5d1
    20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    23 
    23 
    24 
    24 
    25 import urllib
    25 import urllib.request, urllib.parse
    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
   104            }
   104            }
   105     '''dict for standrd values of the smstrade api, it is used to get the right values to the API.'''
   105     '''dict for standrd values of the smstrade api, it is used to get the right values to the API.'''
   106 
   106 
   107     def __init__(self, name):
   107     def __init__(self, name):
   108         self.url = "https://gateway.smstrade.de"
   108         self.url = "https://gateway.smstrade.de"
   109         options =[("key", Option(lambda x,y:x,long="smstrade Gateway Key https://login.smstrade.de/index.php?gateway", must=True)),]
   109         options =[("key", Option(lambda x,y:x,int="smstrade Gateway Key https://login.smstrade.de/index.php?gateway", must=True)),]
   110         Provider.__init__(self, name, {"sms":["basic","economy","gold","direct"]},options)
   110         Provider.__init__(self, name, {"sms":["basic","economy","gold","direct"]},options)
   111 
   111 
   112     def send(self, route, recipient, sms):
   112     def send(self, route, recipient, sms):
   113         """send one SMS to recipient via route
   113         """send one SMS to recipient via route
   114 
   114 
   118         :return:
   118         :return:
   119             - All went ok -- :class:`iro.model.status.Status` object
   119             - All went ok -- :class:`iro.model.status.Status` object
   120             - otherwise -- an exception
   120             - otherwise -- an exception
   121         """
   121         """
   122         #logger.debug('smstrade.sendSMS(%s,%s)'%(sms,  recipient))
   122         #logger.debug('smstrade.sendSMS(%s,%s)'%(sms,  recipient))
   123 
       
   124         route = unicode(route)
       
   125 
   123 
   126         if recipient.land != '49' and route == "basic":
   124         if recipient.land != '49' and route == "basic":
   127             raise RejectRecipient(recipient)
   125             raise RejectRecipient(recipient)
   128 
   126 
   129         to ='00'+recipient.land+recipient.number
   127         to ='00'+recipient.land+recipient.number
   168             length += sms.content.count(s)
   166             length += sms.content.count(s)
   169         parameters["concat_sms"] = True if length > 160 else False
   167         parameters["concat_sms"] = True if length > 160 else False
   170 
   168 
   171         ps={}
   169         ps={}
   172         for p in parameters:
   170         for p in parameters:
   173             if p in self._params.keys():
   171             if p in list(self._params.keys()):
   174                 if self._params[p][0] == "boolean":
   172                 if self._params[p][0] == "boolean":
   175                     if parameters[p] != self._params[p][1]:
   173                     if parameters[p] != self._params[p][1]:
   176                         ps[p]=int(bool(parameters[p]))
   174                         ps[p]=int(bool(parameters[p]))
   177             else:
   175             else:
   178                 ps[p] = parameters[p]
   176                 ps[p] = parameters[p]
   179 
   177 
   180         params = urllib.urlencode(ps)
   178         params = urllib.parse.urlencode(ps)
   181         dp=copy.deepcopy(ps)
   179         dp=copy.deepcopy(ps)
   182         dp["key"]="<KEY>"
   180         dp["key"]="<KEY>"
   183         print 'smstrade._send-parameters:%s\n\t->%s'%(str(dp), urllib.urlencode(dp))
   181         print('smstrade._send-parameters:%s\n\t->%s'%(str(dp), urllib.parse.urlencode(dp)))
   184 
   182 
   185         response = urllib.urlopen(self.url, params)
   183         response = urllib.request.urlopen(self.url, params)
   186         data = response.readlines()
   184         data = response.readlines()
   187         print "result:%s"%(data)
   185         print("result:%s"%(data))
   188         if len(data) == 1:
   186         if len(data) == 1:
   189             return StatusCode(int(data[0]))
   187             return StatusCode(int(data[0]))
   190         return StatusCode(int(data[0]),exID=data[1].strip(),costs=data[2],count=data[3])
   188         return StatusCode(int(data[0]),exID=data[1].strip(),costs=data[2],count=data[3])
   191 
   189 
   192     def getSendFunc(self, typ, route):
   190     def getSendFunc(self, typ, route):