summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--README.md36
-rw-r--r--composer.json2
-rwxr-xr-xexample_v3.php2
-rw-r--r--lib/Client.php2
-rw-r--r--lib/SendGrid.php2
-rw-r--r--test/unit/SendGridTest.php2
-rw-r--r--test/unit/resources/api_keysTest.php46
8 files changed, 90 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d51c24a..ceacbbf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+## [v4.0.2] - (2015-12-15) ##
+### Added
+- Tests for API Keys endpoint [POST, PATCH, DELETE]
+
## [v4.0.1] - (2015-12-03) ##
### Fixed
- HTTP 406 Not Acceptable Errors [#177](https://github.com/sendgrid/sendgrid-php/issues/177)
diff --git a/README.md b/README.md
index 958fc86..e31ae16 100644
--- a/README.md
+++ b/README.md
@@ -317,7 +317,7 @@ Permission denied, wrong credentials
[APIKeys](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html)
-List all API Keys belonging to the authenticated user.
+List all API Keys belonging to the authenticated user. [GET]
```php
require 'vendor/autoload.php';
@@ -329,6 +329,40 @@ print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");
```
+Generate a new API Key for the authenticated user. [POST]
+
+```php
+require 'vendor/autoload.php';
+Dotenv::load(__DIR__);
+$sendgrid_apikey = getenv('SG_KEY');
+$sendgrid = new Client($sendgrid_apikey);
+$response = $sendgrid->api_keys->post("Key Name");
+print("Status Code: " . $response->getStatusCode() . "\n");
+print("Body: " . $response->getBody() . "\n");
+```
+
+Update the name of an existing API Key
+
+```php
+require 'vendor/autoload.php';
+Dotenv::load(__DIR__);
+$sendgrid_apikey = getenv('SG_KEY');
+$sendgrid = new Client($sendgrid_apikey);
+$response = $sendgrid->api_keys->patch("<API Key ID>", "Updated API Key Name");
+print("Status Code: " . $response->getStatusCode() . "\n");
+print("Body: " . $response->getBody() . "\n");
+```
+Revoke an existing API Key [DELETE]
+
+```php
+require 'vendor/autoload.php';
+Dotenv::load(__DIR__);
+$sendgrid_apikey = getenv('SG_KEY');
+$sendgrid = new Client($sendgrid_apikey);
+$response = $sendgrid->api_keys->delete("<API Key ID>");
+print("Status Code: " . $response->getStatusCode() . "\n");
+print("Body: " . $response->getBody() . "\n");
+
[ASMGroups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html)
Retrieve all suppression groups associated with the user.
diff --git a/composer.json b/composer.json
index e9242f5..9ef07d4 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "sendgrid/sendgrid",
"description": "This library allows you to quickly and easily send emails through SendGrid using PHP.",
- "version": "4.0.1",
+ "version": "4.0.2",
"homepage": "http://github.com/sendgrid/sendgrid-php",
"license": "MIT",
"keywords": ["SendGrid", "sendgrid", "email", "send", "grid"],
diff --git a/example_v3.php b/example_v3.php
index c8d85f9..33322db 100755
--- a/example_v3.php
+++ b/example_v3.php
@@ -39,7 +39,7 @@ $response = $sendgrid->api_keys->patch("<API Key ID>", "Magic Key Updated");
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");
-$response = $sendgrid->api_keys->delete("<API Key ID>);
+$response = $sendgrid->api_keys->delete("<API Key ID>");
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");
diff --git a/lib/Client.php b/lib/Client.php
index f620fc8..a25ce15 100644
--- a/lib/Client.php
+++ b/lib/Client.php
@@ -6,7 +6,7 @@ require 'resources/asm_suppressions.php';
class Client
{
- const VERSION = '4.0.1';
+ const VERSION = '4.0.2';
protected
$namespace = 'SendGrid',
diff --git a/lib/SendGrid.php b/lib/SendGrid.php
index cb02c51..0f7d390 100644
--- a/lib/SendGrid.php
+++ b/lib/SendGrid.php
@@ -2,7 +2,7 @@
class SendGrid
{
- const VERSION = '4.0.1';
+ const VERSION = '4.0.2';
protected
$namespace = 'SendGrid',
diff --git a/test/unit/SendGridTest.php b/test/unit/SendGridTest.php
index bc220ee..c7ec2bf 100644
--- a/test/unit/SendGridTest.php
+++ b/test/unit/SendGridTest.php
@@ -12,7 +12,7 @@ class SendGridTest_SendGrid extends PHPUnit_Framework_TestCase
public function testVersion()
{
- $this->assertEquals(SendGrid::VERSION, '4.0.1');
+ $this->assertEquals(SendGrid::VERSION, '4.0.2');
$this->assertEquals(json_decode(file_get_contents(__DIR__ . '/../../composer.json'))->version, SendGrid::VERSION);
}
diff --git a/test/unit/resources/api_keysTest.php b/test/unit/resources/api_keysTest.php
index 8045d4c..72ecff9 100644
--- a/test/unit/resources/api_keysTest.php
+++ b/test/unit/resources/api_keysTest.php
@@ -13,4 +13,50 @@ class SendGridTest_APIKeys extends baseTest
$this->assertEquals($code, $response->getStatusCode());
$this->assertEquals($body, $response->getBody());
}
+
+ public function testPOST()
+ {
+ $code = 200;
+ $headers = array('Content-Type' => 'application/json');
+ $body = '{
+ "api_key": "SG.xxxxxxxx.yyyyyyyy",
+ "api_key_id": "xxxxxxxx",
+ "name": "My API Key",
+ "scopes": [
+ "mail.send",
+ "alerts.create",
+ "alerts.read"
+ ]
+ }';
+ $sendgrid = $this->buildClient($code, $headers, $body);
+ $response = $sendgrid->api_keys->post("My API Key");
+ $this->assertEquals($code, $response->getStatusCode());
+ $this->assertEquals($body, $response->getBody());
+ }
+
+ public function testPATCH()
+ {
+ $code = 200;
+ $headers = array('Content-Type' => 'application/json');
+ $body = '{
+ "api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",
+ "name": "A New Hope"
+ }';
+ $sendgrid = $this->buildClient($code, $headers, $body);
+ $response = $sendgrid->api_keys->patch("qfTQ6KG0QBiwWdJ0-pCLCA", "Magic Key Updated");
+ $this->assertEquals($code, $response->getStatusCode());
+ $this->assertEquals($body, $response->getBody());
+ }
+
+ public function testDELETE()
+ {
+ $code = 204;
+ $headers = '';
+ $body = '';
+ $sendgrid = $this->buildClient($code, $headers, $body);
+ $response = $sendgrid->api_keys->delete("qfTQ6KG0QBiwWdJ0-pCLCA");
+ $this->assertEquals($code, $response->getStatusCode());
+ $this->assertEquals($body, $response->getBody());
+ }
+
} \ No newline at end of file