summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--composer.json9
-rw-r--r--composer.lock613
-rw-r--r--lib/SparkPost/Response.php55
-rw-r--r--lib/SparkPost/SparkPost.php55
-rw-r--r--lib/SparkPost/SparkPostException.php26
-rw-r--r--lib/SparkPost/SparkPostPromise.php (renamed from lib/SparkPost/Promise.php)8
-rw-r--r--lib/SparkPost/SparkPostResponse.php104
7 files changed, 568 insertions, 302 deletions
diff --git a/composer.json b/composer.json
index 9a21d51..2962dd2 100644
--- a/composer.json
+++ b/composer.json
@@ -16,14 +16,15 @@
},
"require": {
"php": ">=5.5.0",
- "php-http/client-implementation": "^1.0"
+ "php-http/client-implementation": "^1.0",
+ "guzzlehttp/psr7": "1.3.*"
},
"require-dev": {
"phpunit/phpunit": "4.3.*",
- "guzzlehttp/guzzle": "6.*",
- "php-http/guzzle6-adapter": "*",
+ "guzzlehttp/guzzle": "5.*",
+ "php-http/guzzle5-adapter": "*",
+ "php-http/message": "*",
"mockery/mockery": "^0.9.4",
- "satooshi/php-coveralls": "dev-master",
"fabpot/php-cs-fixer": "^1.11"
},
"autoload": {
diff --git a/composer.lock b/composer.lock
index 63293c3..a4b401e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,43 +4,39 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "e4e159b9ea86988b1782dce935c5643b",
- "content-hash": "ee3bd017cd3260f3bfe25dc10efafbeb",
+ "hash": "a20653dbdc9cb61db488224520f62aaa",
+ "content-hash": "1023d8370cc9af702c5e2d68fd21ca8d",
"packages": [
{
"name": "guzzlehttp/guzzle",
- "version": "6.2.0",
+ "version": "5.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "d094e337976dff9d8e2424e8485872194e768662"
+ "reference": "f3c8c22471cb55475105c14769644a49c3262b93"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
- "reference": "d094e337976dff9d8e2424e8485872194e768662",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f3c8c22471cb55475105c14769644a49c3262b93",
+ "reference": "f3c8c22471cb55475105c14769644a49c3262b93",
"shasum": ""
},
"require": {
- "guzzlehttp/promises": "~1.0",
- "guzzlehttp/psr7": "~1.1",
- "php": ">=5.5.0"
+ "guzzlehttp/ringphp": "^1.1",
+ "php": ">=5.4.0"
},
"require-dev": {
"ext-curl": "*",
- "phpunit/phpunit": "~4.0",
- "psr/log": "~1.0"
+ "phpunit/phpunit": "^4.0",
+ "psr/log": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "6.2-dev"
+ "dev-master": "5.0-dev"
}
},
"autoload": {
- "files": [
- "src/functions_include.php"
- ],
"psr-4": {
"GuzzleHttp\\": "src/"
}
@@ -56,7 +52,7 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "Guzzle is a PHP HTTP client library",
+ "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
@@ -67,24 +63,28 @@
"rest",
"web service"
],
- "time": "2016-03-21 20:02:09"
+ "time": "2015-05-20 03:47:55"
},
{
- "name": "guzzlehttp/promises",
- "version": "1.2.0",
+ "name": "guzzlehttp/psr7",
+ "version": "1.3.0",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/promises.git",
- "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579"
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "31382fef2889136415751badebbd1cb022a4ed72"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579",
- "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
+ "reference": "31382fef2889136415751badebbd1cb022a4ed72",
"shasum": ""
},
"require": {
- "php": ">=5.5.0"
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
@@ -97,7 +97,7 @@
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Promise\\": "src/"
+ "GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
@@ -114,32 +114,82 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "Guzzle promises library",
+ "description": "PSR-7 message implementation",
"keywords": [
- "promise"
+ "http",
+ "message",
+ "stream",
+ "uri"
],
- "time": "2016-05-18 16:56:05"
+ "time": "2016-04-13 19:56:01"
},
{
- "name": "guzzlehttp/psr7",
- "version": "1.3.0",
+ "name": "guzzlehttp/ringphp",
+ "version": "1.1.0",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/psr7.git",
- "reference": "31382fef2889136415751badebbd1cb022a4ed72"
+ "url": "https://github.com/guzzle/RingPHP.git",
+ "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
- "reference": "31382fef2889136415751badebbd1cb022a4ed72",
+ "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
+ "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
"shasum": ""
},
"require": {
+ "guzzlehttp/streams": "~3.0",
"php": ">=5.4.0",
- "psr/http-message": "~1.0"
+ "react/promise": "~2.0"
},
- "provide": {
- "psr/http-message-implementation": "1.0"
+ "require-dev": {
+ "ext-curl": "*",
+ "phpunit/phpunit": "~4.0"
+ },
+ "suggest": {
+ "ext-curl": "Guzzle will use specific adapters if cURL is present"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Ring\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.",
+ "time": "2015-05-20 03:37:09"
+ },
+ {
+ "name": "guzzlehttp/streams",
+ "version": "3.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/streams.git",
+ "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
+ "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
@@ -147,16 +197,13 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Psr7\\": "src/"
- },
- "files": [
- "src/functions_include.php"
- ]
+ "GuzzleHttp\\Stream\\": "src/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -169,51 +216,118 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "PSR-7 message implementation",
+ "description": "Provides a simple abstraction over streams of data",
+ "homepage": "http://guzzlephp.org/",
"keywords": [
+ "Guzzle",
+ "stream"
+ ],
+ "time": "2014-10-12 19:18:40"
+ },
+ {
+ "name": "php-http/discovery",
+ "version": "v0.8.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-http/discovery.git",
+ "reference": "fac1240e8a070b3e2f0e38606941de80c849fa53"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-http/discovery/zipball/fac1240e8a070b3e2f0e38606941de80c849fa53",
+ "reference": "fac1240e8a070b3e2f0e38606941de80c849fa53",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.4|7.*"
+ },
+ "require-dev": {
+ "henrikbjorn/phpspec-code-coverage": "^1.0",
+ "php-http/httplug": "^1.0",
+ "php-http/message-factory": "^1.0",
+ "phpspec/phpspec": "^2.4",
+ "puli/composer-plugin": "1.0.0-beta9"
+ },
+ "suggest": {
+ "php-http/message": "Allow to use Guzzle or Diactoros factories",
+ "puli/composer-plugin": "Sets up Puli which is required for Discovery to work. Check http://docs.php-http.org/en/latest/discovery.html for more details."
+ },
+ "bin": [
+ "bin/puli.phar"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.9-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Http\\Discovery\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com"
+ }
+ ],
+ "description": "Finds installed HTTPlug implementations and PSR-7 message factories",
+ "homepage": "http://httplug.io",
+ "keywords": [
+ "adapter",
+ "client",
+ "discovery",
+ "factory",
"http",
- "message",
- "stream",
- "uri"
+ "message"
],
- "time": "2016-04-13 19:56:01"
+ "time": "2016-02-11 09:53:37"
},
{
- "name": "php-http/guzzle6-adapter",
- "version": "v1.1.1",
+ "name": "php-http/guzzle5-adapter",
+ "version": "v0.5.0",
"source": {
"type": "git",
- "url": "https://github.com/php-http/guzzle6-adapter.git",
- "reference": "a56941f9dc6110409cfcddc91546ee97039277ab"
+ "url": "https://github.com/php-http/guzzle5-adapter.git",
+ "reference": "4edc424fe9c4c620775ee7fab77fa7ae02584765"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-http/guzzle6-adapter/zipball/a56941f9dc6110409cfcddc91546ee97039277ab",
- "reference": "a56941f9dc6110409cfcddc91546ee97039277ab",
+ "url": "https://api.github.com/repos/php-http/guzzle5-adapter/zipball/4edc424fe9c4c620775ee7fab77fa7ae02584765",
+ "reference": "4edc424fe9c4c620775ee7fab77fa7ae02584765",
"shasum": ""
},
"require": {
- "guzzlehttp/guzzle": "^6.0",
- "php": ">=5.5.0",
+ "guzzlehttp/guzzle": "^5.1",
+ "php": ">=5.4",
+ "php-http/discovery": "^0.8",
"php-http/httplug": "^1.0"
},
"provide": {
- "php-http/async-client-implementation": "1.0",
"php-http/client-implementation": "1.0"
},
"require-dev": {
"ext-curl": "*",
- "php-http/adapter-integration-tests": "^0.4"
+ "guzzlehttp/psr7": "^1.2",
+ "guzzlehttp/ringphp": "^1.1",
+ "php-http/adapter-integration-tests": "^0.3",
+ "php-http/client-common": "^1.0",
+ "puli/composer-plugin": "1.0.0-beta9"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.2-dev"
+ "dev-master": "0.6-dev"
}
},
"autoload": {
"psr-4": {
- "Http\\Adapter\\Guzzle6\\": "src/"
+ "Http\\Adapter\\Guzzle5\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -222,21 +336,21 @@
],
"authors": [
{
- "name": "Márk Sági-Kazár",
- "email": "mark.sagikazar@gmail.com"
+ "name": "Eric GELOEN",
+ "email": "geloen.eric@gmail.com"
},
{
- "name": "David de Boer",
- "email": "david@ddeboer.nl"
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com"
}
],
- "description": "Guzzle 6 HTTP Adapter",
+ "description": "Guzzle 5 HTTP Adapter",
"homepage": "http://httplug.io",
"keywords": [
"Guzzle",
"http"
],
- "time": "2016-05-10 06:13:32"
+ "time": "2016-02-23 14:14:55"
},
{
"name": "php-http/httplug",
@@ -392,10 +506,103 @@
"response"
],
"time": "2015-05-04 20:22:00"
+ },
+ {
+ "name": "react/promise",
+ "version": "v2.4.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/reactphp/promise.git",
+ "reference": "8025426794f1944de806618671d4fa476dc7626f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/reactphp/promise/zipball/8025426794f1944de806618671d4fa476dc7626f",
+ "reference": "8025426794f1944de806618671d4fa476dc7626f",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "React\\Promise\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jan Sorgalla",
+ "email": "jsorgalla@gmail.com"
+ }
+ ],
+ "description": "A lightweight implementation of CommonJS Promises/A for PHP",
+ "time": "2016-05-03 17:50:52"
}
],
"packages-dev": [
{
+ "name": "clue/stream-filter",
+ "version": "v1.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/clue/php-stream-filter.git",
+ "reference": "e3bf9415da163d9ad6701dccb407ed501ae69785"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/clue/php-stream-filter/zipball/e3bf9415da163d9ad6701dccb407ed501ae69785",
+ "reference": "e3bf9415da163d9ad6701dccb407ed501ae69785",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Clue\\StreamFilter\\": "src/"
+ },
+ "files": [
+ "src/functions.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Christian Lück",
+ "email": "christian@lueck.tv"
+ }
+ ],
+ "description": "A simple and modern approach to stream filtering in PHP",
+ "homepage": "https://github.com/clue/php-stream-filter",
+ "keywords": [
+ "bucket brigade",
+ "callback",
+ "filter",
+ "php_user_filter",
+ "stream",
+ "stream_filter_append",
+ "stream_filter_register"
+ ],
+ "time": "2015-11-08 23:41:30"
+ },
+ {
"name": "doctrine/instantiator",
"version": "1.0.5",
"source": {
@@ -615,6 +822,122 @@
"time": "2016-05-22 21:52:33"
},
{
+ "name": "php-http/message",
+ "version": "v1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-http/message.git",
+ "reference": "c8fadec9533f5e34a8a730a947fa76363f3aa620"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-http/message/zipball/c8fadec9533f5e34a8a730a947fa76363f3aa620",
+ "reference": "c8fadec9533f5e34a8a730a947fa76363f3aa620",
+ "shasum": ""
+ },
+ "require": {
+ "clue/stream-filter": "^1.3",
+ "php": ">=5.4",
+ "php-http/message-factory": "^1.0.2",
+ "psr/http-message": "^1.0"
+ },
+ "require-dev": {
+ "coduo/phpspec-data-provider-extension": "^1.0",
+ "ext-zlib": "*",
+ "guzzlehttp/psr7": "^1.0",
+ "henrikbjorn/phpspec-code-coverage": "^1.0",
+ "phpspec/phpspec": "^2.4",
+ "zendframework/zend-diactoros": "^1.0"
+ },
+ "suggest": {
+ "ext-zlib": "Used with compressor/decompressor streams",
+ "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories",
+ "zendframework/zend-diactoros": "Used with Diactoros Factories"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Http\\Message\\": "src/"
+ },
+ "files": [
+ "src/filters.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com"
+ }
+ ],
+ "description": "HTTP Message related tools",
+ "homepage": "http://php-http.org",
+ "keywords": [
+ "http",
+ "message",
+ "psr-7"
+ ],
+ "time": "2016-03-29 20:44:24"
+ },
+ {
+ "name": "php-http/message-factory",
+ "version": "v1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-http/message-factory.git",
+ "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1",
+ "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4",
+ "psr/http-message": "^1.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Http\\Message\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com"
+ }
+ ],
+ "description": "Factory interfaces for PSR-7 HTTP Message",
+ "homepage": "http://php-http.org",
+ "keywords": [
+ "factory",
+ "http",
+ "message",
+ "stream",
+ "uri"
+ ],
+ "time": "2015-12-19 14:08:53"
+ },
+ {
"name": "phpunit/php-code-coverage",
"version": "2.2.4",
"source": {
@@ -986,107 +1309,6 @@
"time": "2015-10-02 06:51:40"
},
{
- "name": "psr/log",
- "version": "1.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/php-fig/log.git",
- "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
- "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
- "shasum": ""
- },
- "type": "library",
- "autoload": {
- "psr-0": {
- "Psr\\Log\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
- }
- ],
- "description": "Common interface for logging libraries",
- "keywords": [
- "log",
- "psr",
- "psr-3"
- ],
- "time": "2012-12-21 11:40:51"
- },
- {
- "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",
"version": "1.2.0",
"source": {
@@ -1407,59 +1629,6 @@
"time": "2015-06-21 13:59:46"
},
{
- "name": "symfony/config",
- "version": "v3.1.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/config.git",
- "reference": "048dc47e07f92333203c3b7045868bbc864fc40e"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/config/zipball/048dc47e07f92333203c3b7045868bbc864fc40e",
- "reference": "048dc47e07f92333203c3b7045868bbc864fc40e",
- "shasum": ""
- },
- "require": {
- "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": "3.1-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Symfony\\Component\\Config\\": ""
- },
- "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 Config Component",
- "homepage": "https://symfony.com",
- "time": "2016-05-20 11:48:17"
- },
- {
"name": "symfony/console",
"version": "v3.1.0",
"source": {
@@ -1886,9 +2055,7 @@
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": {
- "satooshi/php-coveralls": 20
- },
+ "stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
diff --git a/lib/SparkPost/Response.php b/lib/SparkPost/Response.php
deleted file mode 100644
index c2751b6..0000000
--- a/lib/SparkPost/Response.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-namespace SparkPost;
-
-use Psr\Http\Message\ResponseInterface as ResponseInterface;
-use GuzzleHttp\Psr7\Response as HttpResponse;
-use GuzzleHttp\Psr7\MessageTrait;
-
-class Response implements ResponseInterface {
-
- use MessageTrait;
-
- private $response;
-
- public function __construct(HttpResponse $response) {
- $this->response = $response;
- }
-
- public function getBody()
- {
- $body = $this->response->getBody();
- $body_string = $body->__toString();
-
- if (is_string($body_string)) {
- $json = json_decode($body_string, true);
-
- if (json_last_error() == JSON_ERROR_NONE) {
- return $json;
- }
- else {
- return $body;
- }
- }
-
- return $body;
- }
-
- public function getStatusCode()
- {
- return $this->response->getStatusCode();
- }
-
- public function withStatus($code, $reasonPhrase = '')
- {
- return $this->response->withStatus($code, $reasonPhrase);
- }
-
- public function getReasonPhrase()
- {
- $this->response->getReasonPhrase();
- }
-
-}
-
-?> \ No newline at end of file
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index b37351e..70c75da 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -3,28 +3,26 @@
namespace SparkPost;
use Http\Client\HttpClient;
+use Http\Client\HttpAsyncClient;
use GuzzleHttp\Psr7\Request as Request;
-use SparkPost\Promise as SparkPostPromise;
class SparkPost
{
private $version = '2.0.0';
- private $config;
public $httpClient;
private $options;
- public $transmissions;
-
private static $defaultOptions = [
'host' => 'api.sparkpost.com',
'protocol' => 'https',
'port' => 443,
- 'strictSSL' => true,
'key' => '',
'version' => 'v1',
'timeout' => 10
];
+ public $transmissions;
+
public function __construct(HttpClient $httpClient, $options)
{
$this->setOptions($options);
@@ -32,12 +30,36 @@ class SparkPost
$this->setupEndpoints();
}
- public function request($method = '', $uri = '', $payload = [], $headers = [])
+ public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
+ {
+ $request = $this->buildRequest($method, $uri, $payload, $headers);
+ try
+ {
+ return new SparkPostResponse($this->httpClient->sendRequest($request));
+ }
+ catch (\Exception $exception)
+ {
+ throw new SparkPostException($exception);
+ }
+ }
+
+ public function asyncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
+ {
+ if ($this->httpClient instanceof HttpAsyncClient) {
+ $request = $this->buildRequest($method, $uri, $payload, $headers);
+ return new SparkPostPromise($this->httpClient->sendAsyncRequest($request));
+ }
+ else {
+ throw new Exception('Your http client can not send asynchronous requests.');
+ }
+ }
+
+ private function buildRequest($method, $uri, $payload, $headers)
{
$method = trim(strtoupper($method));
- if ($method === 'GET') {
+ if ($method === 'GET'){
$params = $payload;
$body = [];
}
@@ -49,19 +71,21 @@ class SparkPost
$url = $this->getUrl($uri, $params);
$headers = $this->getHttpHeaders($headers);
- $request = new Request($method, $url, $headers, json_encode($body));
-
- $promise = $this->httpClient->sendAsyncRequest($request);
-
- return new SparkPostPromise($promise);
+ return new Request($method, $url, $headers, json_encode($body));
}
- public function getHttpHeaders($headers)
+ public function getHttpHeaders($headers = [])
{
- return [
+ $constantHeaders = [
'Authorization' => $this->options['key'],
- 'Content-Type' => 'application/json',
+ 'Content-Type' => 'application/json'
];
+
+ foreach ($constantHeaders as $key => $value) {
+ $headers[$key] = $value;
+ }
+
+ return $headers;
}
public function getUrl($path, $params) {
@@ -71,6 +95,7 @@ class SparkPost
if (is_array($params[$index]))
$params[$index] = implode(',', $params);
}
+
$paramsString = http_build_query($params);
return $options['protocol'].'://'.$options['host'].($options['port'] ? ':'.$options['port'] : '').'/api/'.$options['version'].'/'.$path.($paramsString ? '?'.$paramsString : '');
diff --git a/lib/SparkPost/SparkPostException.php b/lib/SparkPost/SparkPostException.php
new file mode 100644
index 0000000..92be3d5
--- /dev/null
+++ b/lib/SparkPost/SparkPostException.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace SparkPost;
+
+use Http\Client\Exception\HttpException as HttpException;
+
+class SparkPostException extends \Exception {
+
+ private $body = null;
+
+ public function __construct(\Exception $exception) {
+ $message = $exception->getMessage();
+ if($exception instanceof HttpException) {
+ $message = $exception->getResponse()->getBody()->__toString();
+ $this->body = json_decode($message, true);
+ }
+
+ parent::__construct($message, $exception->getCode(), $exception->getPrevious());
+ }
+
+ public function getBody() {
+ return $this->body;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/lib/SparkPost/Promise.php b/lib/SparkPost/SparkPostPromise.php
index c419597..462599a 100644
--- a/lib/SparkPost/Promise.php
+++ b/lib/SparkPost/SparkPostPromise.php
@@ -3,10 +3,8 @@
namespace SparkPost;
use Http\Promise\Promise as HttpPromise;
-use SparkPost\Response as SparkPostResponse;
-use SparkPost\Exception as SparkPostException;
-class Promise implements HttpPromise
+class SparkPostPromise implements HttpPromise
{
private $promise;
@@ -19,7 +17,7 @@ class Promise implements HttpPromise
function($response) {
$onFulfilled(new SparkPostResponse($response));
},
- function(Exception $exception) {
+ function(\Exception $exception) {
$onRejected(new SparkPostException($exception));
});
}
@@ -35,7 +33,7 @@ class Promise implements HttpPromise
$response = $this->promise->wait($unwrap);
return new SparkPostResponse($response);
}
- catch (Exception $exception)
+ catch (\Exception $exception)
{
throw new SparkPostException($exception);
}
diff --git a/lib/SparkPost/SparkPostResponse.php b/lib/SparkPost/SparkPostResponse.php
new file mode 100644
index 0000000..161b864
--- /dev/null
+++ b/lib/SparkPost/SparkPostResponse.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace SparkPost;
+
+use Psr\Http\Message\ResponseInterface as ResponseInterface;
+use Psr\Http\Message\StreamInterface as StreamInterface;
+
+class SparkPostResponse implements ResponseInterface {
+
+ private $response;
+
+ public function __construct(ResponseInterface $response) {
+ $this->response = $response;
+ }
+
+ public function getBody()
+ {
+ $body = $this->response->getBody();
+ $body_string = $body->__toString();
+
+ if (is_string($body_string)) {
+ $json = json_decode($body_string, true);
+
+ if (json_last_error() == JSON_ERROR_NONE) {
+ return $json;
+ }
+ else {
+ return $body;
+ }
+ }
+
+ return $body;
+ }
+
+ // pass these down to the response given in the constructor
+
+ public function getProtocolVersion()
+ {
+ return $this->response->getProtocolVersion();
+ }
+
+ public function withProtocolVersion($version)
+ {
+ return $this->response->withProtocolVersion($version);
+ }
+
+ public function getHeaders()
+ {
+ return $this->response->getHeaders();
+ }
+
+ public function hasHeader($name)
+ {
+ return $this->response->hasHeader($name);
+ }
+
+ public function getHeader($name)
+ {
+ return $this->response->getHeader($name);
+ }
+
+ public function getHeaderLine($name)
+ {
+ return $this->response->getHeaderLine($name);
+ }
+
+ public function withHeader($name, $value)
+ {
+ return $this->response->withHeader($name, $value);
+ }
+
+ public function withAddedHeader($name, $value)
+ {
+ return $this->response->withAddedHeader($name, $value);
+ }
+
+ public function withoutHeader($name)
+ {
+ return $this->response->withoutHeader($name);
+ }
+
+ public function withBody(StreamInterface $body)
+ {
+ return $this->response->withBody($body);
+ }
+
+ public function getStatusCode()
+ {
+ return $this->response->getStatusCode();
+ }
+
+ public function withStatus($code, $reasonPhrase = '')
+ {
+ return $this->response->withStatus($code, $reasonPhrase);
+ }
+
+ public function getReasonPhrase()
+ {
+ $this->response->getReasonPhrase();
+ }
+
+}
+
+?> \ No newline at end of file