12
12
import logging
13
13
import base64
14
14
from hashlib import md5
15
+ from deprecated import deprecated
15
16
16
17
try :
17
18
import simplejson as json
@@ -975,9 +976,11 @@ def sms_delete_phones_from_blacklist(self, phones):
975
976
logger .info ("Function call: sms_add_phones_to_blacklist" )
976
977
return self .__handle_result (self .__send_request ('sms/black_list' , 'DELETE' , data_to_send ))
977
978
979
+ @deprecated (version = '0.1.4' , reason = "You should use sms_add_campaign_by_addressbook_id" )
978
980
def sms_add_campaign (self , sender_name , addressbook_id , body , date = None , transliterate = False ):
979
981
""" Create new sms campaign
980
982
983
+ @deprecated: use method sms_delete_phonesfrom_blacklist
981
984
@param sender_name: string senders name
982
985
@param addressbook_id: unsigned int addressbook ID
983
986
@param body: string campaign body
@@ -1004,6 +1007,7 @@ def sms_add_campaign(self, sender_name, addressbook_id, body, date=None, transli
1004
1007
1005
1008
return self .__handle_result (self .__send_request ('sms/campaigns' , 'POST' , data_to_send ))
1006
1009
1010
+ @deprecated (version = '0.1.4' , reason = "You should use sms_add_campaign_by_phones" )
1007
1011
def sms_send (self , sender_name , phones , body , date = None , transliterate = False ):
1008
1012
""" Send sms by some phones
1009
1013
@@ -1039,6 +1043,70 @@ def sms_send(self, sender_name, phones, body, date=None, transliterate=False):
1039
1043
1040
1044
return self .__handle_result (self .__send_request ('sms/send' , 'POST' , data_to_send ))
1041
1045
1046
+ def sms_add_campaign_by_addressbook_id (self , sender_name , addressbook_id , body , additional_params = {}):
1047
+ """ Create new sms campaign by addressbook_id
1048
+
1049
+ @param sender_name: string senders name
1050
+ @param addressbook_id: unsigned int addressbook ID
1051
+ @param body: string campaign body
1052
+ @param additional_params: dictionary additional params for sms task
1053
+ @return: dictionary with response message
1054
+ """
1055
+
1056
+ logger .info ("Function call: sms_add_campaign_by_addressbook_id" )
1057
+ if not sender_name :
1058
+ return self .__handle_error ('Seems you not pass sender name' )
1059
+ if not addressbook_id :
1060
+ return self .__handle_error ('Seems you not pass addressbook ID' )
1061
+ if not body :
1062
+ return self .__handle_error ('Seems you not pass sms text' )
1063
+
1064
+ data_to_send = {
1065
+ 'sender' : sender_name ,
1066
+ 'addressBookId' : addressbook_id ,
1067
+ 'body' : body
1068
+ }
1069
+
1070
+ if additional_params :
1071
+ data_to_send .update (additional_params )
1072
+
1073
+ return self .__handle_result (self .__send_request ('sms/campaigns' , 'POST' , data_to_send ))
1074
+
1075
+ def sms_add_campaign_by_phones (self , sender_name , phones , body , additional_params = {}):
1076
+ """ Create new sms campaign by some phones
1077
+
1078
+ @param sender_name: string senders name
1079
+ @param phones: array phones
1080
+ @param body: string campaign body
1081
+ @param additional_params: dictionary additional params for sms task
1082
+ @return: dictionary with response message
1083
+ """
1084
+
1085
+ logger .info ("Function call: sms_add_campaign_by_phones" )
1086
+ if not sender_name :
1087
+ return self .__handle_error ('Seems you not pass sender name' )
1088
+ if not phones :
1089
+ return self .__handle_error ('Seems you not pass phones' )
1090
+ if not body :
1091
+ return self .__handle_error ('Seems you not pass sms text' )
1092
+
1093
+ try :
1094
+ phones = json .dumps (phones )
1095
+ except :
1096
+ logger .debug ("Phones: {}" .format (phones ))
1097
+ return self .__handle_error ("Phones list can't be converted by JSON library" )
1098
+
1099
+ data_to_send = {
1100
+ 'sender' : sender_name ,
1101
+ 'phones' : phones ,
1102
+ 'body' : body ,
1103
+ }
1104
+
1105
+ if additional_params :
1106
+ data_to_send .update (additional_params )
1107
+
1108
+ return self .__handle_result (self .__send_request ('sms/send' , 'POST' , data_to_send ))
1109
+
1042
1110
def sms_get_list_campaigns (self , date_from , date_to ):
1043
1111
""" SMS: get list of campaigns
1044
1112
0 commit comments