summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md44
-rw-r--r--RoboFile.php17
-rw-r--r--composer.json19
-rw-r--r--composer.lock620
-rw-r--r--examples/transmission/get_all_transmissions.php6
-rw-r--r--examples/transmission/get_transmission.php6
-rw-r--r--examples/transmission/rfc822.php24
-rw-r--r--examples/transmission/send_transmission_all_fields.php38
-rw-r--r--examples/transmission/simple_send.php (renamed from examples/transmission/configuration_based.php)23
-rw-r--r--examples/transmission/stored_recipients_inline_content.php10
-rw-r--r--examples/transmission/stored_template_send.php22
-rw-r--r--lib/SendGridCompatibility/Email.php199
-rw-r--r--lib/SendGridCompatibility/SendGrid.php22
-rw-r--r--lib/SparkPost/SparkPost.php (renamed from lib/MessageSystems/SparkPost.php)13
-rw-r--r--lib/SparkPost/Transmission.php (renamed from lib/MessageSystems/Transmission.php)83
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php161
-rw-r--r--test/unit/SparkPostTest.php10
-rw-r--r--test/unit/TransmissionTest.php118
18 files changed, 695 insertions, 740 deletions
diff --git a/README.md b/README.md
index 3520ace..74bcb64 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ curl -sS https://getcomposer.org/installer | php
```
Next, run the Composer command to install the SparkPost PHP SDK:
```
-composer require messagesystems/php-sdk
+composer require sparkpost/php-sparkpost
```
After installing, you need to require Composer's autoloader:
```
@@ -26,14 +26,14 @@ SparkPost::setConfig(["key"=>"YOUR API KEY"]);
try {
// Build your email and send it!
- Transmission::send(['campaign'=>'first-mailing',
+ Transmission::send(array('campaign'=>'first-mailing',
'from'=>'you@your-company.com',
'subject'=>'First SDK Mailing',
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
- 'substitutionData'=>['name'=>'YOUR FIRST NAME'],
- 'recipients'=>[['address'=>['name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' ]]]
- ]);
+ 'substitutionData'=>array('name'=>'YOUR FIRST NAME'),
+ 'recipients'=>array(array('address'=>array('name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' )))
+ ));
echo 'Woohoo! You just sent your first mailing!';
} catch (Exception $err) {
@@ -44,9 +44,33 @@ try {
## Learn More
* For more detailed examples, check our examples:
- * [Transmissions](https://github.com/MessageSystems/php-sdk/tree/master/examples/transmission/)
+ * [Transmissions](https://github.com/SparkPost/php-sparkpost/tree/master/examples/transmission)
* Read our REST API documentation - <http://www.sparkpost.com/docs/introduction>
+## Field Descriptions
+### Transmissions
+| Field Name | Required? | Description | Data Type |
+| ------------ | ----------- | ------------- | ----------- |
+| description | no | Field for describing what this transmission is for the user | String |
+| campaign | no | Field for assigning a given transmission to a specific campaign, which is a logical container for similar transmissions | String |
+| metadata | no | Field for adding arbitrary key/value pairs which will be included in open/click tracking | Object (Simple) |
+| substitutionData | no | Field for adding transmission level substitution data, which can be used in a variety of fields and in content | Object (Complex) |
+| trackOpens | no | Field for enabling/disabling transmission level open tracking (default: true) | Boolean |
+| trackClicks | no | Field for enabling/disabling transmission level click tracking (default: true) | Boolean |
+| useDraftTemplate | no | Field for allowing the sending of a transmission using a draft of a stored template (default: false) | Boolean |
+| replyTo | no | Field for specifying the email address that should be used when a recipient hits the reply button | String |
+| subject | yes | Field for setting the subject line of a given transmission | String |
+| from | yes | Field for setting the from line of a given transmission | String or Object |
+| html | yes** | Field for setting the HTML content of a given transmission | String |
+| text | yes** | Field for setting the Plain Text content of a given transmission | String |
+| rfc822 | no** | Field for setting the RFC-822 encoded content of a given transmission | String |
+| template | no** | Field for specifying the Template ID of a stored template to be used when sending a given transmission | String |
+| customHeaders | no | Field for specifying additional headers to be applied to a given transmission (other than Subject, From, To, and Reply-To) | Object (Simple) |
+| recipients | yes** | Field for specifying who a given transmission should be sent to | Array of Objects |
+| recipientList | no** | Field for specifying a stored recipient list ID to be used for a given transmission | String |
+
+** - If using inline content then html or text are required. If using RFC-822 Inline Content, then rfc822 is required. If using a stored recipient list, then recipientList is required. If using a stored template, then template is required.
+
## Tips and Tricks
### General
* You _must_ provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]`
@@ -63,12 +87,12 @@ try {
## Development
### Setup
-We use [Robo](http://robo.li/) for our task runner.
-
-Run `composer install` inside the directory to install dependecies and development tools including Robo.
+Run `composer install` inside the directory to install dependecies and development tools.
### Testing
-Once all the dependencies are installed, you can execute the unit tests using `vendor\bin\robo test`
+Once all the dependencies are installed, you can execute the unit tests using `vendor/bin/phpunit --bootstrap test/unit/bootstrap.php ./test/unit`.
+
+If you're interested in code coverage, you can add the `--coverage` flag for phpunit like so: ```phpunit --coverage-html test/output/report --bootstrap test/unit/bootstrap.php ./test/unit```
### Contributing
Guidelines for adding issues
diff --git a/RoboFile.php b/RoboFile.php
deleted file mode 100644
index 9245e1b..0000000
--- a/RoboFile.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-/**
- * This is project's console commands configuration for Robo task runner.
- *
- * @see http://robo.li/
- */
-class RoboFile extends \Robo\Tasks
-{
- public function test () {
- $res = $this->taskExec('phpunit --coverage-html test/output/report --bootstrap test/unit/bootstrap.php ./test/unit')->run();
-
- // print message when tests passed
- if ($res->wasSuccessful()) $this->say("All tests passed");
-
- return $res();
- }
-}
diff --git a/composer.json b/composer.json
index 5bfd63a..096a94b 100644
--- a/composer.json
+++ b/composer.json
@@ -1,25 +1,24 @@
{
- "name": "messagesystems/php-sdk",
- "description": "SDK for interfacing with messagesystems APIs",
- "license": "Apache",
+ "name": "sparkpost/php-sparkpost",
+ "description": "SDK for interfacing with SparkPost APIs",
+ "license": "Apache 2.0",
"authors": [
{
- "name": "Message Systems",
- "email": "info@messagesystems.com"
+ "name": "Message Systems, Inc."
}
],
"minimum-stability": "stable",
"require": {
- "php": ">=5.6.1",
- "guzzlehttp/guzzle": "5.0.1"
+ "php": ">=5.3.0",
+ "guzzlehttp/guzzle": "3.8.1"
},
"require-dev": {
- "phpunit/phpunit": "4.3.*",
- "codegyre/robo": "0.4.6"
+ "phpunit/phpunit": "4.3.*"
},
"autoload": {
"psr-4": {
- "MessageSystems\\": "lib/MessageSystems/"
+ "SparkPost\\": "lib/SparkPost/",
+ "SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/"
}
}
}
diff --git a/composer.lock b/composer.lock
index a2c948d..56e173b 100644
--- a/composer.lock
+++ b/composer.lock
@@ -3,40 +3,70 @@
"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"
],
- "hash": "25bb67c57c5a357f0cc9873a717dfd51",
+ "hash": "6f9c9d455eb869305157559b093a3c5d",
"packages": [
{
"name": "guzzlehttp/guzzle",
- "version": "5.0.1",
+ "version": "v3.8.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd"
+ "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9e806208d9b418a58ec86c49078aa94385e64bbd",
- "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
+ "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
"shasum": ""
},
"require": {
- "guzzlehttp/ringphp": "~1.0",
- "php": ">=5.4.0"
+ "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"
},
"require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0",
- "psr/log": "~1.0"
+ "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"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-ring": "5.0-dev"
+ "dev-master": "3.8-dev"
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\": "src/"
+ "psr-0": {
+ "Guzzle": "src/",
+ "Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -48,6 +78,10 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Guzzle Community",
+ "homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
@@ -61,87 +95,45 @@
"rest",
"web service"
],
- "time": "2014-10-16 18:00:41"
+ "time": "2014-01-28 22:29:15"
},
{
- "name": "guzzlehttp/ringphp",
- "version": "1.0.2",
+ "name": "symfony/event-dispatcher",
+ "version": "v2.5.6",
+ "target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/RingPHP.git",
- "reference": "86df4c0ea5459b292ff8c519f8db1513ea41ca9b"
+ "url": "https://github.com/symfony/EventDispatcher.git",
+ "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/86df4c0ea5459b292ff8c519f8db1513ea41ca9b",
- "reference": "86df4c0ea5459b292ff8c519f8db1513ea41ca9b",
+ "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212",
+ "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212",
"shasum": ""
},
"require": {
- "guzzlehttp/streams": "~3.0",
- "php": ">=5.4.0",
- "react/promise": "~2.0"
+ "php": ">=5.3.3"
},
"require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0"
+ "psr/log": "~1.0",
+ "symfony/config": "~2.0",
+ "symfony/dependency-injection": "~2.0,<2.6.0",
+ "symfony/stopwatch": "~2.2"
},
"suggest": {
- "ext-curl": "Guzzle will use specific adapters if cURL is present"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0-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"
- }
- ],
- "time": "2014-10-29 02:00:14"
- },
- {
- "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"
+ "symfony/dependency-injection": "",
+ "symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-master": "2.5-dev"
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\Stream\\": "src/"
+ "psr-0": {
+ "Symfony\\Component\\EventDispatcher\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -150,115 +142,21 @@
],
"authors": [
{
- "name": "Michael Dowling",
- "email": "mtdowling@gmail.com",
- "homepage": "https://github.com/mtdowling"
- }
- ],
- "description": "Provides a simple abstraction over streams of data",
- "homepage": "http://guzzlephp.org/",
- "keywords": [
- "Guzzle",
- "stream"
- ],
- "time": "2014-10-12 19:18:40"
- },
- {
- "name": "react/promise",
- "version": "v2.1.0",
- "source": {
- "type": "git",
- "url": "https://github.com/reactphp/promise.git",
- "reference": "937b04f1b0ee8f6d180e75a0830aac778ca4bcd6"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/reactphp/promise/zipball/937b04f1b0ee8f6d180e75a0830aac778ca4bcd6",
- "reference": "937b04f1b0ee8f6d180e75a0830aac778ca4bcd6",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "React\\Promise\\": "src/"
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
},
- "files": [
- "src/functions.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
{
- "name": "Jan Sorgalla",
- "email": "jsorgalla@googlemail.com"
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
}
],
- "description": "A lightweight implementation of CommonJS Promises/A for PHP",
- "time": "2014-10-15 20:05:57"
+ "description": "Symfony EventDispatcher Component",
+ "homepage": "http://symfony.com",
+ "time": "2014-10-01 15:43:05"
}
],
"packages-dev": [
{
- "name": "codegyre/robo",
- "version": "0.4.6",
- "source": {
- "type": "git",
- "url": "https://github.com/Codegyre/Robo.git",
- "reference": "ba257924e3ff9bdcb9899225e9f24957c7e4b3f3"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/Codegyre/Robo/zipball/ba257924e3ff9bdcb9899225e9f24957c7e4b3f3",
- "reference": "ba257924e3ff9bdcb9899225e9f24957c7e4b3f3",
- "shasum": ""
- },
- "require": {
- "henrikbjorn/lurker": "1.0.*@dev",
- "php": ">=5.4.0",
- "symfony/console": "~2.1",
- "symfony/filesystem": "~2.1",
- "symfony/finder": "~2.1",
- "symfony/process": "~2.1"
- },
- "require-dev": {
- "codeception/aspect-mock": "0.4.*",
- "codeception/codeception": "~2.0",
- "codeception/verify": "0.2.*"
- },
- "bin": [
- "robo"
- ],
- "type": "library",
- "autoload": {
- "psr-4": {
- "Robo\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Davert",
- "email": "davert.php@resend.cc"
- }
- ],
- "description": "Modern task runner",
- "time": "2014-10-17 00:55:05"
- },
- {
"name": "doctrine/instantiator",
"version": "1.0.4",
"source": {
@@ -313,67 +211,6 @@
"time": "2014-10-13 12:58:55"
},
{
- "name": "henrikbjorn/lurker",
- "version": "1.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/henrikbjorn/Lurker.git",
- "reference": "a020d45b3bc37810aeafe27343c51af8a74c9419"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/henrikbjorn/Lurker/zipball/a020d45b3bc37810aeafe27343c51af8a74c9419",
- "reference": "a020d45b3bc37810aeafe27343c51af8a74c9419",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "symfony/config": "~2.2",
- "symfony/event-dispatcher": "~2.2"
- },
- "suggest": {
- "ext-inotify": ">=0.1.6"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Lurker": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Henrik Bjornskov",
- "email": "henrik@bjrnskov.dk",
- "homepage": "http://henrik.bjrnskov.dk"
- },
- {
- "name": "Konstantin Kudryashov",
- "email": "ever.zet@gmail.com",
- "homepage": "http://everzet.com"
- },
- {
- "name": "Yaroslav Kiliba",
- "email": "om.dattaya@gmail.com"
- }
- ],
- "description": "Resource Watcher.",
- "keywords": [
- "filesystem",
- "resource",
- "watching"
- ],
- "time": "2013-05-24 06:47:29"
- },
- {
"name": "phpunit/php-code-coverage",
"version": "2.0.11",
"source": {
@@ -622,16 +459,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "4.3.4",
+ "version": "4.3.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71"
+ "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/23e4e0310f037aae873cc81b8658dbbb82878f71",
- "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
+ "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
"shasum": ""
},
"require": {
@@ -692,7 +529,7 @@
"testing",
"xunit"
],
- "time": "2014-10-22 11:43:12"
+ "time": "2014-11-11 10:11:09"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -1016,307 +853,6 @@
"time": "2014-03-07 15:35:33"
},
{
- "name": "symfony/config",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Config",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Config.git",
- "reference": "0316364bfebc8b080077c731a99f189341476bd7"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Config/zipball/0316364bfebc8b080077c731a99f189341476bd7",
- "reference": "0316364bfebc8b080077c731a99f189341476bd7",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "symfony/filesystem": "~2.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Config\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Config Component",
- "homepage": "http://symfony.com",
- "time": "2014-09-23 05:25:11"
- },
- {
- "name": "symfony/console",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Console",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Console.git",
- "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Console/zipball/6f177fca24200a5b97aef5ce7a5c98124a0f0db0",
- "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "psr/log": "~1.0",
- "symfony/event-dispatcher": "~2.1"
- },
- "suggest": {
- "psr/log": "For using the console logger",
- "symfony/event-dispatcher": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Console\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Console Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-05 13:57:04"
- },
- {
- "name": "symfony/event-dispatcher",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/EventDispatcher",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/EventDispatcher.git",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212",
- "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": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\EventDispatcher\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony EventDispatcher Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 15:43:05"
- },
- {
- "name": "symfony/filesystem",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Filesystem",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Filesystem.git",
- "reference": "4e62fab0060a826561c78b665925b37c870c45f5"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Filesystem/zipball/4e62fab0060a826561c78b665925b37c870c45f5",
- "reference": "4e62fab0060a826561c78b665925b37c870c45f5",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Filesystem\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Filesystem Component",
- "homepage": "http://symfony.com",
- "time": "2014-09-22 09:14:18"
- },
- {
- "name": "symfony/finder",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Finder",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Finder.git",
- "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Finder/zipball/cf66df4e783e6aade319b273c9bcf9e42aa9b10f",
- "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Finder\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Finder Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 05:50:18"
- },
- {
- "name": "symfony/process",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Process",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Process.git",
- "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Process/zipball/9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a",
- "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Process\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Process Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 05:50:18"
- },
- {
"name": "symfony/yaml",
"version": "v2.5.6",
"target-dir": "Symfony/Component/Yaml",
@@ -1368,7 +904,7 @@
"minimum-stability": "stable",
"stability-flags": [],
"platform": {
- "php": ">=5.6.1"
+ "php": ">=5.3.0"
},
"platform-dev": []
}
diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php
index 754a6fc..db06b68 100644
--- a/examples/transmission/get_all_transmissions.php
+++ b/examples/transmission/get_all_transmissions.php
@@ -2,11 +2,11 @@
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
$results = Transmission::all();
diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php
index b85d814..574388c 100644
--- a/examples/transmission/get_transmission.php
+++ b/examples/transmission/get_transmission.php
@@ -1,11 +1,11 @@
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
$results = Transmission::find('Your Transmission Id');
diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php
index 1927382..b97bbb9 100644
--- a/examples/transmission/rfc822.php
+++ b/examples/transmission/rfc822.php
@@ -1,23 +1,23 @@
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
- $results = Transmission::send([
- 'recipients'=>[
- [
- 'address'=>[
+ $results = Transmission::send(array(
+ 'recipients'=>array(
+ array(
+ 'address'=>array(
'email'=>'john.doe@sample.com'
- ]
- ]
- ],
- 'rfc822Part'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"
- ]);
+ )
+ )
+ ),
+ 'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"
+ ));
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php
index 6064e67..30f7793 100644
--- a/examples/transmission/send_transmission_all_fields.php
+++ b/examples/transmission/send_transmission_all_fields.php
@@ -1,41 +1,41 @@
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try{
- $results = Transmission::send([
+ $results = Transmission::send(array(
"campaign"=>"my-campaign",
- "metadata"=>[
+ "metadata"=>array(
"sample_campaign"=>true,
"type"=>"these are custom fields"
- ],
- "substitutionData"=>[
+ ),
+ "substitutionData"=>array(
"name"=>"Test Name"
- ],
+ ),
"description"=>"my description",
"replyTo"=>"reply@test.com",
- "headers"=>[
+ "customHeaders"=>array(
"X-Custom-Header"=>"Sample Custom Header"
- ],
- "openTracking"=>false,
- "clickTracking"=>false,
+ ),
+ "trackOpens"=>false,
+ "trackClicks"=>false,
"from"=>"From Envelope <from@example.com>",
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
"text"=>"Hello World!",
"subject"=>"Example Email: {{name}}",
- "recipients"=>[
- [
- "address"=>[
+ "recipients"=>array(
+ array(
+ "address"=>array(
"email"=>"john.doe@sample.com"
- ]
- ]
- ]
- ]);
+ )
+ )
+ )
+ ));
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
diff --git a/examples/transmission/configuration_based.php b/examples/transmission/simple_send.php
index 157d3f3..8149238 100644
--- a/examples/transmission/configuration_based.php
+++ b/examples/transmission/simple_send.php
@@ -2,27 +2,26 @@
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
- $results = Transmission::send([
- "returnPath"=>"return@example.com",
+ $results = Transmission::send(array(
"from"=>"From Envelope <from@example.com>",
"html"=>"<p>Hello World!</p>",
"text"=>"Hello World!",
"subject"=>"Example Email",
- "recipients"=>[
- [
- "address"=>[
+ "recipients"=>array(
+ array(
+ "address"=>array(
"email"=>"john.doe@example.com"
- ]
- ]
- ]
- ]);
+ )
+ )
+ )
+ ));
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php
index f09ca63..dbb7c1d 100644
--- a/examples/transmission/stored_recipients_inline_content.php
+++ b/examples/transmission/stored_recipients_inline_content.php
@@ -1,22 +1,22 @@
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
- $results = Transmission::send([
+ $results = Transmission::send(array(
"campaign"=>"my-campaign",
"from"=>"From Envelope <from@example.com>",
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
"text"=>"Hello World!",
"subject"=>"Example Email: {{name}}",
"recipientList"=>'Example List'
- ]);
+ ));
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php
index 298ba69..cda6de6 100644
--- a/examples/transmission/stored_template_send.php
+++ b/examples/transmission/stored_template_send.php
@@ -1,24 +1,24 @@
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
-use MessageSystems\SparkPost;
-use MessageSystems\Transmission;
+use SparkPost\SparkPost;
+use SparkPost\Transmission;
$key = 'YOURAPIKEY';
-SparkPost::setConfig(['key'=>$key]);
+SparkPost::setConfig(array('key'=>$key));
try {
- $results = Transmission::send([
+ $results = Transmission::send(array(
"from"=>"From Envelope <from@example.com>",
- "recipients"=>[
- [
- "address"=>[
+ "recipients"=>array(
+ array(
+ "address"=>array(
"email"=>"john.doe@sample.com"
- ]
- ]
- ],
+ )
+ )
+ ),
"template"=>"my-template"
- ]);
+ ));
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
diff --git a/lib/SendGridCompatibility/Email.php b/lib/SendGridCompatibility/Email.php
new file mode 100644
index 0000000..5351324
--- /dev/null
+++ b/lib/SendGridCompatibility/Email.php
@@ -0,0 +1,199 @@
+<?php
+namespace SparkPost\SendGridCompatibility;
+
+class Email {
+ public $model;
+
+
+ /**
+ * @desc Sets up the model for saving the configuration
+ */
+ public function __construct() {
+ $this->model = array();
+ }
+
+ /**
+ * @desc adds addresses as recipients
+ * @param string $address
+ * @param string $name optional
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function addTo($address, $name = null) {
+ if (!isset($this->model['recipients'])) {
+ $this->model['recipients'] = array();
+ }
+
+ if(isset($name)) {
+ $address = array('address'=>array('email'=>$address, 'name'=>$name));
+ } else {
+ $address = array('address'=>array('email'=>$address));
+ }
+
+ array_push($this->model['recipients'], $address);
+ return $this;
+ }
+
+ /**
+ * @desc explicitly sets a list of addresses
+ * @param array $addresses
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function setTos(array $addresses) {
+ $this->model['recipients'] = $addresses;
+ return $this;
+ }
+
+ /**
+ * @desc sets the from address
+ * @param string $address
+ * @return \MessageSystems\SendGridCompatibility\Email
+ */
+ public function setFrom($address) {
+ $this->model['from'] = array('email' => $address);
+ return $this;
+ }
+
+ /**
+ * @desc sets the name for the from address
+ * @param string $name
+ */
+ public function setFromName($name) {
+ if(!isset($this->model['from'])){
+ throw new \Exception('Must set "From" prior to setting "From Name".');
+ }
+ $this->model['from']['name'] = $name;
+ return $this;
+ }
+
+ /**
+ * @desc sets the reply to field
+ * @param string $address
+ * @return \MessageSystems\SendGridCompatibility\Email
+ */
+ public function setReplyTo ($address) {
+ $this->model['replyTo'] = $address;
+ return $this;
+ }
+
+ /**
+ * @desc throws an error because bcc fields are not yet implemented.
+ * @throws \Exception
+ * @param string $address
+ * @return \MessageSystems\SendGridCompatibility\Email
+ */
+ public function addBcc($address) {
+ throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a "to" address');
+ }
+
+ /**
+ * @desc sets the subject header
+ * @param string $subject
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function setSubject($subject) {
+ $this->model['subject'] = $subject;
+ return $this;
+ }
+
+ /**
+ * @desc sets the text body
+ * @param string $text
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function setText($text) {
+ $this->model['text'] = $text;
+ return $this;
+ }
+
+ /**
+ * @desc sets the html body
+ * @param string $html
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function setHtml($html) {
+ $this->model['html'] = $html;
+ return $this;
+ }
+
+ /**
+ * @desc Throws an exception since adding categories is not yet supported
+ * @throws \Exception
+ * @param string $category
+ * @throws \Exception
+ */
+ public function addCategory($category) {
+ throw new \Exception('Adding categories is not yet supported');
+ }
+
+ /**
+ * @desc Throws an exception since adding attachments is not yet supported
+ * @throws Exception
+ * @param mixed $attachment
+ */
+ public function addAttachment($attachment) {
+ throw new \Exception('Adding attachments is not yet supported');
+ }
+
+ /**
+ * @desc Adds transmission level substitution data
+ * @param string $name
+ * @param mixed $values
+ * @return \SparkPost\SendGridCompatibility\Email
+ */
+ public function addSubstitution($name, $values) {
+ if (!isset($this->model['substitutionData'])) {
+ $this->model['substitutionData'] = array();
+ }
+ $this->model['substitutionData'][$name] = $values;
+
+ return $this;
+ }
+
+ /**
+ * @desc Adds transmission level substitution data
+ * @param string $name
+ * @param mixed $values
+ */
+ public function addSection($name, $values) {
+ $this->addSubstitution($name, $values);
+ }
+
+ /**
+ * @desc Throws an exception because arguments for third party systems is not supported
+ * @throws Exception
+ * @param mixed $value
+ */
+ public function addUniqueArg($key, $value) {
+ throw new \Exception('Adding Unique Arguments is not yet supported');
+ }
+
+ /**
+ * @desc Throws an exception because arguments for third party systems is not supported
+ * @throws Exception
+ * @param mixed $values
+ */
+ public function setUniqueArgs(array $values) {
+ throw new \Exception('Setting Unique Arguments is not yet supported');
+ }
+
+ /**
+ * @desc Adds custom headers to the email header
+ * @param string $name
+ * @param string $value
+ */
+ public function addHeader($name, $value) {
+ if (!isset($this->model['customHeaders'])) {
+ $this->model['customHeaders'] = array();
+ }
+ $this->model['customHeaders'][$name] = $value;
+ }
+
+ /**
+ * @desc converts this object to a configuration for a SparkPost transmission
+ * @return array
+ */
+ public function toSparkPostTransmission() {
+ return $this->model;
+ }
+}
+?> \ No newline at end of file
diff --git a/lib/SendGridCompatibility/SendGrid.php b/lib/SendGridCompatibility/SendGrid.php
new file mode 100644
index 0000000..a85337a
--- /dev/null
+++ b/lib/SendGridCompatibility/SendGrid.php
@@ -0,0 +1,22 @@
+<?php
+namespace SparkPost\SendGridCompatibility;
+
+use SparkPost\Transmission;
+use SparkPost\SendGridCompatibility\Email;
+use SparkPost\Configuration;
+
+class SendGrid{
+ public function __construct($username, $password, $options = null) {
+ //username isn't used in our system
+ $opts = array('key'=>$password);
+ if (!is_null($options)) {
+ $opts = array_merge($opts, $options);
+ }
+ Configuration::setConfig($opts);
+ }
+
+ public function send(Email $email) {
+ Trasmission::send($email->toSparkPostTransmission());
+ }
+}
+?> \ No newline at end of file
diff --git a/lib/MessageSystems/SparkPost.php b/lib/SparkPost/SparkPost.php
index b1ad20a..5c2a554 100644
--- a/lib/MessageSystems/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -1,17 +1,17 @@
<?php
-namespace MessageSystems;
+namespace SparkPost;
class SparkPost {
private static $config;
- private static $defaults = [
+ private static $defaults = array(
'host'=>'api.sparkpost.com',
'protocol'=>'https',
'port'=>443,
'strictSSL'=>true,
'key'=>'',
'version'=>'v1'
- ];
+ );
/**
* Enforce that this object can't be instansiated
@@ -25,7 +25,12 @@ class SparkPost {
*/
public static function setConfig(array $configMap) {
//check for API key because its required
- if (!isset($configMap['key']) || empty(trim($configMap['key']))){
+ if (isset($configMap['key'])){
+ $key = trim($configMap['key']);
+ if(empty($key)){
+ throw new \Exception('You must provide an API key');
+ }
+ } else {
throw new \Exception('You must provide an API key');
}
self::$config = self::$defaults;
diff --git a/lib/MessageSystems/Transmission.php b/lib/SparkPost/Transmission.php
index e820cff..c083825 100644
--- a/lib/MessageSystems/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -1,7 +1,7 @@
<?php
-namespace MessageSystems;
-use GuzzleHttp\Client;
-use GuzzleHttp\Exception\RequestException;
+namespace SparkPost;
+use Guzzle\Http\Client;
+use Guzzle\Http\Exception\ClientErrorResponseException;
/**
* @desc SDK interface for managing transmissions
@@ -17,7 +17,7 @@ class Transmission {
* @desc Mapping for values passed into the send method to the values needed for the Transmission API
* @var array
*/
- private static $parameterMappings = [
+ private static $parameterMappings = array(
'campaign'=>'campaign_id',
'metadata'=>'metadata',
'substitutionData'=>'substitution_data',
@@ -28,33 +28,33 @@ class Transmission {
'from'=>'content.from',
'html'=>'content.html',
'text'=>'content.text',
- 'rfc822Part'=>'content.email_rfc822',
- 'headers'=>'content.headers',
+ 'rfc822'=>'content.email_rfc822',
+ 'customHeaders'=>'content.headers',
'recipients'=>'recipients',
'recipientList'=>'recipients.list_id',
'template'=>'content.template_id',
- 'openTracking'=>'options.open_tracking',
- 'clickTracking'=>'options.click_tracking',
+ 'trackOpens'=>'options.open_tracking',
+ '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
*/
- private static $structure = [
+ private static $structure = array(
'return_path'=>"default@sparkpostmail.com",
- 'content'=>[
+ 'content'=>array(
'html'=>null,
'text'=>null,
'email_rfc822'=>null
- ],
- 'options'=>[
+ ),
+ 'options'=>array(
'open_tracking'=>true,
'click_tracking'=>true
- ],
+ ),
'use_draft_template'=>false
- ];
+ );
/**
* @desc Ensure that this class cannot be instansiated
@@ -113,13 +113,13 @@ class Transmission {
* 'from': string,
* 'html': string,
* 'text': string,
- * 'rfc822Part': string,
- * 'headers': array,
+ * 'rfc822': string,
+ * 'customHeaders': array,
* 'recipients': array,
* 'recipientList': string,
* 'template': string,
- * 'openTracking': boolean,
- * 'clickTracking': boolean,
+ * 'trackOpens': boolean,
+ * 'trackClicks': boolean,
* 'useDraftTemplate': boolean
*
* @return array API repsonse represented as key-value pairs
@@ -136,19 +136,23 @@ class Transmission {
//send the request
try {
- $response = $request->post(self::getBaseUrl($hostConfig), [
- 'json'=>$model,
- "headers"=>['authorization' => $hostConfig['key']],
- "verify"=>$hostConfig['strictSSL']
- ]);
+ $response = $request->post(self::getBaseUrl($hostConfig), array('authorization' => $hostConfig['key']), json_encode($model), array("verify"=>$hostConfig['strictSSL']))->send();
return $response->json();
- } catch (RequestException $exception) {
+ }
+ /*
+ * Handles 4XX responses
+ */
+ catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
- throw new \Exception(json_encode($response->json()['errors']));
- } catch (\Exception $exception) {
+ $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 Transmissions API: '. $exception->getMessage());
}
-
}
/**
@@ -174,19 +178,24 @@ class Transmission {
//make request
try {
- $response = $request->get($url, [
- "headers"=>['authorization' => $hostConfig['key']],
- "verify"=>$hostConfig['strictSSL']
- ]);
+ $response = $request->get($url, array('authorization' => $hostConfig['key']), array("verify"=>$hostConfig['strictSSL']))->send();
return $response->json();
- } catch (RequestException $exception) {
+ }
+ /*
+ * Handles 4XX responses
+ */
+ catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
- if($response->getStatusCode() === '404') {
+ $statusCode = $response->getStatusCode();
+ if($statusCode === 404) {
throw new \Exception("The specified Transmission ID does not exist", 404);
- } else {
- throw new \Exception("Received bad response from Transmission API: ". $response->getStatusCode());
}
- } catch (\Exception $exception) {
+ throw new \Exception("Received bad response from Transmission API: ". $statusCode);
+ }
+ /*
+ * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
+ */
+ catch (\Exception $exception) {
throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage());
}
}
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
new file mode 100644
index 0000000..c60801c
--- /dev/null
+++ b/test/unit/SendGridCompatibiility/EmailTest.php
@@ -0,0 +1,161 @@
+<?php
+use SparkPost\SendGridCompatibility\Email;
+
+class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
+
+ private $email;
+
+ public function setup() {
+ $this->email = new Email();
+ }
+
+ public function testConstruct() {
+ $email = new Email();
+
+ $this->assertInstanceOf('SparkPost\SendGridCompatibility\Email', $email);
+ $this->assertInternalType('array', $email->model);
+ }
+
+ public function testAddTo() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $this->email->addTo($fakeEmail);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail))), $this->email->model['recipients']);
+ }
+
+ public function testAddToWithName() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $fakeName = 'Joe Schmoe';
+ $this->email->addTo($fakeEmail, $fakeName);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail, 'name'=>$fakeName))), $this->email->model['recipients']);
+ }
+
+ public function testSetTos() {
+ $tos = array();
+ array_push($tos, array('address'=>array('email'=>'joe.schmoe@test.com', 'name'=>'Joe Schmoe')));
+ array_push($tos, array('address'=>array('email'=>'jill.schmoe@test.com', 'name'=>'Jill Schmoe')));
+ $this->email->setTos($tos);
+
+ $this->assertEquals($tos, $this->email->model['recipients']);
+ }
+
+ public function testSetFrom() {
+ $this->email->setFrom('test@email.com');
+
+ $this->assertEquals(array('email'=>'test@email.com'), $this->email->model['from']);
+ }
+
+
+ public function testSetFromName() {
+ $this->email->setFrom('test@email.com');
+ $this->email->setFromName('Test Bot');
+
+ $this->assertEquals(array('email'=>'test@email.com', 'name'=>'Test Bot'), $this->email->model['from']);
+ }
+
+ /**
+ * @desc Tests that setting the fromName prior to setting the From field throws an exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Must set "From" prior to setting "From Name".
+ */
+ public function testSetFromNameWithoutAddress() {
+ $this->email->setFromName('Test Bot');
+ }
+
+ public function testSetReplyto() {
+ $this->email->setReplyTo('test@email.com');
+
+ $this->assertEquals('test@email.com', $this->email->model['replyTo']);
+ }
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding bcc recipients is not yet supported, try adding them as a "to" address
+ */
+ public function testAddBcc() {
+ $this->email->addBcc('test@email.com');
+ }
+
+ public function testSetSubject() {
+ $this->email->setSubject('Awesome Subject');
+
+ $this->assertEquals('Awesome Subject', $this->email->model['subject']);
+ }
+
+ public function testSetText() {
+ $value = 'This is some plain/text';
+ $this->email->setText($value);
+
+ $this->assertEquals($value, $this->email->model['text']);
+ }
+
+ public function testSetHtml() {
+ $value = '<html><body><p>This is some html</p></body></html>';
+ $this->email->setHtml($value);
+
+ $this->assertEquals($value, $this->email->model['html']);
+ }
+
+ /**
+ * @desc test that adding a category throws an exception since we don't support tags at transmission level yet
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding categories is not yet supported
+ */
+ public function testAddCategory() {
+ $this->email->addCategory('');
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding attachments is not yet supported
+ */
+ public function testAddAttachment() {
+ $this->email->addAttachment('blah');
+ }
+
+ public function testAddSubstitution() {
+ $this->email->addSubstitution('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ public function testAddSection() {
+ $this->email->addSection('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding Unique Arguments is not yet supported
+ */
+ public function testAddUniqueArguement() {
+ $this->email->addUniqueArg('blah', 'someblah');
+ }
+
+
+ /**
+ * @desc Tests that setting an unique argument throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Setting Unique Arguments is not yet supported
+ */
+ public function testSetUniqueArgs() {
+ $this->email->setUniqueArgs(array('blah', 'andBlah'));
+ }
+
+
+ public function testAddHeader() {
+ $value = 'My Header';
+ $this->email->addHeader('X-header', $value);
+
+ $this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']);
+ }
+
+ public function testToSparkPostTransmission() {
+ $this->assertInternalType('array', $this->email->toSparkPostTransmission());
+ }
+}
+
+?> \ No newline at end of file
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index 1b86a8f..650cb36 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -1,7 +1,7 @@
<?php
namespace SparkPost\Test;
-use MessageSystems\SparkPost;
+use SparkPost\SparkPost;
class SparkPostTest extends \PHPUnit_Framework_TestCase {
@@ -9,7 +9,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
* @desc Ensures that the configuration class is not instantiable.
*/
public function testConstructorCannotBeCalled() {
- $class = new \ReflectionClass('\MessageSystems\SparkPost');
+ $class = new \ReflectionClass('\SparkPost\SparkPost');
$this->assertFalse($class->isInstantiable());
}
@@ -29,7 +29,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage You must provide an API key
*/
public function testSetConfigAPIKeyNotSetException() {
- SparkPost::setConfig(['something'=>'other than an API Key']);
+ SparkPost::setConfig(array('something'=>'other than an API Key'));
}
/**
@@ -38,14 +38,14 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage You must provide an API key
*/
public function testSetConfigAPIKeyEmptyException() {
- SparkPost::setConfig(['key'=>'']);
+ SparkPost::setConfig(array('key'=>''));
}
/**
* @desc Tests overridable values are set while invalid values are ignored
*/
public function testSetConfigMultipleValuesAndGetConfig() {
- SparkPost::setConfig(['key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue']);
+ SparkPost::setConfig(array('key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue'));
$testConfig = SparkPost::getConfig();
$this->assertEquals('lala', $testConfig['key']);
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index ae7d59d..de72f2a 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -1,11 +1,10 @@
<?php
namespace SparkPost\Test;
-use MessageSystems\Transmission;
-use MessageSystems\SparkPost;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Message\Response;
-use GuzzleHttp\Stream\Stream;
+use SparkPost\Transmission;
+use SparkPost\SparkPost;
+use Guzzle\Plugin\Mock\MockPlugin;
+use Guzzle\Http\Message\Response;
class TransmissionTest extends \PHPUnit_Framework_TestCase {
@@ -21,7 +20,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @return ReflectionMethod
*/
private static function getMethod($name) {
- $class = new \ReflectionClass('\MessageSystems\Transmission');
+ $class = new \ReflectionClass('\SparkPost\Transmission');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
@@ -33,7 +32,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @see PHPUnit_Framework_TestCase::setUp()
*/
public function setUp() {
- SparkPost::setConfig(['key'=>'blah']);
+ SparkPost::setConfig(array('key'=>'blah'));
$this->client = self::getMethod('getHttpClient')->invoke(null); //so we can bootstrap api responses
}
@@ -41,7 +40,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc Ensures that the configuration class is not instantiable.
*/
public function testConstructorCannotBeCalled() {
- $class = new \ReflectionClass('\MessageSystems\Transmission');
+ $class = new \ReflectionClass('\SparkPost\Transmission');
$this->assertFalse($class->isInstantiable());
}
@@ -49,77 +48,96 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests happy path
*/
public function testAllWithGoodResponse() {
- $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))]);
- $this->client->getEmitter()->attach($mock);
- $this->assertEquals(["results"=>[['test'=>'This is a test'], ['test'=>'two']]], Transmission::all());
- $this->client->getEmitter()->detach($mock);
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), '{"results":[{"test":"This is a test"}, {"test":"two"}]}'));
+ $this->client->addSubscriber($mock);
+ $this->assertEquals(array("results"=>array(array('test'=>'This is a test'), array('test'=>'two'))), Transmission::all());
}
/**
* @desc tests happy path
*/
public function testFindWithGoodResponse() {
- $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}]}'))]);
- $this->client->getEmitter()->attach($mock);
- $this->assertEquals(["results"=>[['test'=>'This is a test']]], Transmission::find('someId'));
- $this->client->getEmitter()->detach($mock);
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), '{"results":[{"test":"This is a test"}]}'));
+ $this->client->addSubscriber($mock);
+
+ $this->assertEquals(array("results"=>array(array('test'=>'This is a test'))), Transmission::find('someId'));
}
/**
* @desc tests 404 bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage The specified Transmission ID does not exist
*/
public function testFindWith404Response() {
- $mock = new Mock([new Response(404, [])]);
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::find('someId');
- } catch (\Exception $e) {
- $this->assertEquals('The specified Transmission ID does not exist', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(404, array()));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
}
/**
* @desc tests unknown bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage Received bad response from Transmission API: 400
*/
public function testFindWithOtherBadResponse() {
- $mock = new Mock([new Response(400, [])]);
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::find('someId');
- } catch (\Exception $e) {
- $this->assertEquals('Received bad response from Transmission API: 400', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(400, array()));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
+ }
+
+ /**
+ * @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* /
+ */
+ public function testFindForCatchAllException() {
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(500));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
}
/**
* @desc tests happy path
*/
public function testSuccessfulSend() {
- $body = ["result"=>["transmission_id"=> "11668787484950529"], "status"=>["message"=> "ok","code"=> "1000"]];
- $mock = new Mock([new Response(200, [], Stream::factory(json_encode($body)))]);
- $this->client->getEmitter()->attach($mock);
- $this->assertEquals($body, Transmission::send(['text'=>'awesome email']));
- $this->client->getEmitter()->detach($mock);
+ $body = array("result"=>array("transmission_id"=>"11668787484950529"), "status"=>array("message"=> "ok","code"=> "1000"));
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), json_encode($body)));
+ $this->client->addSubscriber($mock);
+
+
+ $this->assertEquals($body, Transmission::send(array('text'=>'awesome email')));
}
/**
* @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage ["This is a fake error"]
*/
- public function testSendForRequestException() {
- $body = ['errors'=>['This is a fake error']];
- $mock = new Mock([new Response(400, [], Stream::factory(json_encode($body)))]);
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::send(['text'=>'awesome email']);
- } catch (\Exception $e) {
- $this->assertEquals('["This is a fake error"]', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ public function testSendFor400Exception() {
+ $body = array('errors'=>array('This is a fake error'));
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(400, array(), json_encode($body)));
+ $this->client->addSubscriber($mock);
+ Transmission::send(array('text'=>'awesome email'));
+ }
+
+
+ /**
+ * @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* /
+ */
+ public function testSendForCatchAllException() {
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(500));
+ $this->client->addSubscriber($mock);
+ Transmission::send(array('text'=>'awesome email'));
}
}