Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
 
3
// If running this outside of this context, use the following include and
4
// comment out the two includes below
5
// require __DIR__ . '/vendor/autoload.php';
6
include(dirname(__DIR__) . '/lib/Client.php');
7
// This gets the parent directory, for your current directory use getcwd()
8
$path_to_config = dirname(__DIR__);
9
$apiKey = getenv('SENDGRID_API_KEY');
10
$headers = ['Authorization: Bearer ' . $apiKey];
11
$client = new SendGrid\Client('https://api.sendgrid.com', $headers, '/v3');
12
 
13
// GET Collection
14
$query_params = ['limit' => 100, 'offset' => 0];
15
$request_headers = ['X-Mock: 200'];
16
$response = $client->api_keys()->get(null, $query_params, $request_headers);
17
echo $response->statusCode();
18
echo $response->body();
19
echo $response->headers();
20
 
21
// POST
22
$request_body = [
23
    'name' => 'My PHP API Key',
24
    'scopes' => [
25
        'mail.send',
26
        'alerts.create',
27
        'alerts.read'
28
    ]
29
];
30
$response = $client->api_keys()->post($request_body);
31
echo $response->statusCode();
32
echo $response->body();
33
echo $response->headers();
34
$response_body = json_decode($response->body());
35
$api_key_id = $response_body->api_key_id;
36
 
37
// GET Single
38
$response = $client->version('/v3')->api_keys()->_($api_key_id)->get();
39
echo $response->statusCode();
40
echo $response->body();
41
echo $response->headers();
42
 
43
// PATCH
44
$request_body = [
45
    'name' => 'A New Hope'
46
];
47
$response = $client->api_keys()->_($api_key_id)->patch($request_body);
48
echo $response->statusCode();
49
echo $response->body();
50
echo $response->headers();
51
 
52
// PUT
53
$request_body = [
54
    'name' => 'A New Hope',
55
    'scopes' => [
56
        'user.profile.read',
57
        'user.profile.update'
58
    ]
59
];
60
$response = $client->api_keys()->_($api_key_id)->put($request_body);
61
echo $response->statusCode();
62
echo $response->body();
63
echo $response->headers();
64
 
65
// DELETE
66
$response = $client->api_keys()->_($api_key_id)->delete();
67
echo $response->statusCode();
68
echo $response->body();
69
echo $response->headers();