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