| 103 |
- |
1 |
<?php
|
|
|
2 |
// If you are using Composer
|
|
|
3 |
require 'vendor/autoload.php';
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
$apiKey = getenv('SENDGRID_API_KEY');
|
|
|
7 |
$sg = new \SendGrid($apiKey);
|
|
|
8 |
|
|
|
9 |
////////////////////////////////////////////////////
|
|
|
10 |
// Retrieve all IP addresses #
|
|
|
11 |
// GET /ips #
|
|
|
12 |
|
|
|
13 |
$query_params = json_decode('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}');
|
|
|
14 |
$response = $sg->client->ips()->get(null, $query_params);
|
|
|
15 |
echo $response->statusCode();
|
|
|
16 |
echo $response->body();
|
|
|
17 |
echo $response->headers();
|
|
|
18 |
|
|
|
19 |
////////////////////////////////////////////////////
|
|
|
20 |
// Retrieve all assigned IPs #
|
|
|
21 |
// GET /ips/assigned #
|
|
|
22 |
|
|
|
23 |
$response = $sg->client->ips()->assigned()->get();
|
|
|
24 |
echo $response->statusCode();
|
|
|
25 |
echo $response->body();
|
|
|
26 |
echo $response->headers();
|
|
|
27 |
|
|
|
28 |
////////////////////////////////////////////////////
|
|
|
29 |
// Create an IP pool. #
|
|
|
30 |
// POST /ips/pools #
|
|
|
31 |
|
|
|
32 |
$request_body = json_decode('{
|
|
|
33 |
"name": "marketing"
|
|
|
34 |
}');
|
|
|
35 |
$response = $sg->client->ips()->pools()->post($request_body);
|
|
|
36 |
echo $response->statusCode();
|
|
|
37 |
echo $response->body();
|
|
|
38 |
echo $response->headers();
|
|
|
39 |
|
|
|
40 |
////////////////////////////////////////////////////
|
|
|
41 |
// Retrieve all IP pools. #
|
|
|
42 |
// GET /ips/pools #
|
|
|
43 |
|
|
|
44 |
$response = $sg->client->ips()->pools()->get();
|
|
|
45 |
echo $response->statusCode();
|
|
|
46 |
echo $response->body();
|
|
|
47 |
echo $response->headers();
|
|
|
48 |
|
|
|
49 |
////////////////////////////////////////////////////
|
|
|
50 |
// Update an IP pools name. #
|
|
|
51 |
// PUT /ips/pools/{pool_name} #
|
|
|
52 |
|
|
|
53 |
$request_body = json_decode('{
|
|
|
54 |
"name": "new_pool_name"
|
|
|
55 |
}');
|
|
|
56 |
$pool_name = "test_url_param";
|
|
|
57 |
$response = $sg->client->ips()->pools()->_($pool_name)->put($request_body);
|
|
|
58 |
echo $response->statusCode();
|
|
|
59 |
echo $response->body();
|
|
|
60 |
echo $response->headers();
|
|
|
61 |
|
|
|
62 |
////////////////////////////////////////////////////
|
|
|
63 |
// Retrieve all IPs in a specified pool. #
|
|
|
64 |
// GET /ips/pools/{pool_name} #
|
|
|
65 |
|
|
|
66 |
$pool_name = "test_url_param";
|
|
|
67 |
$response = $sg->client->ips()->pools()->_($pool_name)->get();
|
|
|
68 |
echo $response->statusCode();
|
|
|
69 |
echo $response->body();
|
|
|
70 |
echo $response->headers();
|
|
|
71 |
|
|
|
72 |
////////////////////////////////////////////////////
|
|
|
73 |
// Delete an IP pool. #
|
|
|
74 |
// DELETE /ips/pools/{pool_name} #
|
|
|
75 |
|
|
|
76 |
$pool_name = "test_url_param";
|
|
|
77 |
$response = $sg->client->ips()->pools()->_($pool_name)->delete();
|
|
|
78 |
echo $response->statusCode();
|
|
|
79 |
echo $response->body();
|
|
|
80 |
echo $response->headers();
|
|
|
81 |
|
|
|
82 |
////////////////////////////////////////////////////
|
|
|
83 |
// Add an IP address to a pool #
|
|
|
84 |
// POST /ips/pools/{pool_name}/ips #
|
|
|
85 |
|
|
|
86 |
$request_body = json_decode('{
|
|
|
87 |
"ip": "0.0.0.0"
|
|
|
88 |
}');
|
|
|
89 |
$pool_name = "test_url_param";
|
|
|
90 |
$response = $sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body);
|
|
|
91 |
echo $response->statusCode();
|
|
|
92 |
echo $response->body();
|
|
|
93 |
echo $response->headers();
|
|
|
94 |
|
|
|
95 |
////////////////////////////////////////////////////
|
|
|
96 |
// Remove an IP address from a pool. #
|
|
|
97 |
// DELETE /ips/pools/{pool_name}/ips/{ip} #
|
|
|
98 |
|
|
|
99 |
$pool_name = "test_url_param";
|
|
|
100 |
$ip = "test_url_param";
|
|
|
101 |
$response = $sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete();
|
|
|
102 |
echo $response->statusCode();
|
|
|
103 |
echo $response->body();
|
|
|
104 |
echo $response->headers();
|
|
|
105 |
|
|
|
106 |
////////////////////////////////////////////////////
|
|
|
107 |
// Add an IP to warmup #
|
|
|
108 |
// POST /ips/warmup #
|
|
|
109 |
|
|
|
110 |
$request_body = json_decode('{
|
|
|
111 |
"ip": "0.0.0.0"
|
|
|
112 |
}');
|
|
|
113 |
$response = $sg->client->ips()->warmup()->post($request_body);
|
|
|
114 |
echo $response->statusCode();
|
|
|
115 |
echo $response->body();
|
|
|
116 |
echo $response->headers();
|
|
|
117 |
|
|
|
118 |
////////////////////////////////////////////////////
|
|
|
119 |
// Retrieve all IPs currently in warmup #
|
|
|
120 |
// GET /ips/warmup #
|
|
|
121 |
|
|
|
122 |
$response = $sg->client->ips()->warmup()->get();
|
|
|
123 |
echo $response->statusCode();
|
|
|
124 |
echo $response->body();
|
|
|
125 |
echo $response->headers();
|
|
|
126 |
|
|
|
127 |
////////////////////////////////////////////////////
|
|
|
128 |
// Retrieve warmup status for a specific IP address #
|
|
|
129 |
// GET /ips/warmup/{ip_address} #
|
|
|
130 |
|
|
|
131 |
$ip_address = "test_url_param";
|
|
|
132 |
$response = $sg->client->ips()->warmup()->_($ip_address)->get();
|
|
|
133 |
echo $response->statusCode();
|
|
|
134 |
echo $response->body();
|
|
|
135 |
echo $response->headers();
|
|
|
136 |
|
|
|
137 |
////////////////////////////////////////////////////
|
|
|
138 |
// Remove an IP from warmup #
|
|
|
139 |
// DELETE /ips/warmup/{ip_address} #
|
|
|
140 |
|
|
|
141 |
$ip_address = "test_url_param";
|
|
|
142 |
$response = $sg->client->ips()->warmup()->_($ip_address)->delete();
|
|
|
143 |
echo $response->statusCode();
|
|
|
144 |
echo $response->body();
|
|
|
145 |
echo $response->headers();
|
|
|
146 |
|
|
|
147 |
////////////////////////////////////////////////////
|
|
|
148 |
// Retrieve all IP pools an IP address belongs to #
|
|
|
149 |
// GET /ips/{ip_address} #
|
|
|
150 |
|
|
|
151 |
$ip_address = "test_url_param";
|
|
|
152 |
$response = $sg->client->ips()->_($ip_address)->get();
|
|
|
153 |
echo $response->statusCode();
|
|
|
154 |
echo $response->body();
|
|
|
155 |
echo $response->headers();
|