summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbeardyman <nornholdj@gmail.com>2015-09-15 20:43:30 -0400
committerbeardyman <nornholdj@gmail.com>2015-09-15 20:43:30 -0400
commitc0b9e8b6cb7b1d616941b657958126b551b22eef (patch)
tree98829e5b048cf9328f6211719f7e87886472dbe4
parentaeea514f81c652257b64e606c771cc51249db49c (diff)
downloadphp-sparkpost-c0b9e8b6cb7b1d616941b657958126b551b22eef.zip
php-sparkpost-c0b9e8b6cb7b1d616941b657958126b551b22eef.tar.gz
php-sparkpost-c0b9e8b6cb7b1d616941b657958126b551b22eef.tar.bz2
Refactored to use http adapter instead of guzzle directly
-rw-r--r--.travis.yml3
-rw-r--r--composer.json8
-rw-r--r--composer.lock639
-rw-r--r--examples/transmission/get_all_transmissions.php11
-rw-r--r--lib/SparkPost/APIResource.php159
-rw-r--r--lib/SparkPost/SparkPost.php84
-rw-r--r--lib/SparkPost/Transmission.php42
7 files changed, 608 insertions, 338 deletions
diff --git a/.travis.yml b/.travis.yml
index 5f42efd..cfabab0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,8 @@
language: php
php:
- '5.5'
-- '5.4'
+- '5.6'
+- '5.7'
install:
- composer install
script: phpunit --bootstrap test/unit/bootstrap.php ./test/unit
diff --git a/composer.json b/composer.json
index 096a94b..3917db1 100644
--- a/composer.json
+++ b/composer.json
@@ -2,6 +2,7 @@
"name": "sparkpost/php-sparkpost",
"description": "SDK for interfacing with SparkPost APIs",
"license": "Apache 2.0",
+ "version": "0.2.0",
"authors": [
{
"name": "Message Systems, Inc."
@@ -9,11 +10,12 @@
],
"minimum-stability": "stable",
"require": {
- "php": ">=5.3.0",
- "guzzlehttp/guzzle": "3.8.1"
+ "php": ">=5.5.0",
+ "egeloen/http-adapter": "*"
},
"require-dev": {
- "phpunit/phpunit": "4.3.*"
+ "phpunit/phpunit": "4.3.*",
+ "guzzlehttp/guzzle": "6.*"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index 56e173b..e62177f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1,72 +1,69 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
- "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
],
- "hash": "6f9c9d455eb869305157559b093a3c5d",
+ "hash": "c1b222200ff1ed0a0aa545592e856675",
+ "content-hash": "28082d79d1a6e023f128688258c25e5d",
"packages": [
{
- "name": "guzzlehttp/guzzle",
- "version": "v3.8.1",
+ "name": "egeloen/http-adapter",
+ "version": "0.8.0",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/guzzle.git",
- "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba"
+ "url": "https://github.com/egeloen/ivory-http-adapter.git",
+ "reference": "9641f11487ec26b24c6bbcee4f267cf62f60b855"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
- "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
+ "url": "https://api.github.com/repos/egeloen/ivory-http-adapter/zipball/9641f11487ec26b24c6bbcee4f267cf62f60b855",
+ "reference": "9641f11487ec26b24c6bbcee4f267cf62f60b855",
"shasum": ""
},
"require": {
- "ext-curl": "*",
- "php": ">=5.3.3",
- "symfony/event-dispatcher": ">=2.1"
- },
- "replace": {
- "guzzle/batch": "self.version",
- "guzzle/cache": "self.version",
- "guzzle/common": "self.version",
- "guzzle/http": "self.version",
- "guzzle/inflection": "self.version",
- "guzzle/iterator": "self.version",
- "guzzle/log": "self.version",
- "guzzle/parser": "self.version",
- "guzzle/plugin": "self.version",
- "guzzle/plugin-async": "self.version",
- "guzzle/plugin-backoff": "self.version",
- "guzzle/plugin-cache": "self.version",
- "guzzle/plugin-cookie": "self.version",
- "guzzle/plugin-curlauth": "self.version",
- "guzzle/plugin-error-response": "self.version",
- "guzzle/plugin-history": "self.version",
- "guzzle/plugin-log": "self.version",
- "guzzle/plugin-md5": "self.version",
- "guzzle/plugin-mock": "self.version",
- "guzzle/plugin-oauth": "self.version",
- "guzzle/service": "self.version",
- "guzzle/stream": "self.version"
+ "php": ">=5.4.8",
+ "zendframework/zend-diactoros": "^1.1"
},
"require-dev": {
- "doctrine/cache": "*",
- "monolog/monolog": "1.*",
- "phpunit/phpunit": "3.7.*",
- "psr/log": "1.0.*",
- "symfony/class-loader": "*",
- "zendframework/zend-cache": "<2.3",
- "zendframework/zend-log": "<2.3"
+ "cakephp/cakephp": "^3.0.3",
+ "ext-curl": "*",
+ "guzzle/guzzle": "^3.9.4@dev",
+ "guzzlehttp/guzzle": "^4.1.4|^5.0|^6.0",
+ "kriswallsmith/buzz": "^0.13",
+ "nategood/httpful": "^0.2.17",
+ "phpunit/phpunit": "^4.0",
+ "phpunit/phpunit-mock-objects": "dev-matcher-verify as 2.3.x-dev",
+ "psr/log": "^1.0",
+ "react/dns": "^0.4.1",
+ "react/http-client": "^0.4",
+ "satooshi/php-coveralls": "^0.6",
+ "symfony/event-dispatcher": "^2.0",
+ "zendframework/zend-http": "^2.3.4",
+ "zendframework/zendframework1": ">=1.12.9,<=1.12.14|^1.12.16"
+ },
+ "suggest": {
+ "ext-curl": "Allows you to use the cURL adapter",
+ "ext-http": "Allows you to use the PECL adapter",
+ "guzzle/guzzle": "Allows you to use the Guzzle 3 adapter",
+ "guzzlehttp/guzzle": "Allows you to use the Guzzle 4 adapter",
+ "kriswallsmith/buzz": "Allows you to use the Buzz adapter",
+ "nategood/httpful": "Allows you to use the httpful adapter",
+ "psr/log": "Allows you to use the logger event subscriber",
+ "symfony/event-dispatcher": "Allows you to use the event lifecycle",
+ "symfony/stopwatch": "Allows you to use the stopwatch http adapter and event subscriber",
+ "zendframework/zend-http": "Allows you to use the Zend 2 adapter",
+ "zendframework/zendframework1": "Allows you to use the Zend 1 adapter"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.8-dev"
+ "dev-master": "0.8-dev"
}
},
"autoload": {
- "psr-0": {
- "Guzzle": "src/",
- "Guzzle\\Tests": "tests/"
+ "psr-4": {
+ "Ivory\\HttpAdapter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -75,65 +72,45 @@
],
"authors": [
{
- "name": "Michael Dowling",
- "email": "mtdowling@gmail.com",
- "homepage": "https://github.com/mtdowling"
- },
- {
- "name": "Guzzle Community",
- "homepage": "https://github.com/guzzle/guzzle/contributors"
+ "name": "Eric GELOEN",
+ "email": "geloen.eric@gmail.com"
}
],
- "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
- "homepage": "http://guzzlephp.org/",
+ "description": "Issue HTTP request for PHP 5.3+.",
"keywords": [
- "client",
- "curl",
- "framework",
"http",
- "http client",
- "rest",
- "web service"
+ "http-adapter",
+ "http-client",
+ "psr-7"
],
- "time": "2014-01-28 22:29:15"
+ "time": "2015-08-12 09:35:40"
},
{
- "name": "symfony/event-dispatcher",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/EventDispatcher",
+ "name": "psr/http-message",
+ "version": "1.0",
"source": {
"type": "git",
- "url": "https://github.com/symfony/EventDispatcher.git",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212"
+ "url": "https://github.com/php-fig/http-message.git",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212",
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"shasum": ""
},
"require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "psr/log": "~1.0",
- "symfony/config": "~2.0",
- "symfony/dependency-injection": "~2.0,<2.6.0",
- "symfony/stopwatch": "~2.2"
- },
- "suggest": {
- "symfony/dependency-injection": "",
- "symfony/http-kernel": ""
+ "php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.5-dev"
+ "dev-master": "1.0.x-dev"
}
},
"autoload": {
- "psr-0": {
- "Symfony\\Component\\EventDispatcher\\": ""
+ "psr-4": {
+ "Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -142,32 +119,85 @@
],
"authors": [
{
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for HTTP messages",
+ "keywords": [
+ "http",
+ "http-message",
+ "psr",
+ "psr-7",
+ "request",
+ "response"
+ ],
+ "time": "2015-05-04 20:22:00"
+ },
+ {
+ "name": "zendframework/zend-diactoros",
+ "version": "1.1.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/zendframework/zend-diactoros.git",
+ "reference": "e2f5c12916c74da384058d0dfbc7fbc0b03d1181"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/e2f5c12916c74da384058d0dfbc7fbc0b03d1181",
+ "reference": "e2f5c12916c74da384058d0dfbc7fbc0b03d1181",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4",
+ "psr/http-message": "~1.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "~1.0.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.6",
+ "squizlabs/php_codesniffer": "^2.3.1"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev",
+ "dev-develop": "1.1-dev"
}
+ },
+ "autoload": {
+ "psr-4": {
+ "Zend\\Diactoros\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-2-Clause"
],
- "description": "Symfony EventDispatcher Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 15:43:05"
+ "description": "PSR HTTP Message implementations",
+ "homepage": "https://github.com/zendframework/zend-diactoros",
+ "keywords": [
+ "http",
+ "psr",
+ "psr-7"
+ ],
+ "time": "2015-08-10 20:04:20"
}
],
"packages-dev": [
{
"name": "doctrine/instantiator",
- "version": "1.0.4",
+ "version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119"
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119",
- "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
@@ -178,7 +208,7 @@
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
- "squizlabs/php_codesniffer": "2.0.*@ALPHA"
+ "squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
@@ -187,8 +217,8 @@
}
},
"autoload": {
- "psr-0": {
- "Doctrine\\Instantiator\\": "src"
+ "psr-4": {
+ "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -208,20 +238,191 @@
"constructor",
"instantiate"
],
- "time": "2014-10-13 12:58:55"
+ "time": "2015-06-14 21:17:01"
+ },
+ {
+ "name": "guzzlehttp/guzzle",
+ "version": "6.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/guzzle.git",
+ "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/66fd14b4d0b8f2389eaf37c5458608c7cb793a81",
+ "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81",
+ "shasum": ""
+ },
+ "require": {
+ "guzzlehttp/promises": "~1.0",
+ "guzzlehttp/psr7": "~1.1",
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "ext-curl": "*",
+ "phpunit/phpunit": "~4.0",
+ "psr/log": "~1.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.1-dev"
+ }
+ },
+ "autoload": {
+ "files": [
+ "src/functions_include.php"
+ ],
+ "psr-4": {
+ "GuzzleHttp\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "Guzzle is a PHP HTTP client library",
+ "homepage": "http://guzzlephp.org/",
+ "keywords": [
+ "client",
+ "curl",
+ "framework",
+ "http",
+ "http client",
+ "rest",
+ "web service"
+ ],
+ "time": "2015-09-08 17:36:26"
+ },
+ {
+ "name": "guzzlehttp/promises",
+ "version": "1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/promises.git",
+ "reference": "97fe7210def29451ec74923b27e552238defd75a"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/97fe7210def29451ec74923b27e552238defd75a",
+ "reference": "97fe7210def29451ec74923b27e552238defd75a",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Promise\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "Guzzle promises library",
+ "keywords": [
+ "promise"
+ ],
+ "time": "2015-08-15 19:37:21"
+ },
+ {
+ "name": "guzzlehttp/psr7",
+ "version": "1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
+ "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "1.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Psr7\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "PSR-7 message implementation",
+ "keywords": [
+ "http",
+ "message",
+ "stream",
+ "uri"
+ ],
+ "time": "2015-08-15 19:32:36"
},
{
"name": "phpunit/php-code-coverage",
- "version": "2.0.11",
+ "version": "2.2.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7"
+ "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7",
- "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef1ca6835468857944d5c3b48fa503d5554cff2f",
+ "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f",
"shasum": ""
},
"require": {
@@ -229,12 +430,12 @@
"phpunit/php-file-iterator": "~1.3",
"phpunit/php-text-template": "~1.2",
"phpunit/php-token-stream": "~1.3",
- "sebastian/environment": "~1.0",
+ "sebastian/environment": "^1.3.2",
"sebastian/version": "~1.0"
},
"require-dev": {
"ext-xdebug": ">=2.1.4",
- "phpunit/phpunit": "~4.1"
+ "phpunit/phpunit": "~4"
},
"suggest": {
"ext-dom": "*",
@@ -244,7 +445,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0.x-dev"
+ "dev-master": "2.2.x-dev"
}
},
"autoload": {
@@ -253,9 +454,6 @@
]
},
"notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
"license": [
"BSD-3-Clause"
],
@@ -273,7 +471,7 @@
"testing",
"xunit"
],
- "time": "2014-08-31 06:33:04"
+ "time": "2015-09-14 06:51:16"
},
{
"name": "phpunit/php-file-iterator",
@@ -322,16 +520,16 @@
},
{
"name": "phpunit/php-text-template",
- "version": "1.2.0",
+ "version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
- "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
- "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
"shasum": ""
},
"require": {
@@ -340,20 +538,17 @@
"type": "library",
"autoload": {
"classmap": [
- "Text/"
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
+ "email": "sebastian@phpunit.de",
"role": "lead"
}
],
@@ -362,20 +557,20 @@
"keywords": [
"template"
],
- "time": "2014-01-30 17:20:04"
+ "time": "2015-06-21 13:50:34"
},
{
"name": "phpunit/php-timer",
- "version": "1.0.5",
+ "version": "1.0.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
- "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
- "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
"shasum": ""
},
"require": {
@@ -384,13 +579,10 @@
"type": "library",
"autoload": {
"classmap": [
- "PHP/"
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
"license": [
"BSD-3-Clause"
],
@@ -406,20 +598,20 @@
"keywords": [
"timer"
],
- "time": "2013-08-02 07:42:54"
+ "time": "2015-06-21 08:01:12"
},
{
"name": "phpunit/php-token-stream",
- "version": "1.3.0",
+ "version": "1.4.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "f8d5d08c56de5cfd592b3340424a81733259a876"
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876",
- "reference": "f8d5d08c56de5cfd592b3340424a81733259a876",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
"shasum": ""
},
"require": {
@@ -432,7 +624,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.3-dev"
+ "dev-master": "1.4-dev"
}
},
"autoload": {
@@ -455,7 +647,7 @@
"keywords": [
"tokenizer"
],
- "time": "2014-08-31 06:12:13"
+ "time": "2015-09-15 10:49:45"
},
{
"name": "phpunit/phpunit",
@@ -533,25 +725,26 @@
},
{
"name": "phpunit/phpunit-mock-objects",
- "version": "2.3.0",
+ "version": "2.3.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "c63d2367247365f688544f0d500af90a11a44c65"
+ "reference": "5e2645ad49d196e020b85598d7c97e482725786a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65",
- "reference": "c63d2367247365f688544f0d500af90a11a44c65",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a",
+ "reference": "5e2645ad49d196e020b85598d7c97e482725786a",
"shasum": ""
},
"require": {
- "doctrine/instantiator": "~1.0,>=1.0.1",
+ "doctrine/instantiator": "^1.0.2",
"php": ">=5.3.3",
- "phpunit/php-text-template": "~1.2"
+ "phpunit/php-text-template": "~1.2",
+ "sebastian/exporter": "~1.2"
},
"require-dev": {
- "phpunit/phpunit": "~4.3"
+ "phpunit/phpunit": "~4.4"
},
"suggest": {
"ext-soap": "*"
@@ -584,34 +777,34 @@
"mock",
"xunit"
],
- "time": "2014-10-03 05:12:11"
+ "time": "2015-08-19 09:14:08"
},
{
"name": "sebastian/comparator",
- "version": "1.0.1",
+ "version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
- "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef"
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef",
- "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
- "sebastian/diff": "~1.1",
- "sebastian/exporter": "~1.0"
+ "sebastian/diff": "~1.2",
+ "sebastian/exporter": "~1.2"
},
"require-dev": {
- "phpunit/phpunit": "~4.1"
+ "phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.2.x-dev"
}
},
"autoload": {
@@ -648,20 +841,20 @@
"compare",
"equality"
],
- "time": "2014-05-11 23:00:21"
+ "time": "2015-07-26 15:48:44"
},
{
"name": "sebastian/diff",
- "version": "1.2.0",
+ "version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
- "reference": "5843509fed39dee4b356a306401e9dd1a931fec7"
+ "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7",
- "reference": "5843509fed39dee4b356a306401e9dd1a931fec7",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
+ "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
"shasum": ""
},
"require": {
@@ -673,7 +866,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.2-dev"
+ "dev-master": "1.3-dev"
}
},
"autoload": {
@@ -700,32 +893,32 @@
"keywords": [
"diff"
],
- "time": "2014-08-15 10:29:00"
+ "time": "2015-02-22 15:13:53"
},
{
"name": "sebastian/environment",
- "version": "1.2.0",
+ "version": "1.3.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d"
+ "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d",
- "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44",
+ "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
- "phpunit/phpunit": "~4.3"
+ "phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.2.x-dev"
+ "dev-master": "1.3.x-dev"
}
},
"autoload": {
@@ -750,32 +943,33 @@
"environment",
"hhvm"
],
- "time": "2014-10-22 06:38:05"
+ "time": "2015-08-03 06:14:51"
},
{
"name": "sebastian/exporter",
- "version": "1.0.2",
+ "version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0"
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0",
- "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e",
"shasum": ""
},
"require": {
- "php": ">=5.3.3"
+ "php": ">=5.3.3",
+ "sebastian/recursion-context": "~1.0"
},
"require-dev": {
- "phpunit/phpunit": "~4.0"
+ "phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.2.x-dev"
}
},
"autoload": {
@@ -815,20 +1009,73 @@
"export",
"exporter"
],
- "time": "2014-09-10 00:51:36"
+ "time": "2015-06-21 07:55:53"
+ },
+ {
+ "name": "sebastian/recursion-context",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/recursion-context.git",
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba",
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
+ {
+ "name": "Adam Harvey",
+ "email": "aharvey@php.net"
+ }
+ ],
+ "description": "Provides functionality to recursively process PHP variables",
+ "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "time": "2015-06-21 08:04:50"
},
{
"name": "sebastian/version",
- "version": "1.0.3",
+ "version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
- "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43"
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
- "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
"shasum": ""
},
"type": "library",
@@ -850,34 +1097,36 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
- "time": "2014-03-07 15:35:33"
+ "time": "2015-06-21 13:59:46"
},
{
"name": "symfony/yaml",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Yaml",
+ "version": "v2.7.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
- "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726"
+ "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726",
- "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726",
+ "url": "https://api.github.com/repos/symfony/Yaml/zipball/2dc7b06c065df96cc686c66da2705e5e18aef661",
+ "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661",
"shasum": ""
},
"require": {
- "php": ">=5.3.3"
+ "php": ">=5.3.9"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "~2.7"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.5-dev"
+ "dev-master": "2.7-dev"
}
},
"autoload": {
- "psr-0": {
+ "psr-4": {
"Symfony\\Component\\Yaml\\": ""
}
},
@@ -887,24 +1136,26 @@
],
"authors": [
{
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 05:50:18"
+ "homepage": "https://symfony.com",
+ "time": "2015-08-24 07:13:45"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
"platform": {
- "php": ">=5.3.0"
+ "php": ">=5.5.0"
},
"platform-dev": []
}
diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php
index db06b68..2005a75 100644
--- a/examples/transmission/get_all_transmissions.php
+++ b/examples/transmission/get_all_transmissions.php
@@ -4,14 +4,19 @@ require_once (dirname(__FILE__).'/../bootstrap.php');
use SparkPost\SparkPost;
use SparkPost\Transmission;
+use GuzzleHttp\Client;
+use Ivory\HttpAdapter\Guzzle6HttpAdapter;
-$key = 'YOURAPIKEY';
-SparkPost::setConfig(array('key'=>$key));
+$key = 'YOURAPIKEY';
+$httpAdapter = new Guzzle6HttpAdapter(new Client());
+SparkPost::setConfig($httpAdapter, ['key'=>$key]);
try {
$results = Transmission::all();
+ echo "it returned!!!";
+ var_dump($results);
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
}
-?> \ No newline at end of file
+?>
diff --git a/lib/SparkPost/APIResource.php b/lib/SparkPost/APIResource.php
index 469ba7e..be3d788 100644
--- a/lib/SparkPost/APIResource.php
+++ b/lib/SparkPost/APIResource.php
@@ -1,65 +1,36 @@
<?php
namespace SparkPost;
-use Guzzle\Http\Client;
-use Guzzle\Http\Exception\ClientErrorResponseException;
+use Ivory\HttpAdapter\HttpAdapterException;
/**
* @desc SDK interface for managing SparkPost API endpoints
*/
class APIResource {
-
+
/**
* @desc name of the API endpoint, mainly used for URL construction.
* @var string
*/
public static $endpoint;
-
- /**
- * @desc singleton holder to create a guzzle http client
- * @var \GuzzleHttp\Client
- */
- protected static $request;
-
+
/**
* @desc Mapping for values passed into the send method to the values needed for the respective API
* @var array
*/
protected static $parameterMappings = array();
-
+
/**
* @desc Sets up default structure and default values for the model that is acceptable by the API
* @var array
*/
protected static $structure = array();
-
+
/**
* @desc Ensure that this class cannot be instansiated
*/
private function __construct() {}
/**
- * @desc Creates and returns a guzzle http client.
- * @return \GuzzleHttp\Client
- */
- protected static function getHttpClient() {
- if(!isset(self::$request)) {
- self::$request = new Client();
- }
- return self::$request;
- }
-
- /**
- * @desc Private Method helper to get the configuration values to create the base url for the current API endpoint
- *
- * @return string base url for the transmissions API
- */
- protected static function getBaseUrl($config) {
- $baseUrl = '/api/' . $config['version'] . '/' . static::$endpoint;
- return $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . $baseUrl;
- }
-
-
- /**
* @desc Private Method helper to reference parameter mappings and set the right value for the right parameter
*/
protected static function setMappedValue (&$model, $mapKey, $value) {
@@ -74,7 +45,7 @@ class APIResource {
} else {
return;
}
-
+
$path = explode('.', $mapPath);
$temp = &$model;
foreach( $path as $key ) {
@@ -84,57 +55,30 @@ class APIResource {
$temp = &$temp[$key];
}
$temp = $value;
-
+
}
-
+
protected static function buildRequestModel( $requestConfig, $model=array() ) {
foreach($requestConfig as $key=>$value) {
self::setMappedValue($model, $key, $value);
}
return $model;
}
-
+
/**
- * @desc Method for issuing POST requests
- *
- * @return array API repsonse represented as key-value pairs
+ * TODO: Docs
*/
- public static function sendRequest( $requestConfig ) {
- $hostConfig = SparkPost::getConfig();
- $request = self::getHttpClient();
-
- //create model from $transmissionConfig
- $model = static::$structure;
- $requestModel = self::buildRequestModel( $requestConfig, $model );
-
- //send the request
- try {
- $response = $request->post(
- self::getBaseUrl($hostConfig),
- array('authorization' => $hostConfig['key']),
- json_encode($requestModel),
- array("verify"=>$hostConfig['strictSSL'])
- )->send();
-
- return $response->json();
- }
- /*
- * Handles 4XX responses
- */
- catch (ClientErrorResponseException $exception) {
- $response = $exception->getResponse();
- $responseArray = $response->json();
- throw new \Exception(json_encode($responseArray['errors']));
- }
- /*
- * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
- */
- catch (\Exception $exception) {
- throw new \Exception("Unable to contact ".ucfirst(static::$endpoint)." API: ". $exception->getMessage());
- }
+ public static function create(Array $body=[]) {
+ return self::callResource( 'post', '/', ['body'=>$options]);
+ }
+
+ /**
+ * TODO: Docs
+ */
+ public static function update(String $resourcePath, Array $body=[]) {
+ return self::callResource( 'post', $resourcePath, ['body'=>$options]);
}
-
/**
* @desc Wrapper method for issuing GET request to current API endpoint
*
@@ -142,10 +86,10 @@ class APIResource {
* @param array $options (optional) query string parameters
* @return array Result set of transmissions found
*/
- public static function fetchResource( $resourcePath=null, $options=array() ) {
+ public static function get(String $resourcePath=null, Array $options=[] ) {
return self::callResource( 'get', $resourcePath, $options );
}
-
+
/**
* @desc Wrapper method for issuing DELETE request to current API endpoint
*
@@ -153,10 +97,10 @@ class APIResource {
* @param array $options (optional) query string parameters
* @return array Result set of transmissions found
*/
- public static function deleteResource( $resourcePath=null, $options=array() ) {
+ public static function delete(String $resourcePath=null, Array $options=[] ) {
return self::callResource( 'delete', $resourcePath, $options );
}
-
+
/**
* @desc Private Method for issuing GET and DELETE request to current API endpoint
*
@@ -170,41 +114,48 @@ class APIResource {
* @param array $options (optional) query string parameters
* @return array Result set of action performed on resource
*/
- private static function callResource( $action, $resourcePath=null, $options=array() ) {
-
- if( !in_array( $action, array('get', 'delete') ) ) throw new \Exception('Invalid resource action');
-
- //build the url
- $hostConfig = SparkPost::getConfig();
- $url = self::getBaseUrl($hostConfig);
+ private static function callResource( $action, $resourcePath=null, $options=[] ) {
+ $action = strtoupper($action); // normalize
+
+ if( !in_array($action, ['POST', 'PUT', 'GET', 'DELETE'])) {
+ throw new \Exception('Invalid resource action');
+ }
+
+ $url = '/'.static::$endpoint;
+ $body = null;
if (!is_null($resourcePath)){
- $url .= '/'.$resourcePath;
+ $url .= $url.$resourcePath;
}
-
+
// untested:
- if( !empty($options) ) {
- $queryString = http_build_query($options);
+ if( !empty($options['query'])) {
+ $queryString = http_build_query($options['query']);
$url .= '?'.$queryString;
}
-
- $request = self::getHttpClient();
-
+
+ if( !empty($options['body']) ) {
+ $model = static::$structure;
+ $requestModel = self::buildRequestModel( $requestConfig, $options['body'] );
+ $body = json_encode($requestModel);
+ }
+
//make request
try {
- $response = $request->{$action}($url, array('authorization' => $hostConfig['key']), array("verify"=>$hostConfig['strictSSL']))->send();
- return $response->json();
+ $httpAdapter = SparkPost::getHttpAdapter();
+ $response = SparkPost::getHttpAdapter()->send($url, $action, SparkPost::getHttpHeaders(), $body);
+ return json_decode($response->getBody()->getContents(), true);
}
/*
* Handles 4XX responses
*/
- catch (ClientErrorResponseException $exception) {
- $response = $exception->getResponse();
- $statusCode = $response->getStatusCode();
- if($statusCode === 404) {
- throw new \Exception("The specified resource does not exist", 404);
- }
- throw new \Exception("Received bad response from ".ucfirst(static::$endpoint)." API: ". $statusCode );
- }
+ // catch (HttpAdapterException $exception) {
+ // $response = $exception->getResponse();
+ // $statusCode = $response->getStatusCode();
+ // if($statusCode === 404) {
+ // throw new \Exception("The specified resource does not exist", 404);
+ // }
+ // throw new \Exception("Received bad response from ".ucfirst(static::$endpoint)." API: ". $statusCode );
+ // }
/*
* Handles 5XX Errors, Configuration Errors, and a catch all for other errors
*/
@@ -212,5 +163,5 @@ class APIResource {
throw new \Exception("Unable to contact ".ucfirst(static::$endpoint)." API: ". $exception->getMessage());
}
}
-
+
}
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index 755df46..3b54ada 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -1,30 +1,34 @@
<?php
namespace SparkPost;
+use Ivory\HttpAdapter;
+use Ivory\HttpAdapter\Configuration;
class SparkPost {
-
+
private static $config;
+ private static $httpAdapter;
+
private static $defaults = array(
'host'=>'api.sparkpost.com',
'protocol'=>'https',
'port'=>443,
'strictSSL'=>true,
'key'=>'',
- 'version'=>'v1'
+ 'version'=>'v1'
);
-
+
/**
* Enforce that this object can't be instansiated
*/
private function __construct(){}
-
+
/**
* Allows the user to pass in values to override the defaults and set their API key
* @param Array $configMap - Hashmap that contains config values for the SDK to connect to SparkPost
* @throws \Exception
*/
- public static function setConfig(array $configMap) {
- //check for API key because its required
+ public static function setConfig($httpAdapter, array $configMap) {
+ //check for API key because its required
if (isset($configMap['key'])){
$key = trim($configMap['key']);
if(empty($key)){
@@ -33,28 +37,88 @@ class SparkPost {
} else {
throw new \Exception('You must provide an API key');
}
+ // TODO: need to figure out how to enforce this
+ // if (!$httpAdapter instanceOf HttpAdapterInterface) {
+ // throw new \Exception('First Argument must be a valid Ivory\HttpAdapter');
+ // }
+
self::$config = self::$defaults;
+
+ self::$httpAdapter = $httpAdapter;
+
foreach ($configMap as $configOption => $configValue) {
if(key_exists($configOption, self::$config)) {
self::$config[$configOption] = $configValue;
}
}
+
+ self::$httpAdapter->setConfiguration(self::getHttpConfig(self::$config));
+ }
+
+
+ /**
+ * @desc Merges passed in headers with default headers for http requests
+ * @return Array - headers to be set on http requests
+ */
+ public static function getHttpHeaders(Array $headers = null) {
+ $defaultOptions = [
+ 'Authorization' => self::$config['key'],
+ 'Content-Type' => 'application/json',
+ ];
+
+ // Merge passed in headers with defaults
+ if (!is_null($headers)) {
+ foreach ($headers as $header => $value) {
+ $defaultOptions[$header] = $value;
+ }
+ }
+ return $defaultOptions;
+ }
+
+
+ /**
+ * @desc Helper function for getting the configuration for http requests
+ * @return \Ivory\HttpAdapter\Configuration
+ */
+ // TODO: Need to figure out how to set strictSSL
+ private static function getHttpConfig($config) {
+ // get composer.json to extract version number
+ $composerFile = file_get_contents(dirname(__FILE__) . "/../../composer.json");
+ $composer = json_decode($composerFile, true);
+
+ // create Configuration for http adapter
+ $httpConfig = new Configuration();
+ $baseUrl = $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . '/api/' . $config['version'];
+ $httpConfig->setBaseUri($baseUrl);
+ $httpConfig->setUserAgent('php-sparkpost/' . $composer['version']);
+ return $httpConfig;
}
-
+
/**
* Retrieves the configuration that was previously setup by the user
* @throws \Exception
*/
public static function getConfig() {
- if (self::$config === null) {
+ if (self::$config === null) {
throw new \Exception('No configuration has been provided');
}
return self::$config;
}
-
+
public static function unsetConfig() {
self::$config = NULL;
}
+
+ /**
+ * Retrieves the Http Adapter that was previously setup by the user
+ * @throws \Exception
+ */
+ public static function getHttpAdapter() {
+ if (self::$config === null) {
+ throw new \Exception('No Http Adapter has been provided');
+ }
+ return self::$httpAdapter;
+ }
}
-?> \ No newline at end of file
+?>
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index 4e54f1d..82cc11d 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -7,11 +7,11 @@ use Guzzle\Http\Exception\ClientErrorResponseException;
* @desc SDK interface for managing transmissions
*/
class Transmission extends APIResource {
-
+
public static $endpoint = 'transmissions';
-
+
/**
- * @desc Mapping for values passed into the send method to the values needed for the Transmission API
+ * @desc Mapping for values passed into the send method to the values needed for the Transmission API
* @var array
*/
protected static $parameterMappings = array(
@@ -34,7 +34,7 @@ class Transmission extends APIResource {
'trackClicks'=>'options.click_tracking',
'useDraftTemplate'=>'use_draft_template'
);
-
+
/**
* @desc Sets up default structure and default values for the model that is acceptable by the API
* @var array
@@ -42,20 +42,20 @@ class Transmission extends APIResource {
protected static $structure = array(
'return_path'=>"default@sparkpostmail.com",
'content'=>array(
- 'html'=>null,
+ 'html'=>null,
'text'=>null,
'email_rfc822'=>null
),
'use_draft_template'=>false
);
-
+
/**
* @desc Method for issuing POST request to the Transmissions API
*
* This method assumes that all the appropriate fields have
- * been populated by the user through configuration. Acceptable
- * configuration values are:
- * 'campaign': string,
+ * been populated by the user through configuration. Acceptable
+ * configuration values are:
+ * 'campaign': string,
* 'metadata': array,
* 'substitutionData': array,
* 'description': string,
@@ -71,42 +71,38 @@ class Transmission extends APIResource {
* 'template': string,
* 'trackOpens': boolean,
* 'trackClicks': boolean,
- * 'useDraftTemplate': boolean
+ * 'useDraftTemplate': boolean
*
* @return array API repsonse represented as key-value pairs
*/
public static function send( $transmissionConfig ) {
- return self::sendRequest( $transmissionConfig );
+ return self::create( $transmissionConfig );
}
-
+
/**
* @desc Method for retrieving information about all transmissions
* Wrapper method for a cleaner interface
- *
+ *
* @return array result Set of transmissions
*/
public static function all( $campaignID=null, $templateID=null ) {
$options = array();
if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID;
if( $templateID !== NULL ) $options['template_id'] = $templateID;
-
- return self::fetchResource( null, $options );
+
+ return self::get( null, $options );
}
-
+
/**
* @desc Method for retrieving information about a single transmission
* Wrapper method for a cleaner interface
- *
+ *
* @param string $transmissionID Identifier of the transmission to be found
* @return array result Single transmission represented in key-value pairs
*/
public static function find($transmissionID) {
- return self::fetchResource($transmissionID);
- }
-
- public static function delete( $transmissionID ) {
- return self::deleteResource($transmissionID);
+ return self::get($transmissionID);
}
}
-?> \ No newline at end of file
+?>