Skip to content

Commit 8d86210

Browse files
author
Alexey Moroz
committed
Add method for getting campaigns statistic based on list of emails
1 parent 4aefc67 commit 8d86210

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

pysendpulse/examples/sendpulse-rest-api-example.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
emails_for_delete = ['[email protected]']
7474
SPApiProxy.delete_emails_from_addressbook(ADDRESSBOOK_ID, emails_for_delete)
7575

76+
#Get campaigns statistic for list of emails
77+
emails_list = ['[email protected]']
78+
SPApiProxy.get_emails_stat_by_campaigns(emails_list)
79+
7680
# Add sender "FROM" email
7781
SPApiProxy.add_sender('[email protected]', 'Jane Roe')
7882

@@ -117,7 +121,7 @@
117121
'11111111111',
118122
'22222222222'
119123
]
120-
SPApiProxy.sms_add_phones(ADDRESSBOOK_ID, phones_for_add);
124+
SPApiProxy.sms_add_phones(ADDRESSBOOK_ID, phones_for_add)
121125

122126
# Add phones to address book
123127
phones_for_add = {
@@ -139,7 +143,7 @@
139143
]
140144
}
141145

142-
SPApiProxy.sms_add_phones_with_variables(ADDRESSBOOK_ID, phones_for_add);
146+
SPApiProxy.sms_add_phones_with_variables(ADDRESSBOOK_ID, phones_for_add)
143147

144148
# Update phones variables from the address book
145149
phones_for_update = [
@@ -150,7 +154,7 @@
150154
"name":"name","type":"string", "value":"Michael"
151155
}
152156
]
153-
SPApiProxy.sms_update_phones_variables(ADDRESSBOOK_ID, phones_for_update, variables);
157+
SPApiProxy.sms_update_phones_variables(ADDRESSBOOK_ID, phones_for_update, variables)
154158

155159
# Get information about phone from the address book
156160
SPApiProxy.sms_get_phone_info(ADDRESSBOOK_ID, '1111111111')
@@ -160,7 +164,7 @@
160164
'11111111111',
161165
'22222222222'
162166
]
163-
SPApiProxy.sms_delete_phones(ADDRESSBOOK_ID, phones_for_remove);
167+
SPApiProxy.sms_delete_phones(ADDRESSBOOK_ID, phones_for_remove)
164168

165169
# Get phones from the blacklist
166170
SPApiProxy.sms_get_blacklist()
@@ -170,24 +174,24 @@
170174
'111222227',
171175
'222333337'
172176
]
173-
SPApiProxy.sms_add_phones_to_blacklist(phones_for_add_to_blacklist, 'test');
177+
SPApiProxy.sms_add_phones_to_blacklist(phones_for_add_to_blacklist, 'test')
174178

175179
# Remove phones from blacklist
176180
phones_for_remove = [
177181
'11111111111',
178182
'22222222222'
179183
]
180-
SPApiProxy.sms_delete_phones_from_blacklist(phones_for_remove);
184+
SPApiProxy.sms_delete_phones_from_blacklist(phones_for_remove)
181185

182186
# Get info by phones from the blacklist
183187
phones = [
184188
'11111111111',
185189
'22222222222'
186190
]
187-
SPApiProxy.sms_get_phones_info_from_blacklist(phones);
191+
SPApiProxy.sms_get_phones_info_from_blacklist(phones)
188192

189193
# Create new sms campaign
190-
SPApiProxy.sms_add_campaign(SENDER_NAME, ADDRESSBOOK_ID, 'test');
194+
SPApiProxy.sms_add_campaign(SENDER_NAME, ADDRESSBOOK_ID, 'test')
191195

192196
# Send sms by some phones
193197
phones_for_send = [
@@ -196,19 +200,19 @@
196200
SPApiProxy.sms_send(SENDER_NAME, phones_for_send, 'test')
197201

198202
# Get list of sms campaigns
199-
date_from = '2018-04-10 23:00:00';
200-
date_to = '2018-05-10 23:00:00';
201-
SPApiProxy.sms_get_list_campaigns(date_from, date_to);
203+
date_from = '2018-04-10 23:00:00'
204+
date_to = '2018-05-10 23:00:00'
205+
SPApiProxy.sms_get_list_campaigns(date_from, date_to)
202206

203207
# Get information about sms campaign
204-
SPApiProxy.sms_get_campaign_info(CAMPAIGN_ID);
208+
SPApiProxy.sms_get_campaign_info(CAMPAIGN_ID)
205209

206210
# Cancel sms campaign
207-
SPApiProxy.sms_cancel_campaign(CAMPAIGN_ID);
211+
SPApiProxy.sms_cancel_campaign(CAMPAIGN_ID)
208212

209213
# Get cost sms campaign
210-
SPApiProxy.sms_get_campaign_cost('sender', 'test', ADDRESSBOOK_ID);
214+
SPApiProxy.sms_get_campaign_cost('sender', 'test', ADDRESSBOOK_ID)
211215
#SPApiProxy.sms_get_campaign_cost('sender', 'test', None, ['111111111'])
212216

213217
# Remove sms campaign
214-
SPApiProxy.sms_delete_campaign(CAMPAIGN_ID);
218+
SPApiProxy.sms_delete_campaign(CAMPAIGN_ID)

pysendpulse/pysendpulse.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ def delete_emails_from_addressbook(self, id, emails):
322322
return self.__handle_error("Emails list can't be converted by JSON library")
323323
return self.__handle_result(self.__send_request('addressbooks/{}/emails'.format(id), 'DELETE', {'emails': emails}))
324324

325+
def get_emails_stat_by_campaigns(self, emails):
326+
""" Get campaigns statistic for list of emails
327+
328+
@param emails: list of emails ['test_1@test_1.com', ..., 'test_n@test_n.com']
329+
@return: dictionary with response message
330+
"""
331+
logging.info("Function call: get_emails_stat_by_campaigns")
332+
if not emails:
333+
self.__handle_error("Empty emails")
334+
try:
335+
emails = json.dumps(emails)
336+
except:
337+
logging.debug("Emails: {}".format(emails))
338+
return self.__handle_error("Emails list can't be converted by JSON library")
339+
return self.__handle_result(self.__send_request('emails/campaigns', 'POST', {'emails': emails}))
340+
325341
# ------------------------------------------------------------------ #
326342
# EMAIL CAMPAIGNS #
327343
# ------------------------------------------------------------------ #

0 commit comments

Comments
 (0)