diff options
author | beardyman <nornholdj@gmail.com> | 2015-09-23 13:42:28 -0400 |
---|---|---|
committer | beardyman <nornholdj@gmail.com> | 2015-09-23 13:42:28 -0400 |
commit | 81b60fa71e53ce0c1cca28a6311f13903de3ba76 (patch) | |
tree | bce8bdab33a4750daa5770bf1cf2de4eeefe9126 | |
parent | 271d2b486af305ef49830b16748edce84341a3c0 (diff) | |
download | php-sparkpost-81b60fa71e53ce0c1cca28a6311f13903de3ba76.zip php-sparkpost-81b60fa71e53ce0c1cca28a6311f13903de3ba76.tar.gz php-sparkpost-81b60fa71e53ce0c1cca28a6311f13903de3ba76.tar.bz2 |
updated examples (removed uneeded use statement) and updated documentation for using HTTP Adapters.
-rw-r--r-- | README.md | 61 | ||||
-rw-r--r-- | examples/transmission/get_all_transmissions.php | 1 | ||||
-rw-r--r-- | examples/transmission/get_transmission.php | 1 | ||||
-rw-r--r-- | examples/transmission/rfc822.php | 1 | ||||
-rw-r--r-- | examples/transmission/send_transmission_all_fields.php | 1 | ||||
-rw-r--r-- | examples/transmission/simple_send.php | 1 | ||||
-rw-r--r-- | examples/transmission/stored_recipients_inline_content.php | 1 | ||||
-rw-r--r-- | examples/transmission/stored_template_send.php | 1 |
8 files changed, 44 insertions, 24 deletions
@@ -13,7 +13,7 @@ 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: +Next, run the Composer command to install the SparkPost PHP SDK: ``` composer require sparkpost/php-sparkpost ``` @@ -22,25 +22,53 @@ After installing, you need to require Composer's autoloader: require 'vendor/autoload.php'; ``` +## Setting up a Request Adapter +Because of dependency collision, we have opted to use a request adapter rather than +requiring a request library. This means that your application will need to pass in +a request adapter to the constructor of the SparkPost Library. We use the [Ivory HTTP Adapter] (https://github.com/egeloen/ivory-http-adapter) in SparkPost. Please visit their repo +for a list of supported adapters. If you don't currently use a request library, you will +need to require one and create an adapter from it and pass it along. The example below uses the +GuzzleHttp Client Library. + +An Adapter can be setup like so: +``` +use SparkPost\SparkPost; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; + +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']); +``` + ## Getting Started: Your First Mailing ``` -SparkPost::setConfig(["key"=>"YOUR API KEY"]); +use SparkPost\SparkPost; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; + +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']); try { - // Build your email and send it! - 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'=>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) { - echo 'Whoops! Something went wrong'; - var_dump($err); + $results = $sparky->transmission->send([ + 'from'=>'From Envelope <from@sparkpostbox.com>', + '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'=>array('name'=>'YOUR FIRST NAME') + 'subject'=>'First Mailing From PHP', + '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); } ``` @@ -101,4 +129,3 @@ If you're interested in code coverage, you can add the `--coverage` flag for php 2. Fork [the repository](http://github.com/SparkPost/php-sparkpost) on GitHub to start making your changes to the **master** branch (or branch off of it). 3. Write a test which shows that the bug was fixed or that the feature works as expected. 4. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to [AUTHORS](https://github.com/SparkPost/php-sparkpost/blob/master/AUTHORS.md). - diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php index 669c3e7..bc57466 100644 --- a/examples/transmission/get_all_transmissions.php +++ b/examples/transmission/get_all_transmissions.php @@ -3,7 +3,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php index 5882a49..9303eca 100644 --- a/examples/transmission/get_transmission.php +++ b/examples/transmission/get_transmission.php @@ -3,7 +3,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php index cb88471..2b10423 100644 --- a/examples/transmission/rfc822.php +++ b/examples/transmission/rfc822.php @@ -2,7 +2,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php index be82b97..5a6cf7f 100644 --- a/examples/transmission/send_transmission_all_fields.php +++ b/examples/transmission/send_transmission_all_fields.php @@ -2,7 +2,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/simple_send.php b/examples/transmission/simple_send.php index 2edfbf6..34df573 100644 --- a/examples/transmission/simple_send.php +++ b/examples/transmission/simple_send.php @@ -3,7 +3,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php index 853030d..9f3a55d 100644 --- a/examples/transmission/stored_recipients_inline_content.php +++ b/examples/transmission/stored_recipients_inline_content.php @@ -2,7 +2,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php index 3d52f0a..60363ba 100644 --- a/examples/transmission/stored_template_send.php +++ b/examples/transmission/stored_template_send.php @@ -2,7 +2,6 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); use SparkPost\SparkPost; -use SparkPost\Transmission; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; |