Skip to content

Commit ebf68af

Browse files
Version Bump 4.0.2
1 parent 6f46520 commit ebf68af

8 files changed

Lines changed: 90 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [v4.0.2] - (2015-12-15) ##
6+
### Added
7+
- Tests for API Keys endpoint [POST, PATCH, DELETE]
8+
59
## [v4.0.1] - (2015-12-03) ##
610
### Fixed
711
- HTTP 406 Not Acceptable Errors [#177](https://github.com/sendgrid/sendgrid-php/issues/177)

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Permission denied, wrong credentials
317317

318318
[APIKeys](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html)
319319

320-
List all API Keys belonging to the authenticated user.
320+
List all API Keys belonging to the authenticated user. [GET]
321321

322322
```php
323323
require 'vendor/autoload.php';
@@ -329,6 +329,40 @@ print("Status Code: " . $response->getStatusCode() . "\n");
329329
print("Body: " . $response->getBody() . "\n");
330330
```
331331

332+
Generate a new API Key for the authenticated user. [POST]
333+
334+
```php
335+
require 'vendor/autoload.php';
336+
Dotenv::load(__DIR__);
337+
$sendgrid_apikey = getenv('SG_KEY');
338+
$sendgrid = new Client($sendgrid_apikey);
339+
$response = $sendgrid->api_keys->post("Key Name");
340+
print("Status Code: " . $response->getStatusCode() . "\n");
341+
print("Body: " . $response->getBody() . "\n");
342+
```
343+
344+
Update the name of an existing API Key
345+
346+
```php
347+
require 'vendor/autoload.php';
348+
Dotenv::load(__DIR__);
349+
$sendgrid_apikey = getenv('SG_KEY');
350+
$sendgrid = new Client($sendgrid_apikey);
351+
$response = $sendgrid->api_keys->patch("<API Key ID>", "Updated API Key Name");
352+
print("Status Code: " . $response->getStatusCode() . "\n");
353+
print("Body: " . $response->getBody() . "\n");
354+
```
355+
Revoke an existing API Key [DELETE]
356+
357+
```php
358+
require 'vendor/autoload.php';
359+
Dotenv::load(__DIR__);
360+
$sendgrid_apikey = getenv('SG_KEY');
361+
$sendgrid = new Client($sendgrid_apikey);
362+
$response = $sendgrid->api_keys->delete("<API Key ID>");
363+
print("Status Code: " . $response->getStatusCode() . "\n");
364+
print("Body: " . $response->getBody() . "\n");
365+
332366
[ASMGroups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html)
333367

334368
Retrieve all suppression groups associated with the user.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sendgrid/sendgrid",
33
"description": "This library allows you to quickly and easily send emails through SendGrid using PHP.",
4-
"version": "4.0.1",
4+
"version": "4.0.2",
55
"homepage": "http://github.com/sendgrid/sendgrid-php",
66
"license": "MIT",
77
"keywords": ["SendGrid", "sendgrid", "email", "send", "grid"],

example_v3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
print("Status Code: " . $response->getStatusCode() . "\n");
4040
print("Body: " . $response->getBody() . "\n");
4141
42-
$response = $sendgrid->api_keys->delete("<API Key ID>);
42+
$response = $sendgrid->api_keys->delete("<API Key ID>");
4343
print("Status Code: " . $response->getStatusCode() . "\n");
4444
print("Body: " . $response->getBody() . "\n");
4545

lib/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Client
88
{
9-
const VERSION = '4.0.1';
9+
const VERSION = '4.0.2';
1010

1111
protected
1212
$namespace = 'SendGrid',

lib/SendGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class SendGrid
44
{
5-
const VERSION = '4.0.1';
5+
const VERSION = '4.0.2';
66

77
protected
88
$namespace = 'SendGrid',

test/unit/SendGridTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function tearDown()
1212

1313
public function testVersion()
1414
{
15-
$this->assertEquals(SendGrid::VERSION, '4.0.1');
15+
$this->assertEquals(SendGrid::VERSION, '4.0.2');
1616
$this->assertEquals(json_decode(file_get_contents(__DIR__ . '/../../composer.json'))->version, SendGrid::VERSION);
1717
}
1818

test/unit/resources/api_keysTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,50 @@ public function testGET()
1313
$this->assertEquals($code, $response->getStatusCode());
1414
$this->assertEquals($body, $response->getBody());
1515
}
16+
17+
public function testPOST()
18+
{
19+
$code = 200;
20+
$headers = array('Content-Type' => 'application/json');
21+
$body = '{
22+
"api_key": "SG.xxxxxxxx.yyyyyyyy",
23+
"api_key_id": "xxxxxxxx",
24+
"name": "My API Key",
25+
"scopes": [
26+
"mail.send",
27+
"alerts.create",
28+
"alerts.read"
29+
]
30+
}';
31+
$sendgrid = $this->buildClient($code, $headers, $body);
32+
$response = $sendgrid->api_keys->post("My API Key");
33+
$this->assertEquals($code, $response->getStatusCode());
34+
$this->assertEquals($body, $response->getBody());
35+
}
36+
37+
public function testPATCH()
38+
{
39+
$code = 200;
40+
$headers = array('Content-Type' => 'application/json');
41+
$body = '{
42+
"api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",
43+
"name": "A New Hope"
44+
}';
45+
$sendgrid = $this->buildClient($code, $headers, $body);
46+
$response = $sendgrid->api_keys->patch("qfTQ6KG0QBiwWdJ0-pCLCA", "Magic Key Updated");
47+
$this->assertEquals($code, $response->getStatusCode());
48+
$this->assertEquals($body, $response->getBody());
49+
}
50+
51+
public function testDELETE()
52+
{
53+
$code = 204;
54+
$headers = '';
55+
$body = '';
56+
$sendgrid = $this->buildClient($code, $headers, $body);
57+
$response = $sendgrid->api_keys->delete("qfTQ6KG0QBiwWdJ0-pCLCA");
58+
$this->assertEquals($code, $response->getStatusCode());
59+
$this->assertEquals($body, $response->getBody());
60+
}
61+
1662
}

0 commit comments

Comments
 (0)