Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
// Create Subuser #
11
// POST /subusers #
12
 
13
$request_body = json_decode('{
14
  "email": "John@example.com",
15
  "ips": [
16
    "1.1.1.1",
17
    "2.2.2.2"
18
  ],
19
  "password": "johns_password",
20
  "username": "John@example.com"
21
}');
22
$response = $sg->client->subusers()->post($request_body);
23
echo $response->statusCode();
24
echo $response->body();
25
echo $response->headers();
26
 
27
////////////////////////////////////////////////////
28
// List all Subusers #
29
// GET /subusers #
30
 
31
$query_params = json_decode('{"username": "test_string", "limit": 1, "offset": 1}');
32
$response = $sg->client->subusers()->get(null, $query_params);
33
echo $response->statusCode();
34
echo $response->body();
35
echo $response->headers();
36
 
37
////////////////////////////////////////////////////
38
// Retrieve Subuser Reputations #
39
// GET /subusers/reputations #
40
 
41
$query_params = json_decode('{"usernames": "test_string"}');
42
$response = $sg->client->subusers()->reputations()->get(null, $query_params);
43
echo $response->statusCode();
44
echo $response->body();
45
echo $response->headers();
46
 
47
////////////////////////////////////////////////////
48
// Retrieve email statistics for your subusers. #
49
// GET /subusers/stats #
50
 
51
$query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}');
52
$response = $sg->client->subusers()->stats()->get(null, $query_params);
53
echo $response->statusCode();
54
echo $response->body();
55
echo $response->headers();
56
 
57
////////////////////////////////////////////////////
58
// Retrieve monthly stats for all subusers #
59
// GET /subusers/stats/monthly #
60
 
61
$query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}');
62
$response = $sg->client->subusers()->stats()->monthly()->get(null, $query_params);
63
echo $response->statusCode();
64
echo $response->body();
65
echo $response->headers();
66
 
67
////////////////////////////////////////////////////
68
//  Retrieve the totals for each email statistic metric for all subusers. #
69
// GET /subusers/stats/sums #
70
 
71
$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"}');
72
$response = $sg->client->subusers()->stats()->sums()->get(null, $query_params);
73
echo $response->statusCode();
74
echo $response->body();
75
echo $response->headers();
76
 
77
////////////////////////////////////////////////////
78
// Enable/disable a subuser #
79
// PATCH /subusers/{subuser_name} #
80
 
81
$request_body = json_decode('{
82
  "disabled": false
83
}');
84
$subuser_name = "test_url_param";
85
$response = $sg->client->subusers()->_($subuser_name)->patch($request_body);
86
echo $response->statusCode();
87
echo $response->body();
88
echo $response->headers();
89
 
90
////////////////////////////////////////////////////
91
// Delete a subuser #
92
// DELETE /subusers/{subuser_name} #
93
 
94
$subuser_name = "test_url_param";
95
$response = $sg->client->subusers()->_($subuser_name)->delete();
96
echo $response->statusCode();
97
echo $response->body();
98
echo $response->headers();
99
 
100
////////////////////////////////////////////////////
101
// Update IPs assigned to a subuser #
102
// PUT /subusers/{subuser_name}/ips #
103
 
104
$request_body = json_decode('[
105
  "127.0.0.1"
106
]');
107
$subuser_name = "test_url_param";
108
$response = $sg->client->subusers()->_($subuser_name)->ips()->put($request_body);
109
echo $response->statusCode();
110
echo $response->body();
111
echo $response->headers();
112
 
113
////////////////////////////////////////////////////
114
// Update Monitor Settings for a subuser #
115
// PUT /subusers/{subuser_name}/monitor #
116
 
117
$request_body = json_decode('{
118
  "email": "example@example.com",
119
  "frequency": 500
120
}');
121
$subuser_name = "test_url_param";
122
$response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body);
123
echo $response->statusCode();
124
echo $response->body();
125
echo $response->headers();
126
 
127
////////////////////////////////////////////////////
128
// Create monitor settings #
129
// POST /subusers/{subuser_name}/monitor #
130
 
131
$request_body = json_decode('{
132
  "email": "example@example.com",
133
  "frequency": 50000
134
}');
135
$subuser_name = "test_url_param";
136
$response = $sg->client->subusers()->_($subuser_name)->monitor()->post($request_body);
137
echo $response->statusCode();
138
echo $response->body();
139
echo $response->headers();
140
 
141
////////////////////////////////////////////////////
142
// Retrieve monitor settings for a subuser #
143
// GET /subusers/{subuser_name}/monitor #
144
 
145
$subuser_name = "test_url_param";
146
$response = $sg->client->subusers()->_($subuser_name)->monitor()->get();
147
echo $response->statusCode();
148
echo $response->body();
149
echo $response->headers();
150
 
151
////////////////////////////////////////////////////
152
// Delete monitor settings #
153
// DELETE /subusers/{subuser_name}/monitor #
154
 
155
$subuser_name = "test_url_param";
156
$response = $sg->client->subusers()->_($subuser_name)->monitor()->delete();
157
echo $response->statusCode();
158
echo $response->body();
159
echo $response->headers();
160
 
161
////////////////////////////////////////////////////
162
// Retrieve the monthly email statistics for a single subuser #
163
// GET /subusers/{subuser_name}/stats/monthly #
164
 
165
$query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}');
166
$subuser_name = "test_url_param";
167
$response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params);
168
echo $response->statusCode();
169
echo $response->body();
170
echo $response->headers();