summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.coveralls.yml6
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG.md22
-rw-r--r--README.md18
-rw-r--r--composer.json6
-rw-r--r--composer.lock625
-rw-r--r--examples/bootstrap.php4
-rw-r--r--examples/debug/index.php42
-rw-r--r--examples/message-events/get_message_events.php7
-rw-r--r--examples/templates/create_template.php17
-rw-r--r--examples/templates/delete_template.php5
-rw-r--r--examples/templates/get_all_templates.php5
-rw-r--r--examples/templates/get_template.php5
-rw-r--r--examples/templates/preview_template.php9
-rw-r--r--examples/templates/update_template.php9
-rw-r--r--examples/transmissions/create_transmission.php5
-rw-r--r--examples/transmissions/create_transmission_with_attachment.php55
-rw-r--r--examples/transmissions/create_transmission_with_cc_and_bcc.php5
-rw-r--r--examples/transmissions/create_transmission_with_recipient_list.php5
-rw-r--r--examples/transmissions/create_transmission_with_template.php5
-rw-r--r--examples/transmissions/delete_transmission.php5
-rw-r--r--examples/transmissions/get_all_transmissions.php5
-rw-r--r--examples/transmissions/get_transmission.php5
-rw-r--r--examples/transmissions/sparkpost.pngbin0 -> 6953 bytes
-rw-r--r--lib/SparkPost/Resource.php88
-rw-r--r--lib/SparkPost/ResourceBase.php91
-rw-r--r--lib/SparkPost/SparkPost.php74
-rw-r--r--lib/SparkPost/SparkPostException.php19
-rw-r--r--lib/SparkPost/SparkPostPromise.php22
-rw-r--r--lib/SparkPost/SparkPostResponse.php18
-rw-r--r--lib/SparkPost/Transmission.php2
-rw-r--r--phpunit.xml.dist2
-rwxr-xr-xpost-install.sh3
-rw-r--r--test/unit/SparkPostResponseTest.php8
-rw-r--r--test/unit/SparkPostTest.php179
35 files changed, 861 insertions, 516 deletions
diff --git a/.coveralls.yml b/.coveralls.yml
index 12aed78..c5e7e10 100644
--- a/.coveralls.yml
+++ b/.coveralls.yml
@@ -1,9 +1,3 @@
-#.coveralls.yml
-
-src_dir: lib/
-
# single file
coverage_clover: test/output/clover.xml
-
-
json_path: test/output/coveralls-upload.json
diff --git a/.gitignore b/.gitignore
index c295055..a043779 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,6 @@
.settings
.buildpath
test/output/
-examples/example-options.json
.idea
/composer.phar
test.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 483cd55..541724a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,25 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased][unreleased]
+## [2.1.0] - 2017-01-09
+### Added
+- [#161](https://github.com/SparkPost/php-sparkpost/pull/161) added example for sending email with attachment and simplified the examples setup
+- [#159](https://github.com/SparkPost/php-sparkpost/pull/159) added `debug` option for seeing the full request sent to SparkPost
+- [#151](https://github.com/SparkPost/php-sparkpost/pull/151) added packagist badges
+- [#139](https://github.com/SparkPost/php-sparkpost/pull/139) added examples for message events and templates
+
+### Changed
+- [#150](https://github.com/SparkPost/php-sparkpost/issues/150) renamed the `Resource` class to `ResourceBase` since resource soft reserved in php 7
+- [#137](https://github.com/SparkPost/php-sparkpost/pull/137) cleaned up tests and post install scripts
+- [#138](https://github.com/SparkPost/php-sparkpost/pull/138) added PHP 7.1 as a test environment
+
+### Fixed
+- [#156](https://github.com/SparkPost/php-sparkpost/pull/156) fixed typo in README.md
+- [#152](https://github.com/SparkPost/php-sparkpost/issues/152) fixed propagation of coverage tests to coveralls.io
+- [#147](https://github.com/SparkPost/php-sparkpost/pull/147) fixed examples in README.md
+- [#139](https://github.com/SparkPost/php-sparkpost/pull/139) fixed the ability to send using recipient lists
+- Issue[#141](https://github.com/SparkPost/php-sparkpost/issues/141) removed form feeds from the JSON body sent to the API
+
## [2.0.3] - 2016-07-28
### Fixed
- Issue [#135](https://github.com/SparkPost/php-sparkpost/issues/135) reported `Http\Discovery\NotFoundException` caused by 2.0.2 update.
@@ -78,7 +97,8 @@ This major release included a complete refactor of the library to be a thin HTTP
### Fixed
- README now has proper code blocks denoting PHP language
-[unreleased]: https://github.com/sparkpost/php-sparkpost/compare/2.0.3...HEAD
+[unreleased]: https://github.com/sparkpost/php-sparkpost/compare/2.1.0...HEAD
+[2.1.0]: https://github.com/sparkpost/php-sparkpost/compare/2.0.3...2.1.0
[2.0.3]: https://github.com/sparkpost/php-sparkpost/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/sparkpost/php-sparkpost/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/sparkpost/php-sparkpost/compare/2.0.0...2.0.1
diff --git a/README.md b/README.md
index 40b549c..181581e 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,10 @@
# SparkPost PHP Library
[![Travis CI](https://travis-ci.org/SparkPost/php-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/php-sparkpost)
-[![Coverage Status](https://coveralls.io/repos/SparkPost/php-sparkpost/badge.svg?branch=master&service=github)](https://coveralls.io/github/SparkPost/php-sparkpost?branch=master) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com)
+[![Coverage Status](https://coveralls.io/repos/SparkPost/php-sparkpost/badge.svg?branch=master&service=github)](https://coveralls.io/github/SparkPost/php-sparkpost?branch=master)
+[![Downloads](https://img.shields.io/packagist/dt/sparkpost/sparkpost.svg?maxAge=3600)](https://packagist.org/packages/sparkpost/sparkpost)
+[![Packagist](https://img.shields.io/packagist/v/sparkpost/sparkpost.svg?maxAge=3600)](https://packagist.org/packages/sparkpost/sparkpost)
+[![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com)
The official PHP library for using [the SparkPost REST API](https://developers.sparkpost.com/api/).
@@ -48,7 +51,7 @@ requiring a request library. This means that your application will need to pass
a request adapter to the constructor of the SparkPost Library. We use the [HTTPlug](https://github.com/php-http/httplug) in SparkPost. Please visit their repo for a list of supported [clients and adapters](http://docs.php-http.org/en/latest/clients.html). If you don't currently use a request library, you will
need to require one and create a client from it and pass it along. The example below uses the GuzzleHttp Client Library.
-An Client can be setup like so:
+A Client can be setup like so:
```php
<?php
@@ -97,7 +100,11 @@ $sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
* Type: `Boolean`
* Default: `true`
* `async` defines if the `request` function sends an asynchronous or synchronous request. If your client does not support async requests set this to `false`
-
+* `options.debug`
+ * Required: No
+ * Type: `Boolean`
+ * Default: `false`
+ * If `debug` is true, then then all `SparkPostResponse` and `SparkPostException` instances will return any array of the request values through the function `getRequest`
## Methods
### request(method, uri [, payload [, headers]])
@@ -168,7 +175,6 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
-$sparky = new SparkPost($httpClient, $options);
$promise = $sparky->transmissions->post([
'content' => [
'from' => [
@@ -205,6 +211,7 @@ $promise = $sparky->transmissions->post([
],
],
]);
+?>
```
### Send An API Call Using The Base Request Function
@@ -226,6 +233,7 @@ $promise = $sparky->request('GET', 'metrics/ip-pools', [
'timezone' => 'America/New_York',
'limit' => '5',
]);
+?>
```
@@ -295,6 +303,8 @@ An exception will be thrown in two cases: there is a problem with the request or
* Returns the exception message
* **getBody()**
* If there is a response body it returns it as an `Array`. Otherwise it returns `null`.
+* **getRequest()**
+ * Returns an array with the request values `method`, `url`, `headers`, `body` when `debug` is `true`
### Contributing
diff --git a/composer.json b/composer.json
index aa7f40f..20ee16d 100644
--- a/composer.json
+++ b/composer.json
@@ -9,8 +9,6 @@
],
"minimum-stability": "stable",
"scripts": {
- "post-install-cmd": "./post-install.sh",
- "post-update-cmd": "./post-install.sh",
"test": "./vendor/bin/phpunit",
"fix-style": "php-cs-fixer fix ."
},
@@ -26,7 +24,9 @@
"php-http/guzzle6-adapter": "^1.0",
"mockery/mockery": "^0.9.4",
"friendsofphp/php-cs-fixer": "^1.11",
- "nyholm/nsa": "^1.0"
+ "nyholm/nsa": "^1.0",
+ "satooshi/php-coveralls": "dev-master",
+ "phpunit/phpcov": "2.*"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index da75ac5..8bb2f81 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "b89bde64d8afac1dc3913c02bb802810",
- "content-hash": "50c9b5701a45d23dfeaa372b8f640c46",
+ "hash": "4112b63a5cdd9028c1fe389e38f341a0",
+ "content-hash": "8fb2d8826b05413373de415bc323a091",
"packages": [
{
"name": "clue/stream-filter",
@@ -58,16 +58,16 @@
},
{
"name": "guzzlehttp/guzzle",
- "version": "6.2.1",
+ "version": "6.2.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "3f808fba627f2c5b69e2501217bf31af349c1427"
+ "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/3f808fba627f2c5b69e2501217bf31af349c1427",
- "reference": "3f808fba627f2c5b69e2501217bf31af349c1427",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
+ "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
"shasum": ""
},
"require": {
@@ -116,7 +116,7 @@
"rest",
"web service"
],
- "time": "2016-07-15 17:22:37"
+ "time": "2016-10-08 15:01:37"
},
{
"name": "guzzlehttp/promises",
@@ -351,16 +351,16 @@
},
{
"name": "php-http/httplug",
- "version": "v1.0.0",
+ "version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/httplug.git",
- "reference": "2061047ca53a08a6b8f52e997b2a76f386b397dd"
+ "reference": "1c6381726c18579c4ca2ef1ec1498fdae8bdf018"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-http/httplug/zipball/2061047ca53a08a6b8f52e997b2a76f386b397dd",
- "reference": "2061047ca53a08a6b8f52e997b2a76f386b397dd",
+ "url": "https://api.github.com/repos/php-http/httplug/zipball/1c6381726c18579c4ca2ef1ec1498fdae8bdf018",
+ "reference": "1c6381726c18579c4ca2ef1ec1498fdae8bdf018",
"shasum": ""
},
"require": {
@@ -403,7 +403,7 @@
"client",
"http"
],
- "time": "2016-01-26 14:34:50"
+ "time": "2016-08-31 08:30:17"
},
{
"name": "php-http/message",
@@ -679,16 +679,16 @@
},
{
"name": "friendsofphp/php-cs-fixer",
- "version": "v1.12.0",
+ "version": "v1.12.2",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
- "reference": "ddac737e1c06a310a0bb4b3da755a094a31a916a"
+ "reference": "baa7112bef3b86c65fcfaae9a7a50436e3902b41"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/ddac737e1c06a310a0bb4b3da755a094a31a916a",
- "reference": "ddac737e1c06a310a0bb4b3da755a094a31a916a",
+ "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/baa7112bef3b86c65fcfaae9a7a50436e3902b41",
+ "reference": "baa7112bef3b86c65fcfaae9a7a50436e3902b41",
"shasum": ""
},
"require": {
@@ -733,7 +733,7 @@
}
],
"description": "A tool to automatically fix PHP code style",
- "time": "2016-08-17 00:17:27"
+ "time": "2016-09-27 07:57:59"
},
{
"name": "hamcrest/hamcrest-php",
@@ -846,48 +846,6 @@
"time": "2016-05-22 21:52:33"
},
{
- "name": "myclabs/deep-copy",
- "version": "1.5.1",
- "source": {
- "type": "git",
- "url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "a8773992b362b58498eed24bf85005f363c34771"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a8773992b362b58498eed24bf85005f363c34771",
- "reference": "a8773992b362b58498eed24bf85005f363c34771",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "require-dev": {
- "doctrine/collections": "1.*",
- "phpunit/phpunit": "~4.1"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "DeepCopy\\": "src/DeepCopy/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "Create deep copies (clones) of your objects",
- "homepage": "https://github.com/myclabs/DeepCopy",
- "keywords": [
- "clone",
- "copy",
- "duplicate",
- "object",
- "object graph"
- ],
- "time": "2015-11-20 12:04:31"
- },
- {
"name": "nyholm/nsa",
"version": "1.0.1",
"source": {
@@ -990,16 +948,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
- "version": "3.1.0",
+ "version": "3.1.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
- "reference": "9270140b940ff02e58ec577c237274e92cd40cdd"
+ "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd",
- "reference": "9270140b940ff02e58ec577c237274e92cd40cdd",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e",
+ "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e",
"shasum": ""
},
"require": {
@@ -1031,7 +989,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
- "time": "2016-06-10 09:48:41"
+ "time": "2016-09-30 07:12:33"
},
{
"name": "phpdocumentor/type-resolver",
@@ -1144,40 +1102,39 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "4.0.1",
+ "version": "2.2.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3"
+ "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5f3f7e736d6319d5f1fc402aff8b026da26709a3",
- "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979",
+ "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979",
"shasum": ""
},
"require": {
- "php": "^5.6 || ^7.0",
+ "php": ">=5.3.3",
"phpunit/php-file-iterator": "~1.3",
"phpunit/php-text-template": "~1.2",
- "phpunit/php-token-stream": "^1.4.2",
- "sebastian/code-unit-reverse-lookup": "~1.0",
- "sebastian/environment": "^1.3.2 || ^2.0",
- "sebastian/version": "~1.0|~2.0"
+ "phpunit/php-token-stream": "~1.3",
+ "sebastian/environment": "^1.3.2",
+ "sebastian/version": "~1.0"
},
"require-dev": {
"ext-xdebug": ">=2.1.4",
- "phpunit/phpunit": "^5.4"
+ "phpunit/phpunit": "~4"
},
"suggest": {
"ext-dom": "*",
- "ext-xdebug": ">=2.4.0",
+ "ext-xdebug": ">=2.2.1",
"ext-xmlwriter": "*"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0.x-dev"
+ "dev-master": "2.2.x-dev"
}
},
"autoload": {
@@ -1203,7 +1160,7 @@
"testing",
"xunit"
],
- "time": "2016-07-26 14:39:29"
+ "time": "2015-10-06 15:47:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -1387,17 +1344,69 @@
"time": "2015-09-15 10:49:45"
},
{
+ "name": "phpunit/phpcov",
+ "version": "2.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpcov.git",
+ "reference": "9ef291483ff65eefd8639584d61bbfb044d747f3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpcov/zipball/9ef291483ff65eefd8639584d61bbfb044d747f3",
+ "reference": "9ef291483ff65eefd8639584d61bbfb044d747f3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "phpunit/php-code-coverage": "~2.0",
+ "phpunit/phpunit": ">=4.1",
+ "sebastian/diff": "~1.1",
+ "sebastian/finder-facade": "~1.1",
+ "sebastian/version": "~1.0",
+ "symfony/console": "~2.2"
+ },
+ "bin": [
+ "phpcov"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "CLI frontend for PHP_CodeCoverage",
+ "homepage": "https://github.com/sebastianbergmann/phpcov",
+ "time": "2015-10-05 09:24:23"
+ },
+ {
"name": "phpunit/phpunit",
- "version": "5.5.3",
+ "version": "4.8.27",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "08745ede58cb02b4043adadc09a01c09e698e3f7"
+ "reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/08745ede58cb02b4043adadc09a01c09e698e3f7",
- "reference": "08745ede58cb02b4043adadc09a01c09e698e3f7",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c062dddcb68e44b563f66ee319ddae2b5a322a90",
+ "reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90",
"shasum": ""
},
"require": {
@@ -1406,27 +1415,21 @@
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
- "myclabs/deep-copy": "~1.3",
- "php": "^5.6 || ^7.0",
+ "php": ">=5.3.3",
"phpspec/prophecy": "^1.3.1",
- "phpunit/php-code-coverage": "^4.0.1",
+ "phpunit/php-code-coverage": "~2.1",
"phpunit/php-file-iterator": "~1.4",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "^1.0.6",
- "phpunit/phpunit-mock-objects": "^3.2",
+ "phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1",
"sebastian/diff": "~1.2",
- "sebastian/environment": "^1.3 || ^2.0",
+ "sebastian/environment": "~1.3",
"sebastian/exporter": "~1.2",
"sebastian/global-state": "~1.0",
- "sebastian/object-enumerator": "~1.0",
- "sebastian/resource-operations": "~1.0",
- "sebastian/version": "~1.0|~2.0",
+ "sebastian/version": "~1.0",
"symfony/yaml": "~2.1|~3.0"
},
- "conflict": {
- "phpdocumentor/reflection-docblock": "3.0.2"
- },
"suggest": {
"phpunit/php-invoker": "~1.1"
},
@@ -1436,7 +1439,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.5.x-dev"
+ "dev-master": "4.8.x-dev"
}
},
"autoload": {
@@ -1462,33 +1465,30 @@
"testing",
"xunit"
],
- "time": "2016-08-25 04:45:28"
+ "time": "2016-07-21 06:48:14"
},
{
"name": "phpunit/phpunit-mock-objects",
- "version": "3.2.5",
+ "version": "2.3.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "8f444748e174e49d5bd2bd7a9bebbf44edbb55fb"
+ "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/8f444748e174e49d5bd2bd7a9bebbf44edbb55fb",
- "reference": "8f444748e174e49d5bd2bd7a9bebbf44edbb55fb",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983",
+ "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
- "php": "^5.6 || ^7.0",
- "phpunit/php-text-template": "^1.2",
- "sebastian/exporter": "^1.2"
- },
- "conflict": {
- "phpunit/phpunit": "<5.4.0"
+ "php": ">=5.3.3",
+ "phpunit/php-text-template": "~1.2",
+ "sebastian/exporter": "~1.2"
},
"require-dev": {
- "phpunit/phpunit": "^5.4"
+ "phpunit/phpunit": "~4.4"
},
"suggest": {
"ext-soap": "*"
@@ -1496,7 +1496,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.2.x-dev"
+ "dev-master": "2.3.x-dev"
}
},
"autoload": {
@@ -1521,27 +1521,24 @@
"mock",
"xunit"
],
- "time": "2016-08-24 16:58:26"
+ "time": "2015-10-02 06:51:40"
},
{
- "name": "sebastian/code-unit-reverse-lookup",
- "version": "1.0.0",
+ "name": "psr/log",
+ "version": "1.0.2",
"source": {
"type": "git",
- "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
- "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe"
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe",
- "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
- "php": ">=5.6"
- },
- "require-dev": {
- "phpunit/phpunit": "~5"
+ "php": ">=5.3.0"
},
"type": "library",
"extra": {
@@ -1550,23 +1547,91 @@
}
},
"autoload": {
- "classmap": [
- "src/"
- ]
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
- "BSD-3-Clause"
+ "MIT"
],
"authors": [
{
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
}
],
- "description": "Looks up which function or method a line of code belongs to",
- "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
- "time": "2016-02-13 06:45:14"
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2016-10-10 12:19:37"
+ },
+ {
+ "name": "satooshi/php-coveralls",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/satooshi/php-coveralls.git",
+ "reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
+ "reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "ext-simplexml": "*",
+ "guzzlehttp/guzzle": "^6.0",
+ "php": ">=5.5",
+ "psr/log": "^1.0",
+ "symfony/config": "^2.1|^3.0",
+ "symfony/console": "^2.1|^3.0",
+ "symfony/stopwatch": "^2.0|^3.0",
+ "symfony/yaml": "^2.0|^3.0"
+ },
+ "suggest": {
+ "symfony/http-kernel": "Allows Symfony integration"
+ },
+ "bin": [
+ "bin/coveralls"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Satooshi\\": "src/Satooshi/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Kitamura Satoshi",
+ "email": "with.no.parachute@gmail.com",
+ "homepage": "https://www.facebook.com/satooshi.jp"
+ }
+ ],
+ "description": "PHP client library for Coveralls API",
+ "homepage": "https://github.com/satooshi/php-coveralls",
+ "keywords": [
+ "ci",
+ "coverage",
+ "github",
+ "test"
+ ],
+ "time": "2016-01-20 17:44:41"
},
{
"name": "sebastian/comparator",
@@ -1802,34 +1867,24 @@
"time": "2016-06-17 09:04:28"
},
{
- "name": "sebastian/global-state",
- "version": "1.1.1",
+ "name": "sebastian/finder-facade",
+ "version": "1.2.1",
"source": {
"type": "git",
- "url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
+ "url": "https://github.com/sebastianbergmann/finder-facade.git",
+ "reference": "2a6f7f57efc0aa2d23297d9fd9e2a03111a8c0b9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
- "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "url": "https://api.github.com/repos/sebastianbergmann/finder-facade/zipball/2a6f7f57efc0aa2d23297d9fd9e2a03111a8c0b9",
+ "reference": "2a6f7f57efc0aa2d23297d9fd9e2a03111a8c0b9",
"shasum": ""
},
"require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.2"
- },
- "suggest": {
- "ext-uopz": "*"
+ "symfony/finder": "~2.3|~3.0",
+ "theseer/fdomdocument": "~1.3"
},
"type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0-dev"
- }
- },
"autoload": {
"classmap": [
"src/"
@@ -1842,41 +1897,41 @@
"authors": [
{
"name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
}
],
- "description": "Snapshotting of global state",
- "homepage": "http://www.github.com/sebastianbergmann/global-state",
- "keywords": [
- "global state"
- ],
- "time": "2015-10-12 03:26:01"
+ "description": "FinderFacade is a convenience wrapper for Symfony's Finder component.",
+ "homepage": "https://github.com/sebastianbergmann/finder-facade",
+ "time": "2016-02-17 07:02:23"
},
{
- "name": "sebastian/object-enumerator",
- "version": "1.0.0",
+ "name": "sebastian/global-state",
+ "version": "1.1.1",
"source": {
"type": "git",
- "url": "https://github.com/sebastianbergmann/object-enumerator.git",
- "reference": "d4ca2fb70344987502567bc50081c03e6192fb26"
+ "url": "https://github.com/sebastianbergmann/global-state.git",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26",
- "reference": "d4ca2fb70344987502567bc50081c03e6192fb26",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
"shasum": ""
},
"require": {
- "php": ">=5.6",
- "sebastian/recursion-context": "~1.0"
+ "php": ">=5.3.3"
},
"require-dev": {
- "phpunit/phpunit": "~5"
+ "phpunit/phpunit": "~4.2"
+ },
+ "suggest": {
+ "ext-uopz": "*"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.0-dev"
}
},
"autoload": {
@@ -1894,9 +1949,12 @@
"email": "sebastian@phpunit.de"
}
],
- "description": "Traverses array structures and object graphs to enumerate all referenced objects",
- "homepage": "https://github.com/sebastianbergmann/object-enumerator/",
- "time": "2016-01-28 13:25:10"
+ "description": "Snapshotting of global state",
+ "homepage": "http://www.github.com/sebastianbergmann/global-state",
+ "keywords": [
+ "global state"
+ ],
+ "time": "2015-10-12 03:26:01"
},
{
"name": "sebastian/recursion-context",
@@ -1952,28 +2010,20 @@
"time": "2015-11-11 19:50:13"
},
{
- "name": "sebastian/resource-operations",
- "version": "1.0.0",
+ "name": "sebastian/version",
+ "version": "1.0.6",
"source": {
"type": "git",
- "url": "https://github.com/sebastianbergmann/resource-operations.git",
- "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52"
+ "url": "https://github.com/sebastianbergmann/version.git",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52",
- "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
"shasum": ""
},
- "require": {
- "php": ">=5.6.0"
- },
"type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
"autoload": {
"classmap": [
"src/"
@@ -1986,78 +2036,90 @@
"authors": [
{
"name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
}
],
- "description": "Provides a list of PHP built-in functions that operate on resources",
- "homepage": "https://www.github.com/sebastianbergmann/resource-operations",
- "time": "2015-07-28 20:34:47"
+ "description": "Library that helps with managing the version number of Git-hosted PHP projects",
+ "homepage": "https://github.com/sebastianbergmann/version",
+ "time": "2015-06-21 13:59:46"
},
{
- "name": "sebastian/version",
- "version": "2.0.0",
+ "name": "symfony/config",
+ "version": "v3.1.5",
"source": {
"type": "git",
- "url": "https://github.com/sebastianbergmann/version.git",
- "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5"
+ "url": "https://github.com/symfony/config.git",
+ "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5",
- "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5",
+ "url": "https://api.github.com/repos/symfony/config/zipball/949e7e846743a7f9e46dc50eb639d5fde1f53341",
+ "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341",
"shasum": ""
},
"require": {
- "php": ">=5.6"
+ "php": ">=5.5.9",
+ "symfony/filesystem": "~2.8|~3.0"
+ },
+ "suggest": {
+ "symfony/yaml": "To use the yaml reference dumper"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0.x-dev"
+ "dev-master": "3.1-dev"
}
},
"autoload": {
- "classmap": [
- "src/"
+ "psr-4": {
+ "Symfony\\Component\\Config\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
- "BSD-3-Clause"
+ "MIT"
],
"authors": [
{
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de",
- "role": "lead"
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
}
],
- "description": "Library that helps with managing the version number of Git-hosted PHP projects",
- "homepage": "https://github.com/sebastianbergmann/version",
- "time": "2016-02-04 12:56:52"
+ "description": "Symfony Config Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-09-25 08:27:07"
},
{
"name": "symfony/console",
- "version": "v3.1.3",
+ "version": "v2.8.12",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "f9e638e8149e9e41b570ff092f8007c477ef0ce5"
+ "reference": "d7a5a88178f94dcc29531ea4028ea614e35452d4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/f9e638e8149e9e41b570ff092f8007c477ef0ce5",
- "reference": "f9e638e8149e9e41b570ff092f8007c477ef0ce5",
+ "url": "https://api.github.com/repos/symfony/console/zipball/d7a5a88178f94dcc29531ea4028ea614e35452d4",
+ "reference": "d7a5a88178f94dcc29531ea4028ea614e35452d4",
"shasum": ""
},
"require": {
- "php": ">=5.5.9",
+ "php": ">=5.3.9",
+ "symfony/debug": "~2.7,>=2.7.2|~3.0.0",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"psr/log": "~1.0",
- "symfony/event-dispatcher": "~2.8|~3.0",
- "symfony/process": "~2.8|~3.0"
+ "symfony/event-dispatcher": "~2.1|~3.0.0",
+ "symfony/process": "~2.1|~3.0.0"
},
"suggest": {
"psr/log": "For using the console logger",
@@ -2067,7 +2129,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.1-dev"
+ "dev-master": "2.8-dev"
}
},
"autoload": {
@@ -2094,11 +2156,68 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
- "time": "2016-07-26 08:04:17"
+ "time": "2016-09-28 00:10:16"
+ },
+ {
+ "name": "symfony/debug",
+ "version": "v3.0.9",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/debug.git",
+ "reference": "697c527acd9ea1b2d3efac34d9806bf255278b0a"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/debug/zipball/697c527acd9ea1b2d3efac34d9806bf255278b0a",
+ "reference": "697c527acd9ea1b2d3efac34d9806bf255278b0a",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "psr/log": "~1.0"
+ },
+ "conflict": {
+ "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
+ },
+ "require-dev": {
+ "symfony/class-loader": "~2.8|~3.0",
+ "symfony/http-kernel": "~2.8|~3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Debug\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Debug Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-07-30 07:22:48"
},
{
"name": "symfony/event-dispatcher",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
@@ -2158,16 +2277,16 @@
},
{
"name": "symfony/filesystem",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
- "reference": "bb29adceb552d202b6416ede373529338136e84f"
+ "reference": "682fd8fdb3135fdf05fc496a01579ccf6c85c0e5"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/filesystem/zipball/bb29adceb552d202b6416ede373529338136e84f",
- "reference": "bb29adceb552d202b6416ede373529338136e84f",
+ "url": "https://api.github.com/repos/symfony/filesystem/zipball/682fd8fdb3135fdf05fc496a01579ccf6c85c0e5",
+ "reference": "682fd8fdb3135fdf05fc496a01579ccf6c85c0e5",
"shasum": ""
},
"require": {
@@ -2203,20 +2322,20 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
- "time": "2016-07-20 05:44:26"
+ "time": "2016-09-14 00:18:46"
},
{
"name": "symfony/finder",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
- "reference": "8201978de88a9fa0923e18601bb17f1df9c721e7"
+ "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/finder/zipball/8201978de88a9fa0923e18601bb17f1df9c721e7",
- "reference": "8201978de88a9fa0923e18601bb17f1df9c721e7",
+ "url": "https://api.github.com/repos/symfony/finder/zipball/205b5ffbb518a98ba2ae60a52656c4a31ab00c6f",
+ "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f",
"shasum": ""
},
"require": {
@@ -2252,7 +2371,7 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
- "time": "2016-06-29 05:41:56"
+ "time": "2016-09-28 00:11:12"
},
{
"name": "symfony/polyfill-mbstring",
@@ -2315,16 +2434,16 @@
},
{
"name": "symfony/process",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
- "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758"
+ "reference": "66de154ae86b1a07001da9fbffd620206e4faf94"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/process/zipball/04c2dfaae4ec56a5c677b0c69fac34637d815758",
- "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758",
+ "url": "https://api.github.com/repos/symfony/process/zipball/66de154ae86b1a07001da9fbffd620206e4faf94",
+ "reference": "66de154ae86b1a07001da9fbffd620206e4faf94",
"shasum": ""
},
"require": {
@@ -2360,11 +2479,11 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
- "time": "2016-07-28 11:13:48"
+ "time": "2016-09-29 14:13:09"
},
{
"name": "symfony/stopwatch",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
@@ -2413,16 +2532,16 @@
},
{
"name": "symfony/yaml",
- "version": "v3.1.3",
+ "version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "1819adf2066880c7967df7180f4f662b6f0567ac"
+ "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/1819adf2066880c7967df7180f4f662b6f0567ac",
- "reference": "1819adf2066880c7967df7180f4f662b6f0567ac",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3",
+ "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3",
"shasum": ""
},
"require": {
@@ -2458,7 +2577,47 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2016-07-17 14:02:08"
+ "time": "2016-09-25 08:27:07"
+ },
+ {
+ "name": "theseer/fdomdocument",
+ "version": "1.6.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/theseer/fDOMDocument.git",
+ "reference": "d9ad139d6c2e8edf5e313ffbe37ff13344cf0684"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/theseer/fDOMDocument/zipball/d9ad139d6c2e8edf5e313ffbe37ff13344cf0684",
+ "reference": "d9ad139d6c2e8edf5e313ffbe37ff13344cf0684",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "lib-libxml": "*",
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Arne Blankerts",
+ "email": "arne@blankerts.de",
+ "role": "lead"
+ }
+ ],
+ "description": "The classes contained within this repository extend the standard DOM to use exceptions at all occasions of errors instead of PHP warnings or notices. They also add various custom methods and shortcuts for convenience and to simplify the usage of DOM.",
+ "homepage": "https://github.com/theseer/fDOMDocument",
+ "time": "2015-05-27 22:58:02"
},
{
"name": "webmozart/assert",
@@ -2513,11 +2672,13 @@
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": [],
+ "stability-flags": {
+ "satooshi/php-coveralls": 20
+ },
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
- "php": "^5.5 || ^7.0"
+ "php": "^5.6 || ^7.0"
},
"platform-dev": []
}
diff --git a/examples/bootstrap.php b/examples/bootstrap.php
index 1110ed3..688d53e 100644
--- a/examples/bootstrap.php
+++ b/examples/bootstrap.php
@@ -1,7 +1,3 @@
<?php
require_once dirname(__FILE__).'/../vendor/autoload.php';
-
-//pull in library options
-$optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json');
-$options = json_decode($optionsFile, true);
diff --git a/examples/debug/index.php b/examples/debug/index.php
new file mode 100644
index 0000000..84120f0
--- /dev/null
+++ b/examples/debug/index.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Examples\Templates;
+
+require dirname(__FILE__).'/../bootstrap.php';
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
+
+$httpClient = new GuzzleAdapter(new Client());
+
+/*
+ * configure options in example-options.json
+ */
+$sparky = new SparkPost($httpClient, [
+ "key" => "YOUR_API_KEY",
+ // This will expose your API KEY - do not use this in production.
+ "debug" => true
+]);
+
+$promise = $sparky->request('GET', 'templates');
+
+try {
+ $response = $promise->wait();
+
+ var_dump($response);
+
+ echo "Request:\n";
+ print_r($response->getRequest());
+
+ echo "Response:\n";
+ echo $response->getStatusCode()."\n";
+ print_r($response->getBody())."\n";
+} catch (\Exception $e) {
+ echo "Request:\n";
+ print_r($e->getRequest());
+
+ echo "Exception:\n";
+ echo $e->getCode()."\n";
+ echo $e->getMessage()."\n";
+}
diff --git a/examples/message-events/get_message_events.php b/examples/message-events/get_message_events.php
index bff4300..0a3c4ac 100644
--- a/examples/message-events/get_message_events.php
+++ b/examples/message-events/get_message_events.php
@@ -10,13 +10,10 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY",]);
$promise = $sparky->request('GET', 'message-events', [
- 'campaign_ids' => 'CAMPAIGN_ID'
+ 'campaign_ids' => 'CAMPAIGN_ID',
]);
try {
diff --git a/examples/templates/create_template.php b/examples/templates/create_template.php
index c25b900..ada8ff1 100644
--- a/examples/templates/create_template.php
+++ b/examples/templates/create_template.php
@@ -10,18 +10,15 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('POST', 'templates', [
- "name" => "PHP example template",
- "content" => [
- "from" => "from@YOUR_DOMAIN",
- "subject" => "Your Subject",
- "html" => "<b>Write your message here.</b>"
- ]
+ 'name' => 'PHP example template',
+ 'content' => [
+ 'from' => 'from@YOUR_DOMAIN',
+ 'subject' => 'Your Subject',
+ 'html' => '<b>Write your message here.</b>',
+ ],
]);
try {
diff --git a/examples/templates/delete_template.php b/examples/templates/delete_template.php
index 0985c5f..906a308 100644
--- a/examples/templates/delete_template.php
+++ b/examples/templates/delete_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('DELETE', 'templates/TEMPLATE_ID');
diff --git a/examples/templates/get_all_templates.php b/examples/templates/get_all_templates.php
index 25e222c..289ccb8 100644
--- a/examples/templates/get_all_templates.php
+++ b/examples/templates/get_all_templates.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('GET', 'templates');
diff --git a/examples/templates/get_template.php b/examples/templates/get_template.php
index 9ae977e..1cd4d42 100644
--- a/examples/templates/get_template.php
+++ b/examples/templates/get_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('GET', 'templates/TEMPLATE_ID?draft=true');
diff --git a/examples/templates/preview_template.php b/examples/templates/preview_template.php
index cdfa055..60f38c1 100644
--- a/examples/templates/preview_template.php
+++ b/examples/templates/preview_template.php
@@ -10,15 +10,12 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('POST', 'templates/TEMPLATE_ID/preview?draft=true', [
'substitution_data' => [
- 'some_key' => 'some_value'
- ]
+ 'some_key' => 'some_value',
+ ],
]);
try {
diff --git a/examples/templates/update_template.php b/examples/templates/update_template.php
index 1f467ce..bc6ed53 100644
--- a/examples/templates/update_template.php
+++ b/examples/templates/update_template.php
@@ -10,15 +10,12 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('PUT', 'templates/TEMPLATE_ID', [
'options' => [
- 'open_tracking' => true
- ]
+ 'open_tracking' => true,
+ ],
]);
try {
diff --git a/examples/transmissions/create_transmission.php b/examples/transmissions/create_transmission.php
index a7a1914..a46edd2 100644
--- a/examples/transmissions/create_transmission.php
+++ b/examples/transmissions/create_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_attachment.php b/examples/transmissions/create_transmission_with_attachment.php
new file mode 100644
index 0000000..74c1822
--- /dev/null
+++ b/examples/transmissions/create_transmission_with_attachment.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Examples\Transmissions;
+
+require dirname(__FILE__).'/../bootstrap.php';
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
+
+$httpClient = new GuzzleAdapter(new Client());
+
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
+
+$filePath = dirname(__FILE__).'/';
+$fileName = 'sparkpost.png';
+$fileType = mime_content_type($filePath.$fileName);
+$fileData = base64_encode(file_get_contents($filePath.$fileName));
+
+$promise = $sparky->transmissions->post([
+ 'content' => [
+ 'from' => [
+ 'name' => 'SparkPost Team',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'subject' => 'Mailing With Attachment From PHP',
+ 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email with an attachment!</p></body></html>',
+ 'text' => 'Congratulations, {{name}}! You just sent an email with an attachment',
+ 'attachments' => [
+ [
+ 'name' => $fileName,
+ 'type' => $fileType,
+ 'data' => $fileData,
+ ],
+ ],
+ ],
+ 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
+ 'recipients' => [
+ [
+ 'address' => [
+ 'name' => 'YOUR_NAME',
+ 'email' => 'YOUR_EMAIL',
+ ],
+ ],
+ ],
+]);
+
+try {
+ $response = $promise->wait();
+ echo $response->getStatusCode()."\n";
+ print_r($response->getBody())."\n";
+} catch (\Exception $e) {
+ echo $e->getCode()."\n";
+ echo $e->getMessage()."\n";
+}
diff --git a/examples/transmissions/create_transmission_with_cc_and_bcc.php b/examples/transmissions/create_transmission_with_cc_and_bcc.php
index 5e1bf23..de65b29 100644
--- a/examples/transmissions/create_transmission_with_cc_and_bcc.php
+++ b/examples/transmissions/create_transmission_with_cc_and_bcc.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_recipient_list.php b/examples/transmissions/create_transmission_with_recipient_list.php
index e658b0d..b8fa75f 100644
--- a/examples/transmissions/create_transmission_with_recipient_list.php
+++ b/examples/transmissions/create_transmission_with_recipient_list.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_template.php b/examples/transmissions/create_transmission_with_template.php
index e8f3fb6..7bb9020 100644
--- a/examples/transmissions/create_transmission_with_template.php
+++ b/examples/transmissions/create_transmission_with_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => ['template_id' => 'TEMPLATE_ID'],
diff --git a/examples/transmissions/delete_transmission.php b/examples/transmissions/delete_transmission.php
index ad0cc64..f62766c 100644
--- a/examples/transmissions/delete_transmission.php
+++ b/examples/transmissions/delete_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->delete('TRANSMISSION_ID');
diff --git a/examples/transmissions/get_all_transmissions.php b/examples/transmissions/get_all_transmissions.php
index 0b4eb7f..37646ba 100644
--- a/examples/transmissions/get_all_transmissions.php
+++ b/examples/transmissions/get_all_transmissions.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->get();
diff --git a/examples/transmissions/get_transmission.php b/examples/transmissions/get_transmission.php
index b149107..f62078f 100644
--- a/examples/transmissions/get_transmission.php
+++ b/examples/transmissions/get_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->get('TRANSMISSION_ID');
diff --git a/examples/transmissions/sparkpost.png b/examples/transmissions/sparkpost.png
new file mode 100644
index 0000000..140a146
--- /dev/null
+++ b/examples/transmissions/sparkpost.png
Binary files differ
diff --git a/lib/SparkPost/Resource.php b/lib/SparkPost/Resource.php
index 7c88743..84fa20f 100644
--- a/lib/SparkPost/Resource.php
+++ b/lib/SparkPost/Resource.php
@@ -2,87 +2,11 @@
namespace SparkPost;
-class Resource
+/**
+ * Class Resource.
+ *
+ * @deprecated Soft reservations placed on name Resource (as of PHP7)
+ */
+class Resource extends ResourceBase
{
- /**
- * SparkPost object used to make requests.
- */
- protected $sparkpost;
-
- /**
- * The api endpoint that gets prepended to all requests send through this resource.
- */
- protected $endpoint;
-
- /**
- * Sets up the Resource.
- *
- * @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to
- * @param string $endpoint - the endpoint that this resource wraps
- */
- public function __construct(SparkPost $sparkpost, $endpoint)
- {
- $this->sparkpost = $sparkpost;
- $this->endpoint = $endpoint;
- }
-
- /**
- * Sends get request to API at the set endpoint.
- *
- * @see SparkPost->request()
- */
- public function get($uri = '', $payload = [], $headers = [])
- {
- return $this->request('GET', $uri, $payload, $headers);
- }
-
- /**
- * Sends put request to API at the set endpoint.
- *
- * @see SparkPost->request()
- */
- public function put($uri = '', $payload = [], $headers = [])
- {
- return $this->request('PUT', $uri, $payload, $headers);
- }
-
- /**
- * Sends post request to API at the set endpoint.
- *
- * @see SparkPost->request()
- */
- public function post($payload = [], $headers = [])
- {
- return $this->request('POST', '', $payload, $headers);
- }
-
- /**
- * Sends delete request to API at the set endpoint.
- *
- * @see SparkPost->request()
- */
- public function delete($uri = '', $payload = [], $headers = [])
- {
- return $this->request('DELETE', $uri, $payload, $headers);
- }
-
- /**
- * Sends requests to SparkPost object to the resource endpoint.
- *
- * @see SparkPost->request()
- *
- * @return SparkPostPromise or SparkPostResponse depending on sync or async request
- */
- public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
- {
- if (is_array($uri)) {
- $headers = $payload;
- $payload = $uri;
- $uri = '';
- }
-
- $uri = $this->endpoint.'/'.$uri;
-
- return $this->sparkpost->request($method, $uri, $payload, $headers);
- }
}
diff --git a/lib/SparkPost/ResourceBase.php b/lib/SparkPost/ResourceBase.php
new file mode 100644
index 0000000..3620192
--- /dev/null
+++ b/lib/SparkPost/ResourceBase.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace SparkPost;
+
+/**
+ * Class ResourceBase.
+ */
+class ResourceBase
+{
+ /**
+ * SparkPost object used to make requests.
+ */
+ protected $sparkpost;
+
+ /**
+ * The api endpoint that gets prepended to all requests send through this resource.
+ */
+ protected $endpoint;
+
+ /**
+ * Sets up the Resource.
+ *
+ * @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to
+ * @param string $endpoint - the endpoint that this resource wraps
+ */
+ public function __construct(SparkPost $sparkpost, $endpoint)
+ {
+ $this->sparkpost = $sparkpost;
+ $this->endpoint = $endpoint;
+ }
+
+ /**
+ * Sends get request to API at the set endpoint.
+ *
+ * @see SparkPost->request()
+ */
+ public function get($uri = '', $payload = [], $headers = [])
+ {
+ return $this->request('GET', $uri, $payload, $headers);
+ }
+
+ /**
+ * Sends put request to API at the set endpoint.
+ *
+ * @see SparkPost->request()
+ */
+ public function put($uri = '', $payload = [], $headers = [])
+ {
+ return $this->request('PUT', $uri, $payload, $headers);
+ }
+
+ /**
+ * Sends post request to API at the set endpoint.
+ *
+ * @see SparkPost->request()
+ */
+ public function post($payload = [], $headers = [])
+ {
+ return $this->request('POST', '', $payload, $headers);
+ }
+
+ /**
+ * Sends delete request to API at the set endpoint.
+ *
+ * @see SparkPost->request()
+ */
+ public function delete($uri = '', $payload = [], $headers = [])
+ {
+ return $this->request('DELETE', $uri, $payload, $headers);
+ }
+
+ /**
+ * Sends requests to SparkPost object to the resource endpoint.
+ *
+ * @see SparkPost->request()
+ *
+ * @return SparkPostPromise or SparkPostResponse depending on sync or async request
+ */
+ public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
+ {
+ if (is_array($uri)) {
+ $headers = $payload;
+ $payload = $uri;
+ $uri = '';
+ }
+
+ $uri = $this->endpoint.'/'.$uri;
+
+ return $this->sparkpost->request($method, $uri, $payload, $headers);
+ }
+}
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index c880940..05be7f4 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -11,12 +11,12 @@ use Psr\Http\Message\RequestInterface;
class SparkPost
{
/**
- * @var string Library version, used for setting User-Agent.
+ * @var string Library version, used for setting User-Agent
*/
- private $version = '2.0.3';
+ private $version = '2.1.0';
/**
- * @var HttpClient|HttpAsyncClient used to make requests.
+ * @var HttpClient|HttpAsyncClient used to make requests
*/
private $httpClient;
@@ -26,7 +26,7 @@ class SparkPost
private $messageFactory;
/**
- * @var array Options for requests.
+ * @var array Options for requests
*/
private $options;
@@ -40,10 +40,11 @@ class SparkPost
'key' => '',
'version' => 'v1',
'async' => true,
+ 'debug' => false,
];
/**
- * @var Transmission Instance of Transmission class.
+ * @var Transmission Instance of Transmission class
*/
public $transmissions;
@@ -93,11 +94,13 @@ class SparkPost
*/
public function syncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
{
- $request = $this->buildRequest($method, $uri, $payload, $headers);
+ $requestValues = $this->buildRequestValues($method, $uri, $payload, $headers);
+ $request = call_user_func_array(array($this, 'buildRequestInstance'), $requestValues);
+
try {
- return new SparkPostResponse($this->httpClient->sendRequest($request));
+ return new SparkPostResponse($this->httpClient->sendRequest($request), $this->ifDebug($requestValues));
} catch (\Exception $exception) {
- throw new SparkPostException($exception);
+ throw new SparkPostException($exception, $this->ifDebug($requestValues));
}
}
@@ -114,25 +117,26 @@ class SparkPost
public function asyncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
{
if ($this->httpClient instanceof HttpAsyncClient) {
- $request = $this->buildRequest($method, $uri, $payload, $headers);
+ $requestValues = $this->buildRequestValues($method, $uri, $payload, $headers);
+ $request = call_user_func_array(array($this, 'buildRequestInstance'), $requestValues);
- return new SparkPostPromise($this->httpClient->sendAsyncRequest($request));
+ return new SparkPostPromise($this->httpClient->sendAsyncRequest($request), $this->ifDebug($requestValues));
} else {
throw new \Exception('Your http client does not support asynchronous requests. Please use a different client or use synchronous requests.');
}
}
/**
- * Builds request from given params.
+ * Builds request values from given params.
*
* @param string $method
* @param string $uri
* @param array $payload
* @param array $headers
*
- * @return RequestInterface
+ * @return array $requestValues
*/
- public function buildRequest($method, $uri, $payload, $headers)
+ public function buildRequestValues($method, $uri, $payload, $headers)
{
$method = trim(strtoupper($method));
@@ -153,7 +157,37 @@ class SparkPost
];
$body = strtr(json_encode($body), $jsonReplace);
- return $this->getMessageFactory()->createRequest($method, $url, $headers, $body);
+ return [
+ 'method' => $method,
+ 'url' => $url,
+ 'headers' => $headers,
+ 'body' => $body,
+ ];
+ }
+
+ /**
+ * Build RequestInterface from given params.
+ *
+ * @param array $requestValues
+ *
+ * @return RequestInterface
+ */
+ public function buildRequestInstance($method, $uri, $headers, $body)
+ {
+ return $this->getMessageFactory()->createRequest($method, $uri, $headers, $body);
+ }
+
+ /**
+ * Build RequestInterface from given params.
+ *
+ * @param array $requestValues
+ *
+ * @return RequestInterface
+ */
+ public function buildRequest($method, $uri, $payload, $headers)
+ {
+ $requestValues = $this->buildRequestValues($method, $uri, $payload, $headers);
+ return call_user_func_array(array($this, 'buildRequestInstance'), $requestValues);
}
/**
@@ -254,6 +288,18 @@ class SparkPost
}
/**
+ * Returns the given value if debugging, an empty instance otherwise.
+ *
+ * @param any $param
+ *
+ * @return any $param
+ */
+ private function ifDebug($param)
+ {
+ return $this->options['debug'] ? $param : null;
+ }
+
+ /**
* Sets up any endpoints to custom classes e.g. $this->transmissions.
*/
private function setupEndpoints()
diff --git a/lib/SparkPost/SparkPostException.php b/lib/SparkPost/SparkPostException.php
index ca92e24..bde2e5e 100644
--- a/lib/SparkPost/SparkPostException.php
+++ b/lib/SparkPost/SparkPostException.php
@@ -12,12 +12,19 @@ class SparkPostException extends \Exception
private $body = null;
/**
+ * Array with the request values sent.
+ */
+ private $request;
+
+ /**
* Sets up the custom exception and copies over original exception values.
*
* @param Exception $exception - the exception to be wrapped
*/
- public function __construct(\Exception $exception)
+ public function __construct(\Exception $exception, $request = null)
{
+ $this->request = $request;
+
$message = $exception->getMessage();
$code = $exception->getCode();
if ($exception instanceof HttpException) {
@@ -30,6 +37,16 @@ class SparkPostException extends \Exception
}
/**
+ * Returns the request values sent.
+ *
+ * @return array $request
+ */
+ public function getRequest()
+ {
+ return $this->request;
+ }
+
+ /**
* Returns the body.
*
* @return array $body - the json decoded body from the http response
diff --git a/lib/SparkPost/SparkPostPromise.php b/lib/SparkPost/SparkPostPromise.php
index df715d5..b7ded0c 100644
--- a/lib/SparkPost/SparkPostPromise.php
+++ b/lib/SparkPost/SparkPostPromise.php
@@ -12,13 +12,19 @@ class SparkPostPromise implements HttpPromise
private $promise;
/**
+ * Array with the request values sent.
+ */
+ private $request;
+
+ /**
* set the promise to be wrapped.
*
* @param HttpPromise $promise
*/
- public function __construct(HttpPromise $promise)
+ public function __construct(HttpPromise $promise, $request = null)
{
$this->promise = $promise;
+ $this->request = $request;
}
/**
@@ -29,13 +35,15 @@ class SparkPostPromise implements HttpPromise
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
- return $this->promise->then(function ($response) use ($onFulfilled) {
+ $request = $this->request;
+
+ return $this->promise->then(function ($response) use ($onFulfilled, $request) {
if (isset($onFulfilled)) {
- $onFulfilled(new SparkPostResponse($response));
+ $onFulfilled(new SparkPostResponse($response, $request));
}
- }, function ($exception) use ($onRejected) {
+ }, function ($exception) use ($onRejected, $request) {
if (isset($onRejected)) {
- $onRejected(new SparkPostException($exception));
+ $onRejected(new SparkPostException($exception, $request));
}
});
}
@@ -64,9 +72,9 @@ class SparkPostPromise implements HttpPromise
try {
$response = $this->promise->wait($unwrap);
- return $response ? new SparkPostResponse($response) : $response;
+ return $response ? new SparkPostResponse($response, $this->request) : $response;
} catch (\Exception $exception) {
- throw new SparkPostException($exception);
+ throw new SparkPostException($exception, $this->request);
}
}
}
diff --git a/lib/SparkPost/SparkPostResponse.php b/lib/SparkPost/SparkPostResponse.php
index e6a8fd1..402a2b2 100644
--- a/lib/SparkPost/SparkPostResponse.php
+++ b/lib/SparkPost/SparkPostResponse.php
@@ -13,13 +13,29 @@ class SparkPostResponse implements ResponseInterface
private $response;
/**
+ * Array with the request values sent.
+ */
+ private $request;
+
+ /**
* set the response to be wrapped.
*
* @param ResponseInterface $response
*/
- public function __construct(ResponseInterface $response)
+ public function __construct(ResponseInterface $response, $request = null)
{
$this->response = $response;
+ $this->request = $request;
+ }
+
+ /**
+ * Returns the request values sent.
+ *
+ * @return array $request
+ */
+ public function getRequest()
+ {
+ return $this->request;
}
/**
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index 6e44ab5..8efc934 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -2,7 +2,7 @@
namespace SparkPost;
-class Transmission extends Resource
+class Transmission extends ResourceBase
{
public function __construct(SparkPost $sparkpost)
{
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 5a22810..86237d4 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -37,7 +37,7 @@
<filter>
<whitelist>
- <directory>./</directory>
+ <directory>./lib</directory>
<exclude>
<directory>./test</directory>
<directory>./vendor</directory>
diff --git a/post-install.sh b/post-install.sh
deleted file mode 100755
index 0326a42..0000000
--- a/post-install.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t"key":"YOUR_API_KEY"\n}' >> examples/example-options.json; fi
diff --git a/test/unit/SparkPostResponseTest.php b/test/unit/SparkPostResponseTest.php
index efdec1a..d6b3a9f 100644
--- a/test/unit/SparkPostResponseTest.php
+++ b/test/unit/SparkPostResponseTest.php
@@ -99,6 +99,14 @@ class SparkPostResponseTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->responseMock->withoutHeader($param), $sparkpostResponse->withoutHeader($param));
}
+ public function testGetRequest()
+ {
+ $request = ['some' => 'request'];
+ $this->responseMock->shouldReceive('getRequest')->andReturn($request);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock, $request);
+ $this->assertEquals($sparkpostResponse->getRequest(), $request);
+ }
+
public function testWithBody()
{
$param = Mockery::mock('Psr\Http\Message\StreamInterface');
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index 67b9d87..cb139f6 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -19,6 +19,14 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase
/** @var SparkPost */
private $resource;
+ private $exceptionMock;
+ private $exceptionBody;
+
+ private $responseMock;
+ private $responseBody;
+
+ private $promiseMock;
+
private $postTransmissionPayload = [
'content' => [
'from' => ['name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me'],
@@ -44,8 +52,30 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
+ // response mock up
+ $responseBodyMock = Mockery::mock();
+ $this->responseBody = ['results' => 'yay'];
+ $this->responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ $this->responseMock->shouldReceive('getStatusCode')->andReturn(200);
+ $this->responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
+ $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($this->responseBody));
+
+ // exception mock up
+ $exceptionResponseMock = Mockery::mock();
+ $this->exceptionBody = ['results' => 'failed'];
+ $this->exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
+ $this->exceptionMock->shouldReceive('getResponse')->andReturn($exceptionResponseMock);
+ $exceptionResponseMock->shouldReceive('getStatusCode')->andReturn(500);
+ $exceptionResponseMock->shouldReceive('getBody->__toString')->andReturn(json_encode($this->exceptionBody));
+
+ // promise mock up
+ $this->promiseMock = Mockery::mock('Http\Promise\Promise');
+
//setup mock for the adapter
$this->clientMock = Mockery::mock('Http\Adapter\Guzzle6\Client');
+ $this->clientMock->shouldReceive('sendAsyncRequest')->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andReturn($this->promiseMock);
$this->resource = new SparkPost($this->clientMock, ['key' => 'SPARKPOST_API_KEY']);
}
@@ -55,169 +85,142 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase
Mockery::close();
}
- public function testRequest()
+ public function testRequestSync()
{
- $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
$this->resource->setOptions(['async' => false]);
- $this->clientMock->shouldReceive('sendRequest')->andReturn($responseMock);
+ $this->clientMock->shouldReceive('sendRequest')->andReturn($this->responseMock);
+
$this->assertInstanceOf('SparkPost\SparkPostResponse', $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload));
+ }
+ public function testRequestAsync()
+ {
$promiseMock = Mockery::mock('Http\Promise\Promise');
$this->resource->setOptions(['async' => true]);
$this->clientMock->shouldReceive('sendAsyncRequest')->andReturn($promiseMock);
+
$this->assertInstanceOf('SparkPost\SparkPostPromise', $this->resource->request('GET', 'transmissions', $this->getTransmissionPayload));
}
- public function testSuccessfulSyncRequest()
- {
- $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
- $responseBodyMock = Mockery::mock();
+ public function testDebugOptionWhenFalse() {
+ $this->resource->setOptions(['async' => false, 'debug' => false]);
+ $this->clientMock->shouldReceive('sendRequest')->andReturn($this->responseMock);
- $responseBody = ['results' => 'yay'];
+ $response = $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload);
+ $this->assertEquals($response->getRequest(), null);
+ }
+
+ public function testDebugOptionWhenTrue() {
+ // setup
+ $this->resource->setOptions(['async' => false, 'debug' => true]);
+
+ // successful
+ $this->clientMock->shouldReceive('sendRequest')->once()->andReturn($this->responseMock);
+ $response = $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload);
+ $this->assertEquals(json_decode($response->getRequest()['body'], true), $this->postTransmissionPayload);
+
+ // unsuccessful
+ $this->clientMock->shouldReceive('sendRequest')->once()->andThrow($this->exceptionMock);
+
+ try {
+ $response = $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload);
+ }
+ catch (\Exception $e) {
+ $this->assertEquals(json_decode($e->getRequest()['body'], true), $this->postTransmissionPayload);
+ }
+ }
+
+ public function testSuccessfulSyncRequest()
+ {
$this->clientMock->shouldReceive('sendRequest')->
once()->
with(Mockery::type('GuzzleHttp\Psr7\Request'))->
- andReturn($responseMock);
-
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
- $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
+ andReturn($this->responseMock);
$response = $this->resource->syncRequest('POST', 'transmissions', $this->postTransmissionPayload);
- $this->assertEquals($responseBody, $response->getBody());
+ $this->assertEquals($this->responseBody, $response->getBody());
$this->assertEquals(200, $response->getStatusCode());
}
public function testUnsuccessfulSyncRequest()
{
- $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
-
- $responseBody = ['results' => 'failed'];
-
$this->clientMock->shouldReceive('sendRequest')->
once()->
with(Mockery::type('GuzzleHttp\Psr7\Request'))->
- andThrow($exceptionMock);
-
- $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
- $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+ andThrow($this->exceptionMock);
try {
$this->resource->syncRequest('POST', 'transmissions', $this->postTransmissionPayload);
} catch (\Exception $e) {
- $this->assertEquals($responseBody, $e->getBody());
+ $this->assertEquals($this->exceptionBody, $e->getBody());
$this->assertEquals(500, $e->getCode());
}
}
public function testSuccessfulAsyncRequestWithWait()
{
- $promiseMock = Mockery::mock('Http\Promise\Promise');
- $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
- $responseBodyMock = Mockery::mock();
-
- $responseBody = ['results' => 'yay'];
-
- $this->clientMock->shouldReceive('sendAsyncRequest')->
- once()->
- with(Mockery::type('GuzzleHttp\Psr7\Request'))->
- andReturn($promiseMock);
-
- $promiseMock->shouldReceive('wait')->andReturn($responseMock);
-
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
- $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
+ $this->promiseMock->shouldReceive('wait')->andReturn($this->responseMock);
$promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
-
$response = $promise->wait();
- $this->assertEquals($responseBody, $response->getBody());
+ $this->assertEquals($this->responseBody, $response->getBody());
$this->assertEquals(200, $response->getStatusCode());
}
public function testUnsuccessfulAsyncRequestWithWait()
{
- $promiseMock = Mockery::mock('Http\Promise\Promise');
- $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
-
- $responseBody = ['results' => 'failed'];
-
- $this->clientMock->shouldReceive('sendAsyncRequest')->
- once()->
- with(Mockery::type('GuzzleHttp\Psr7\Request'))->
- andReturn($promiseMock);
-
- $promiseMock->shouldReceive('wait')->andThrow($exceptionMock);
-
- $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
- $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+ $this->promiseMock->shouldReceive('wait')->andThrow($this->exceptionMock);
$promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
try {
$response = $promise->wait();
} catch (\Exception $e) {
- $this->assertEquals($responseBody, $e->getBody());
+ $this->assertEquals($this->exceptionBody, $e->getBody());
$this->assertEquals(500, $e->getCode());
}
}
public function testSuccessfulAsyncRequestWithThen()
{
- $responseBody = ['results' => 'yay'];
- $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
- $responseBodyMock = Mockery::mock();
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
- $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
-
- $guzzlePromise = new GuzzleFulfilledPromise($responseMock);
+ $guzzlePromise = new GuzzleFulfilledPromise($this->responseMock);
+ $result = $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, []);
- $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
+ $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $result));
- $promise->then(function ($exception) use ($responseBody) {
- $this->assertEquals(200, $exception->getStatusCode());
- $this->assertEquals($responseBody, $exception->getBody());
+ $responseBody = $this->responseBody;
+ $promise->then(function ($response) use ($responseBody) {
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals($responseBody, $response->getBody());
}, null)->wait();
}
public function testUnsuccessfulAsyncRequestWithThen()
{
- $responseBody = ['results' => 'failed'];
- $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
- $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
- $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+ $guzzlePromise = new GuzzleRejectedPromise($this->exceptionMock);
+ $result = $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, []);
- $guzzlePromise = new GuzzleRejectedPromise($exceptionMock);
+ $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $result));
- $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
-
- $promise->then(null, function ($exception) use ($responseBody) {
+ $exceptionBody = $this->exceptionBody;
+ $promise->then(null, function ($exception) use ($exceptionBody) {
$this->assertEquals(500, $exception->getCode());
- $this->assertEquals($responseBody, $exception->getBody());
+ $this->assertEquals($exceptionBody, $exception->getBody());
})->wait();
}
public function testPromise()
{
- $promiseMock = Mockery::mock('Http\Promise\Promise');
-
- $this->clientMock->shouldReceive('sendAsyncRequest')->
- once()->
- with(Mockery::type('GuzzleHttp\Psr7\Request'))->
- andReturn($promiseMock);
-
$promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
- $promiseMock->shouldReceive('getState')->twice()->andReturn('pending');
- $this->assertEquals($promiseMock->getState(), $promise->getState());
+ $this->promiseMock->shouldReceive('getState')->twice()->andReturn('pending');
+ $this->assertEquals($this->promiseMock->getState(), $promise->getState());
- $promiseMock->shouldReceive('getState')->once()->andReturn('rejected');
- $this->assertEquals('rejected', $promise->getState());
+ $this->promiseMock->shouldReceive('getState')->twice()->andReturn('rejected');
+ $this->assertEquals($this->promiseMock->getState(), $promise->getState());
}
/**