diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | README.md | 82 | ||||
-rw-r--r-- | RoboFile.php | 17 | ||||
-rw-r--r-- | composer.json | 25 | ||||
-rw-r--r-- | composer.lock | 1374 | ||||
-rw-r--r-- | examples/bootstrap.php | 3 | ||||
-rw-r--r-- | examples/transmission/configuration_based.php | 30 | ||||
-rw-r--r-- | examples/transmission/get_all_transmissions.php | 17 | ||||
-rw-r--r-- | examples/transmission/get_transmission.php | 16 | ||||
-rw-r--r-- | examples/transmission/rfc822.php | 25 | ||||
-rw-r--r-- | examples/transmission/send_transmission_all_fields.php | 43 | ||||
-rw-r--r-- | examples/transmission/stored_recipients_inline_content.php | 25 | ||||
-rw-r--r-- | examples/transmission/stored_template_send.php | 26 | ||||
-rw-r--r-- | lib/MessageSystems/SparkPost.php | 51 | ||||
-rw-r--r-- | lib/MessageSystems/Transmission.php | 216 | ||||
-rw-r--r-- | test/unit/SparkPostTest.php | 60 | ||||
-rw-r--r-- | test/unit/TransmissionTest.php | 126 | ||||
-rw-r--r-- | test/unit/bootstrap.php | 3 |
18 files changed, 2142 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd6b314 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor/ +.project +.settings +.buildpath +test/output/ @@ -1,2 +1,80 @@ -php-sdk -======= +# SparkPost PHP SDK +The official PHP binding for your favorite SparkPost APIs! + +Before using this library, you must have a valid API Key. + +To get an API Key, please log in to your SparkPost account and generate one in the Settings page. + +## Installation +The recommended way to install the SparkPost PHP SDK is through composer. +``` +# Install Composer +curl -sS https://getcomposer.org/installer | php +``` +Next, run the Composer command to install the SparkPost PHP SDK: +``` +composer require messagesystems/php-sdk +``` +After installing, you need to require Composer's autoloader: +``` +require 'vendor/autoload.php'; +``` + +## Getting Started: Your First Mailing +``` +SparkPost::setConfig(["key"=>"YOUR API KEY"]); + +try { + // Build your email and send it! + Transmission::send(['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' ]]] + ]); + + echo 'Woohoo! You just sent your first mailing!'; +} catch (Exception $err) { + echo 'Whoops! Something went wrong'; + var_dump($err); +} +``` + +## Learn More +* For more detailed examples, check our examples: + * [Transmissions](https://github.com/MessageSystems/php-sdk/tree/master/examples/transmission/) +* Read our REST API documentation - <http://www.sparkpost.com/docs/introduction> + +## Tips and Tricks +### General +* You _must_ provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]` +* The SDK's features are namespaced under the various SparkPost API names. + +### Transmissions +* If you specify a stored recipient list and inline recipients in a Transmission, you will recieve an error. +* If you specify HTML and/or Plain Text content and then provide RFC-822 encoded content, you will receive an error. + * RFC-822 content is not valid with any other content type. +* If you specify a stored template and also provide inline content via `html` or `text`, you will receive an error. +* By default, open and click tracking are enabled for a transmission. +* By default, a transmission will use the published version of a stored template. + +## 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. + +### Testing +Once all the dependencies are installed, you can execute the unit tests using `vendor\bin\robo test` + +### Contributing +Guidelines for adding issues + +Submitting pull requests + +Signing our CLA + +Our coding standards
\ No newline at end of file diff --git a/RoboFile.php b/RoboFile.php new file mode 100644 index 0000000..9245e1b --- /dev/null +++ b/RoboFile.php @@ -0,0 +1,17 @@ +<?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 new file mode 100644 index 0000000..5bfd63a --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "messagesystems/php-sdk", + "description": "SDK for interfacing with messagesystems APIs", + "license": "Apache", + "authors": [ + { + "name": "Message Systems", + "email": "info@messagesystems.com" + } + ], + "minimum-stability": "stable", + "require": { + "php": ">=5.6.1", + "guzzlehttp/guzzle": "5.0.1" + }, + "require-dev": { + "phpunit/phpunit": "4.3.*", + "codegyre/robo": "0.4.6" + }, + "autoload": { + "psr-4": { + "MessageSystems\\": "lib/MessageSystems/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..a2c948d --- /dev/null +++ b/composer.lock @@ -0,0 +1,1374 @@ +{ + "_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" + ], + "hash": "25bb67c57c5a357f0cc9873a717dfd51", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9e806208d9b418a58ec86c49078aa94385e64bbd", + "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd", + "shasum": "" + }, + "require": { + "guzzlehttp/ringphp": "~1.0", + "php": ">=5.4.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-ring": "5.0-dev" + } + }, + "autoload": { + "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 and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2014-10-16 18:00:41" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "86df4c0ea5459b292ff8c519f8db1513ea41ca9b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/86df4c0ea5459b292ff8c519f8db1513ea41ca9b", + "reference": "86df4c0ea5459b292ff8c519f8db1513ea41ca9b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.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" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple 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/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@googlemail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "time": "2014-10-15 20:05:57" + } + ], + "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": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "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": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4.1" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2014-08-31 06:33:04" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2014-08-31 06:12:13" + }, + { + "name": "phpunit/phpunit", + "version": "4.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/23e4e0310f037aae873cc81b8658dbbb82878f71", + "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.2", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.0", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2014-10-22 11:43:12" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "c63d2367247365f688544f0d500af90a11a44c65" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", + "reference": "c63d2367247365f688544f0d500af90a11a44c65", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.1", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2014-10-03 05:12:11" + }, + { + "name": "sebastian/comparator", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.1", + "sebastian/exporter": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "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": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2014-05-11 23:00:21" + }, + { + "name": "sebastian/diff", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2014-08-15 10:29:00" + }, + { + "name": "sebastian/environment", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2014-10-22 06:38:05" + }, + { + "name": "sebastian/exporter", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "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": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2014-09-10 00:51:36" + }, + { + "name": "sebastian/version", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "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" + }, + { + "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", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726", + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "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 Yaml Component", + "homepage": "http://symfony.com", + "time": "2014-10-01 05:50:18" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "platform": { + "php": ">=5.6.1" + }, + "platform-dev": [] +} diff --git a/examples/bootstrap.php b/examples/bootstrap.php new file mode 100644 index 0000000..8a5f839 --- /dev/null +++ b/examples/bootstrap.php @@ -0,0 +1,3 @@ +<?php + require_once dirname(__FILE__).'/../vendor/autoload.php'; +?>
\ No newline at end of file diff --git a/examples/transmission/configuration_based.php b/examples/transmission/configuration_based.php new file mode 100644 index 0000000..157d3f3 --- /dev/null +++ b/examples/transmission/configuration_based.php @@ -0,0 +1,30 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); + +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::send([ + "returnPath"=>"return@example.com", + "from"=>"From Envelope <from@example.com>", + "html"=>"<p>Hello World!</p>", + "text"=>"Hello World!", + "subject"=>"Example Email", + "recipients"=>[ + [ + "address"=>[ + "email"=>"john.doe@example.com" + ] + ] + ] + ]); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php new file mode 100644 index 0000000..754a6fc --- /dev/null +++ b/examples/transmission/get_all_transmissions.php @@ -0,0 +1,17 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); + +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::all(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php new file mode 100644 index 0000000..b85d814 --- /dev/null +++ b/examples/transmission/get_transmission.php @@ -0,0 +1,16 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::find('Your Transmission Id'); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php new file mode 100644 index 0000000..1927382 --- /dev/null +++ b/examples/transmission/rfc822.php @@ -0,0 +1,25 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::send([ + 'recipients'=>[ + [ + 'address'=>[ + 'email'=>'john.doe@sample.com' + ] + ] + ], + 'rfc822Part'=>"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(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php new file mode 100644 index 0000000..6064e67 --- /dev/null +++ b/examples/transmission/send_transmission_all_fields.php @@ -0,0 +1,43 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try{ + $results = Transmission::send([ + "campaign"=>"my-campaign", + "metadata"=>[ + "sample_campaign"=>true, + "type"=>"these are custom fields" + ], + "substitutionData"=>[ + "name"=>"Test Name" + ], + "description"=>"my description", + "replyTo"=>"reply@test.com", + "headers"=>[ + "X-Custom-Header"=>"Sample Custom Header" + ], + "openTracking"=>false, + "clickTracking"=>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"=>[ + "email"=>"john.doe@sample.com" + ] + ] + ] + ]); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php new file mode 100644 index 0000000..f09ca63 --- /dev/null +++ b/examples/transmission/stored_recipients_inline_content.php @@ -0,0 +1,25 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + + $results = Transmission::send([ + "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) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php new file mode 100644 index 0000000..298ba69 --- /dev/null +++ b/examples/transmission/stored_template_send.php @@ -0,0 +1,26 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::send([ + "from"=>"From Envelope <from@example.com>", + "recipients"=>[ + [ + "address"=>[ + "email"=>"john.doe@sample.com" + ] + ] + ], + "template"=>"my-template" + ]); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/lib/MessageSystems/SparkPost.php b/lib/MessageSystems/SparkPost.php new file mode 100644 index 0000000..b1ad20a --- /dev/null +++ b/lib/MessageSystems/SparkPost.php @@ -0,0 +1,51 @@ +<?php +namespace MessageSystems; + +class SparkPost { + + private static $config; + private static $defaults = [ + 'host'=>'api.sparkpost.com', + 'protocol'=>'https', + 'port'=>443, + 'strictSSL'=>true, + 'key'=>'', + '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 + if (!isset($configMap['key']) || empty(trim($configMap['key']))){ + throw new \Exception('You must provide an API key'); + } + self::$config = self::$defaults; + foreach ($configMap as $configOption => $configValue) { + if(key_exists($configOption, self::$config)) { + self::$config[$configOption] = $configValue; + } + } + } + + /** + * Retrieves the configuration that was previously setup by the user + * @throws \Exception + */ + public static function getConfig() { + if (self::$config === null) { + throw new \Exception('No configuration has been provided'); + } + return self::$config; + } +} + +?>
\ No newline at end of file diff --git a/lib/MessageSystems/Transmission.php b/lib/MessageSystems/Transmission.php new file mode 100644 index 0000000..e820cff --- /dev/null +++ b/lib/MessageSystems/Transmission.php @@ -0,0 +1,216 @@ +<?php +namespace MessageSystems; +use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; + +/** + * @desc SDK interface for managing transmissions + */ +class Transmission { + /** + * @desc singleton holder to create a guzzle http client + * @var \GuzzleHttp\Client + */ + private static $request; + + /** + * @desc Mapping for values passed into the send method to the values needed for the Transmission API + * @var array + */ + private static $parameterMappings = [ + 'campaign'=>'campaign_id', + 'metadata'=>'metadata', + 'substitutionData'=>'substitution_data', + 'description'=>'description', + 'returnPath'=>'return_path', + 'replyTo'=>'content.reply_to', + 'subject'=>'content.subject', + 'from'=>'content.from', + 'html'=>'content.html', + 'text'=>'content.text', + 'rfc822Part'=>'content.email_rfc822', + 'headers'=>'content.headers', + 'recipients'=>'recipients', + 'recipientList'=>'recipients.list_id', + 'template'=>'content.template_id', + 'openTracking'=>'options.open_tracking', + 'clickTracking'=>'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 = [ + 'return_path'=>"default@sparkpostmail.com", + 'content'=>[ + 'html'=>null, + 'text'=>null, + 'email_rfc822'=>null + ], + 'options'=>[ + 'open_tracking'=>true, + 'click_tracking'=>true + ], + 'use_draft_template'=>false + ]; + + /** + * @desc Ensure that this class cannot be instansiated + */ + private function __construct() {} + + /** + * @desc Creates and returns a guzzle http client. + * @return \GuzzleHttp\Client + */ + private static function getHttpClient() { + if(!isset(self::$request)) { + self::$request = new Client(); + } + return self::$request; + } + + + /** + * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter + */ + private static function setMappedValue (&$model, $mapKey, $value) { + //get mapping + if(array_key_exists($mapKey, self::$parameterMappings)) { + $temp = &$model; + $path = explode('.', self::$parameterMappings[$mapKey]); + foreach( $path as $key ) { + $temp = &$temp[$key]; + } + $temp = $value; + } //ignore anything we don't have a mapping for + } + + /** + * @desc Private Method helper to get the configuration values to create the base url for the transmissions API + * + * @return string base url for the transmissions API + */ + private static function getBaseUrl($config) { + $baseUrl = '/api/' . $config['version'] . '/transmissions'; + return $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . $baseUrl; + } + + /** + * @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, + * 'metadata': array, + * 'substitutionData': array, + * 'description': string, + * 'replyTo': string, + * 'subject': string, + * 'from': string, + * 'html': string, + * 'text': string, + * 'rfc822Part': string, + * 'headers': array, + * 'recipients': array, + * 'recipientList': string, + * 'template': string, + * 'openTracking': boolean, + * 'clickTracking': boolean, + * 'useDraftTemplate': boolean + * + * @return array API repsonse represented as key-value pairs + */ + public static function send($transmissionConfig) { + $hostConfig = SparkPost::getConfig(); + $request = self::getHttpClient(); + + //create model from $transmissionConfig + $model = self::$structure; + foreach($transmissionConfig as $key=>$value) { + self::setMappedValue($model, $key, $value); + } + + //send the request + try { + $response = $request->post(self::getBaseUrl($hostConfig), [ + 'json'=>$model, + "headers"=>['authorization' => $hostConfig['key']], + "verify"=>$hostConfig['strictSSL'] + ]); + return $response->json(); + } catch (RequestException $exception) { + $response = $exception->getResponse(); + throw new \Exception(json_encode($response->json()['errors'])); + } catch (\Exception $exception) { + throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage()); + } + + } + + /** + * @desc Private Method for issuing GET request to Transmissions API + * + * This method is responsible for getting the collection _and_ + * a specific entity from the Transmissions API + * + * If TransmissionID parameter is omitted, then we fetch the collection + * + * @param string $transmissionID (optional) string Transmission ID of specific Transmission to retrieve + * @return array Result set of transmissions found + */ + private static function fetch ($transmissionID = null) { + //figure out the url + $hostConfig = SparkPost::getConfig(); + $url = self::getBaseUrl($hostConfig); + if (!is_null($transmissionID)){ + $url .= '/'.$transmissionID; + } + + $request = self::getHttpClient(); + + //make request + try { + $response = $request->get($url, [ + "headers"=>['authorization' => $hostConfig['key']], + "verify"=>$hostConfig['strictSSL'] + ]); + return $response->json(); + } catch (RequestException $exception) { + $response = $exception->getResponse(); + if($response->getStatusCode() === '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('Unable to contact Transmissions API: '. $exception->getMessage()); + } + } + + /** + * @desc Method for retrieving information about all transmissions + * Wrapper method for a cleaner interface + * + * @return array result Set of transmissions + */ + public static function all() { + return self::fetch(); + } + + /** + * @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::fetch($transmissionID); + } +} + +?>
\ No newline at end of file diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php new file mode 100644 index 0000000..1b86a8f --- /dev/null +++ b/test/unit/SparkPostTest.php @@ -0,0 +1,60 @@ +<?php +namespace SparkPost\Test; + +use MessageSystems\SparkPost; + +class SparkPostTest extends \PHPUnit_Framework_TestCase { + + /** + * @desc Ensures that the configuration class is not instantiable. + */ + public function testConstructorCannotBeCalled() { + $class = new \ReflectionClass('\MessageSystems\SparkPost'); + $this->assertFalse($class->isInstantiable()); + } + + /** + * @desc Tests that an exception is thrown when a library tries to recieve the config and it has not yet been set. + * Since its a singleton this test must come before any setConfig tests. + * @expectedException Exception + * @expectedExceptionMessage No configuration has been provided + */ + public function testGetConfigEmptyException() { + SparkPost::getConfig(); + } + + /** + * @desc Tests that the api key is set when setting the config + * @expectedException Exception + * @expectedExceptionMessage You must provide an API key + */ + public function testSetConfigAPIKeyNotSetException() { + SparkPost::setConfig(['something'=>'other than an API Key']); + } + + /** + * @desc Tests that the api key is set when setting the config and that its not empty + * @expectedException Exception + * @expectedExceptionMessage You must provide an API key + */ + public function testSetConfigAPIKeyEmptyException() { + SparkPost::setConfig(['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']); + + $testConfig = SparkPost::getConfig(); + $this->assertEquals('lala', $testConfig['key']); + $this->assertEquals('v8', $testConfig['version']); + $this->assertEquals(1024, $testConfig['port']); + $this->assertNotContains('someOtherValue', array_keys($testConfig)); + $this->assertEquals('https', $testConfig['protocol']); + $this->assertEquals('api.sparkpost.com', $testConfig['host']); + $this->assertEquals(true, $testConfig['strictSSL']); + } +} +?>
\ No newline at end of file diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php new file mode 100644 index 0000000..ae7d59d --- /dev/null +++ b/test/unit/TransmissionTest.php @@ -0,0 +1,126 @@ +<?php +namespace SparkPost\Test; + +use MessageSystems\Transmission; +use MessageSystems\SparkPost; +use GuzzleHttp\Subscriber\Mock; +use GuzzleHttp\Message\Response; +use GuzzleHttp\Stream\Stream; + + +class TransmissionTest extends \PHPUnit_Framework_TestCase { + + private $client = null; + + /** + * Allows access to private methods in the Transmission class + * + * This is needed to mock the GuzzleHttp\Client responses + * + * @param string $name + * @return ReflectionMethod + */ + private static function getMethod($name) { + $class = new \ReflectionClass('\MessageSystems\Transmission'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; + } + + /** + * (non-PHPdoc) + * @before + * @see PHPUnit_Framework_TestCase::setUp() + */ + public function setUp() { + SparkPost::setConfig(['key'=>'blah']); + $this->client = self::getMethod('getHttpClient')->invoke(null); //so we can bootstrap api responses + } + + /** + * @desc Ensures that the configuration class is not instantiable. + */ + public function testConstructorCannotBeCalled() { + $class = new \ReflectionClass('\MessageSystems\Transmission'); + $this->assertFalse($class->isInstantiable()); + } + + /** + * @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); + } + + /** + * @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); + } + + /** + * @desc tests 404 bad response + */ + 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); + } + } + + /** + * @desc tests unknown bad response + */ + 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); + } + } + + /** + * @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); + } + + /** + * @desc tests bad response + */ + 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); + } + } + +} +?>
\ No newline at end of file diff --git a/test/unit/bootstrap.php b/test/unit/bootstrap.php new file mode 100644 index 0000000..7e73606 --- /dev/null +++ b/test/unit/bootstrap.php @@ -0,0 +1,3 @@ +<?php + require_once dirname(__FILE__).'/../../vendor/autoload.php'; +?>
\ No newline at end of file |