Skip to content

Commit 81b60fa

Browse files
committed
updated examples (removed uneeded use statement) and updated documentation for using HTTP Adapters.
1 parent 271d2b4 commit 81b60fa

File tree

8 files changed

+44
-24
lines changed

8 files changed

+44
-24
lines changed

README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The recommended way to install the SparkPost PHP SDK is through composer.
1313
# Install Composer
1414
curl -sS https://getcomposer.org/installer | php
1515
```
16-
Next, run the Composer command to install the SparkPost PHP SDK:
16+
Next, run the Composer command to install the SparkPost PHP SDK:
1717
```
1818
composer require sparkpost/php-sparkpost
1919
```
@@ -22,25 +22,53 @@ After installing, you need to require Composer's autoloader:
2222
require 'vendor/autoload.php';
2323
```
2424

25+
## Setting up a Request Adapter
26+
Because of dependency collision, we have opted to use a request adapter rather than
27+
requiring a request library. This means that your application will need to pass in
28+
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
29+
for a list of supported adapters. If you don't currently use a request library, you will
30+
need to require one and create an adapter from it and pass it along. The example below uses the
31+
GuzzleHttp Client Library.
32+
33+
An Adapter can be setup like so:
34+
```
35+
use SparkPost\SparkPost;
36+
use GuzzleHttp\Client;
37+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
38+
39+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
40+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
41+
```
42+
2543
## Getting Started: Your First Mailing
2644
```
27-
SparkPost::setConfig(["key"=>"YOUR API KEY"]);
45+
use SparkPost\SparkPost;
46+
use GuzzleHttp\Client;
47+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
48+
49+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
50+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
2851
2952
try {
30-
// Build your email and send it!
31-
Transmission::send(array('campaign'=>'first-mailing',
32-
'from'=>'you@your-company.com',
33-
'subject'=>'First SDK Mailing',
34-
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
35-
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
36-
'substitutionData'=>array('name'=>'YOUR FIRST NAME'),
37-
'recipients'=>array(array('address'=>array('name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' )))
38-
));
39-
40-
echo 'Woohoo! You just sent your first mailing!';
41-
} catch (Exception $err) {
42-
echo 'Whoops! Something went wrong';
43-
var_dump($err);
53+
$results = $sparky->transmission->send([
54+
'from'=>'From Envelope <from@sparkpostbox.com>',
55+
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
56+
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
57+
'substitutionData'=>array('name'=>'YOUR FIRST NAME')
58+
'subject'=>'First Mailing From PHP',
59+
'recipients'=>[
60+
[
61+
"address"=>[
62+
'name'=>'YOUR FULL NAME',
63+
'email'=>'YOUR EMAIL ADDRESS'
64+
]
65+
]
66+
]
67+
]);
68+
echo 'Woohoo! You just sent your first mailing!';
69+
} catch (\Exception $err) {
70+
echo 'Whoops! Something went wrong';
71+
var_dump($err);
4472
}
4573
```
4674

@@ -101,4 +129,3 @@ If you're interested in code coverage, you can add the `--coverage` flag for php
101129
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).
102130
3. Write a test which shows that the bug was fixed or that the feature works as expected.
103131
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).
104-

examples/transmission/get_all_transmissions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

55
use SparkPost\SparkPost;
6-
use SparkPost\Transmission;
76
use GuzzleHttp\Client;
87
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
98

examples/transmission/get_transmission.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

55
use SparkPost\SparkPost;
6-
use SparkPost\Transmission;
76
use GuzzleHttp\Client;
87
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
98

examples/transmission/rfc822.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
5-
use SparkPost\Transmission;
65
use GuzzleHttp\Client;
76
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
87

examples/transmission/send_transmission_all_fields.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
5-
use SparkPost\Transmission;
65
use GuzzleHttp\Client;
76
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
87

examples/transmission/simple_send.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

55
use SparkPost\SparkPost;
6-
use SparkPost\Transmission;
76
use GuzzleHttp\Client;
87
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
98

examples/transmission/stored_recipients_inline_content.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
5-
use SparkPost\Transmission;
65
use GuzzleHttp\Client;
76
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
87

examples/transmission/stored_template_send.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
5-
use SparkPost\Transmission;
65
use GuzzleHttp\Client;
76
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
87

0 commit comments

Comments
 (0)