/
examples.py
75 lines (66 loc) · 2.36 KB
/
examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import random
import string
from pyresponse import PureResponseClient as PureResponseClient
def rand_email():
return rand_name(6).lower() + str(random.randint(100,999)) + '@example.com'
def rand_name(N):
return ''.join(random.choice(string.ascii_lowercase) for x in range(N)).capitalize()
def rand_person():
return {'email' : rand_email(), 'name': rand_name(5) + ' ' + rand_name(7)}
def rand_set_of_x(factory):
return [factory() for x in range(3, random.randint(5,12))]
api = PureResponseClient()
print '------------------------------------------------'
print 'Authenticate'
try:
print api.authenticate('username', 'password')
except Exception as e:
print e
print '------------------------------------------------'
print 'Create list with single person'
try:
print api.create_list('new_list_name_a', rand_person(), rand_email(), True)
except Exception as e:
print e
print '------------------------------------------------'
##
## Note that the following calls are commented out as they
## will fail since Pure 360 can't process requests fast enough
## "already pending in queue"
##
# print 'Create list with many people'
# try:
# print api.create_list('new_list_name_b', rand_set_of_x(rand_person), rand_email(), True)
# except Exception as e:
# print e
# print '------------------------------------------------'
# print 'Add person to list'
# try:
# print api.add_person('new_list_name_a', rand_person(), rand_email())
# except Exception as e:
# print e
# print '------------------------------------------------'
# print 'Add people to list'
# try:
# print api.add_people('new_list_name_b', rand_set_of_x(rand_person), rand_email())
# except Exception as e:
# print e
# print '------------------------------------------------'
print 'Create message'
try:
print api.create_message('new_message_name', 'subject line', '<h1>Headline</h1><p>body of text</p>', rand_email())
except Exception as e:
print e
print '------------------------------------------------'
print 'Send single message'
try:
print api.send_to_person('new_message_name', rand_email())
except Exception as e:
print e
print '------------------------------------------------'
print 'Send campaign message'
try:
print api.send_to_list('new_message_name', 'new_list_name_a')
except Exception as e:
print e.message
print '------------------------------------------------'