22 from ..error import RejectRecipient, ExternalException |
22 from ..error import RejectRecipient, ExternalException |
23 |
23 |
24 import logging |
24 import logging |
25 logger=logging.getLogger("smstrade") |
25 logger=logging.getLogger("smstrade") |
26 |
26 |
27 class UnknownStatusCode(ExternalException): |
27 statusCodes = {10 : "Empfaengernummer nicht korrekt.", |
|
28 20 : "Absenderkennung nicht korrekt.", |
|
29 30 : "Nachrichtentext nicht korrekt.", |
|
30 31 : "Messagetyp nicht korrekt.", |
|
31 40 : "SMS Route nicht korrekt.", |
|
32 50 : "Identifikation fehlgeschlagen.", |
|
33 60 : "nicht genuegend Guthaben.", |
|
34 70 : "Netz wird von Route nicht abgedeckt.", |
|
35 71 : "Feature nicht ueber diese Route moeglich.", |
|
36 80 : "Uebergabe an SMS-C fehlgeschlagen.", |
|
37 90 : "Versand nicht moeglich.", |
|
38 100 : "SMS wurde versendet.", |
|
39 } |
|
40 |
|
41 |
|
42 class StatusException(ExternalException): |
28 def __init__(self,status): |
43 def __init__(self,status): |
29 ExternalException.__init__(self) |
44 ExternalException.__init__(self) |
30 self.status=status |
45 self.status = status |
31 |
46 self.str_ = "%i: unknown statuscode."%status |
|
47 try: |
|
48 self.str_="%i: %s"%(status, statusCodes[int(status)]) |
|
49 except KeyError: |
|
50 pass |
32 def __str__(self): |
51 def __str__(self): |
33 return "%s\nStatusCode %i is unknown."%(ExternalException.__str__(self),self.status) |
52 return "%s\n%s"%(ExternalException.__str__(self),self.str_) |
34 |
53 |
35 |
54 |
36 class StatusCode: |
55 class StatusCode: |
37 statusCodes = {10 : "Empfaengernummer nicht korrekt", |
|
38 20 : "Absenderkennung nicht korrekt", |
|
39 30 : "Nachrichtentext nicht korrekt", |
|
40 31 : "Messagetyp nicht korrekt", |
|
41 40 : "SMS Route nicht korrekt", |
|
42 50 : "Identifikation fehlgeschlagen", |
|
43 60 : "nicht genuegend Guthaben", |
|
44 70 : "Netz wird von Route nicht abgedeckt", |
|
45 71 : "Feature nicht ueber diese Route moeglich", |
|
46 80 : "Uebergabe an SMS-C fehlgeschlagen", |
|
47 90 : "Versand nicht moeglich", |
|
48 100 : "SMS wurde versendet", |
|
49 } |
|
50 |
|
51 def __init__(self,code, mID=None, cost=None, count=None): |
56 def __init__(self,code, mID=None, cost=None, count=None): |
52 if code in self.statusCodes.keys(): |
57 if code in statusCodes.keys(): |
53 self.code=code |
58 self.code = code |
54 else: |
59 else: |
55 raise UnknownStatusCode(code) |
60 raise StatusException(code) |
56 self.mID=mID |
61 self.mID=mID |
57 self.cost = cost |
62 self.cost = cost |
58 self.count = count |
63 self.count = count |
59 |
64 |
60 def __str__(self): |
65 def __str__(self): |
61 try: |
66 try: |
62 return "%i: %s"%(self.code, self.statusCodes[self.code]) |
67 return "%i: %s"%(self.code, statusCodes[self.code]) |
63 except IndexError: |
68 except IndexError: |
64 raise UnknownStatusCode(self.code) |
69 raise StatusException(self.code) |
65 |
70 |
66 def __int__(self): |
71 def __int__(self): |
67 if not self.code in self.statusCodes.keys(): |
72 if not self.code in statusCodes.keys(): |
68 raise UnknownStatusCode(self.code) |
73 raise StatusException(self.code) |
69 return self.code |
74 return self.code |
70 |
|
71 |
|
72 |
|
73 |
75 |
74 class Smstrade(Provider): |
76 class Smstrade(Provider): |
75 """ |
77 """ |
76 s. auch http://kundencenter.smstrade.de/sites/smstrade.de.kundencenter/__pdf/SMS-Gateway_HTTP_API_v2.pdf |
78 s. auch http://kundencenter.smstrade.de/sites/smstrade.de.kundencenter/__pdf/SMS-Gateway_HTTP_API_v2.pdf |
77 """ |
79 """ |
103 if int(smsSendStatus) in (100,): |
105 if int(smsSendStatus) in (100,): |
104 return Status(self,route) |
106 return Status(self,route) |
105 elif int(smsSendStatus) in (70,71,): |
107 elif int(smsSendStatus) in (70,71,): |
106 raise RejectRecipient(recipient, status=smsSendStatus) |
108 raise RejectRecipient(recipient, status=smsSendStatus) |
107 else: |
109 else: |
108 raise Exception() |
110 raise StatusException(smsSendStatus) |
109 |
111 |
110 def __send(self, route, to, sms): |
112 def __send(self, route, to, sms): |
111 """ This function is the main part of the request to the sms service. |
113 """ This function is the main part of the request to the sms service. |
112 The function has to return a unicode formated string that will represent the answer of the sms service |
114 The function has to return a unicode formated string that will represent the answer of the sms service |
113 to the request.""" |
115 to the request.""" |