forked from sendgrid/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathips.py
154 lines (124 loc) · 3.87 KB
/
ips.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import sendgrid
import os
sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all IP addresses #
# GET /ips #
params = {'subuser': 'test_string', 'ip': 'test_string',
'limit': 1, 'exclude_whitelabels': 'true', 'offset': 1}
response = sg.client.ips.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all assigned IPs #
# GET /ips/assigned #
response = sg.client.ips.assigned.get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Create an IP pool. #
# POST /ips/pools #
data = {
"name": "marketing"
}
response = sg.client.ips.pools.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all IP pools. #
# GET /ips/pools #
response = sg.client.ips.pools.get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Update an IP pools name. #
# PUT /ips/pools/{pool_name} #
data = {
"name": "new_pool_name"
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).put(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all IPs in a specified pool. #
# GET /ips/pools/{pool_name} #
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Delete an IP pool. #
# DELETE /ips/pools/{pool_name} #
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Add an IP address to a pool #
# POST /ips/pools/{pool_name}/ips #
data = {
"ip": "0.0.0.0"
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).ips.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Remove an IP address from a pool. #
# DELETE /ips/pools/{pool_name}/ips/{ip} #
pool_name = "test_url_param"
ip = "test_url_param"
response = sg.client.ips.pools._(pool_name).ips._(ip).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Add an IP to warmup #
# POST /ips/warmup #
data = {
"ip": "0.0.0.0"
}
response = sg.client.ips.warmup.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all IPs currently in warmup #
# GET /ips/warmup #
response = sg.client.ips.warmup.get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve warmup status for a specific IP address #
# GET /ips/warmup/{ip_address} #
ip_address = "test_url_param"
response = sg.client.ips.warmup._(ip_address).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Remove an IP from warmup #
# DELETE /ips/warmup/{ip_address} #
ip_address = "test_url_param"
response = sg.client.ips.warmup._(ip_address).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve all IP pools an IP address belongs to #
# GET /ips/{ip_address} #
ip_address = "test_url_param"
response = sg.client.ips._(ip_address).get()
print(response.status_code)
print(response.body)
print(response.headers)