summaryrefslogtreecommitdiffstats
path: root/examples/subusers/subusers.php
blob: 528bdd1b883e2a1d587797b790474e769a4140b4 (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// If you are using Composer
require 'vendor/autoload.php';


$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);

////////////////////////////////////////////////////
// Create Subuser #
// POST /subusers #

$request_body = json_decode('{
  "email": "John@example.com", 
  "ips": [
    "1.1.1.1", 
    "2.2.2.2"
  ], 
  "password": "johns_password", 
  "username": "John@example.com"
}');
$response = $sg->client->subusers()->post($request_body);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// List all Subusers #
// GET /subusers #

$query_params = json_decode('{"username": "test_string", "limit": 1, "offset": 1}');
$response = $sg->client->subusers()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Retrieve Subuser Reputations #
// GET /subusers/reputations #

$query_params = json_decode('{"usernames": "test_string"}');
$response = $sg->client->subusers()->reputations()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Retrieve email statistics for your subusers. #
// GET /subusers/stats #

$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}');
$response = $sg->client->subusers()->stats()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Retrieve monthly stats for all subusers #
// GET /subusers/stats/monthly #

$query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}');
$response = $sg->client->subusers()->stats()->monthly()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
//  Retrieve the totals for each email statistic metric for all subusers. #
// GET /subusers/stats/sums #

$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}');
$response = $sg->client->subusers()->stats()->sums()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Enable/disable a subuser #
// PATCH /subusers/{subuser_name} #

$request_body = json_decode('{
  "disabled": false
}');
$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->patch($request_body);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Delete a subuser #
// DELETE /subusers/{subuser_name} #

$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->delete();
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Update IPs assigned to a subuser #
// PUT /subusers/{subuser_name}/ips #

$request_body = json_decode('[
  "127.0.0.1"
]');
$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->ips()->put($request_body);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Update Monitor Settings for a subuser #
// PUT /subusers/{subuser_name}/monitor #

$request_body = json_decode('{
  "email": "example@example.com", 
  "frequency": 500
}');
$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Create monitor settings #
// POST /subusers/{subuser_name}/monitor #

$request_body = json_decode('{
  "email": "example@example.com", 
  "frequency": 50000
}');
$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->monitor()->post($request_body);
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Retrieve monitor settings for a subuser #
// GET /subusers/{subuser_name}/monitor #

$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->monitor()->get();
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Delete monitor settings #
// DELETE /subusers/{subuser_name}/monitor #

$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->monitor()->delete();
echo $response->statusCode();
echo $response->body();
echo $response->headers();

////////////////////////////////////////////////////
// Retrieve the monthly email statistics for a single subuser #
// GET /subusers/{subuser_name}/stats/monthly #

$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}');
$subuser_name = "test_url_param";
$response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
echo $response->headers();