diff -r d0de2ca7201a -r e8d56537c9cc iro/offer/smstrade.py --- a/iro/offer/smstrade.py Sun Mar 25 20:11:34 2012 +0200 +++ b/iro/offer/smstrade.py Sun Mar 25 20:14:35 2012 +0200 @@ -38,9 +38,11 @@ 90 : "Versand nicht moeglich.", 100 : "SMS wurde versendet.", } +"""statuscodes of external smstrade API""" class SmstradeException(ExternalException): + """An excetion that connects the status code with the excetion string (see :attr:`statusCodes`)""" def __init__(self,status): ExternalException.__init__(self) self.status = status @@ -51,25 +53,32 @@ class StatusCode: - def __init__(self,code, exID=None, costs=Decimal("0.0"), count=0): + """Class that represents the output of one smstrade request.""" + def __init__(self,code, exID=None, costs=Decimal("0.0"), count=0): self.code = code self.exID = exID self.costs = Decimal(costs) self.count = int(count) - def __str__(self): + def __str__(self): if self.code in statusCodes.keys(): return "%i: %s"%(self.code, statusCodes[self.code]) return "%i: unknown statuscode."%self.code - def __int__(self): + def __int__(self): return self.code class Smstrade(Provider): - """ - s. auch http://kundencenter.smstrade.de/sites/smstrade.de.kundencenter/__pdf/SMS-Gateway_HTTP_API_v2.pdf + """A Provider to send SMS to recipients using smstrade. + Smstrade only supports to send SMS and four diffrent routes: ``["basic","economy","gold","direct"]``. + + It needs a smstrade Gateway Key https://login.smstrade.de/index.php?gateway in configuration file. + + smstrade API documentation: http://kundencenter.smstrade.de/sites/smstrade.de.kundencenter/__pdf/SMS-Gateway_HTTP_API_v2.pdf + + The smstrade API supports a debug mode, that can be set with :attr:`~iro.offer.provider.Provider.testmode`. """ params= {"debug":("boolean",False), "concat_sms":('boolean',False), @@ -77,6 +86,8 @@ "count":('boolean',False), "cost":('boolean',False), } + '''dict for standrd values of the smstrade api, it is used to get the right values to the API.''' + def __init__(self, name): self.url = "https://gateway.smstrade.de" Provider.__init__(self, name, {"sms":["basic","economy","gold","direct"]}) @@ -86,7 +97,15 @@ self.order.append("key") def send(self, route, recipient, sms): - """send SMS with $sms to $recipients""" + """send on SMS to recipients via route + + :param string route: A valid route ``["basic", "economy", "gold", "direct"] + :param string recipient: Mobilenumber of recipient + :param `iro.model.message.sms` sms: the sms to send + :return: + - All went ok -- :class:`iro.model.status.Status` object + - otherwise -- an exception + """ #logger.debug('smstrade.sendSMS(%s,%s)'%(sms, recipient)) route = unicode(route) @@ -105,9 +124,14 @@ raise SmstradeException(s) def __send(self, route, to, sms): - """ This function is the main part of the request to the sms service. - The function has to return a unicode formated string that will represent the answer of the sms service - to the request.""" + """ This is the main function to request to the sms service. + + :param string route: A valid route ``["basic", "economy", "gold", "direct"] + :param string recipient: Mobilenumber of recipient + :param `iro.model.message.sms` sms: the sms to send + :return: a :class:`.StatusCode` object + """ + #logger.debug('smstrade._send(%s,%s,%s)'%( route, to, sms)) parameters= {"key": self.key, "route": route, @@ -151,6 +175,8 @@ return StatusCode(int(data[0]),exID=data[1],costs=data[2],count=data[3]) def getSendFunc(self, typ, route): + """returns a partial :meth:`send` methed with bounded route, if typ and route is valid.""" + Provider.getSendFunc(self, typ, route) return partial(self.send,route)