Skip to content

Commit 7c39c1e

Browse files
committed
Merge pull request #22 from SparkPost/http-adapter-update
Http adapter update
2 parents c2e4758 + 63022bf commit 7c39c1e

26 files changed

+1817
-1328
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22
php:
33
- '5.5'
4-
- '5.4'
4+
- '5.6'
55
install:
66
- composer install
77
before_script:

AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ php-sparkpost is maintained by Message Systems.
22

33
# Contributors
44

5-
* Jordan Nornhold <jordan.norhold@messagesystems.com>
5+
* Jordan Nornhold <jordan.nornhold@messagesystems.com>, @beardyman
66
* Rich Leland <[email protected]>, @richleland
77
* Matthew April <[email protected]>

README.md

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,67 @@ Next, run the Composer command to install the SparkPost PHP SDK:
1919
composer require sparkpost/php-sparkpost
2020
```
2121
After installing, you need to require Composer's autoloader:
22-
```
22+
```php
2323
require 'vendor/autoload.php';
2424
use SparkPost\SparkPost;
2525
```
2626

27-
## Getting Started: Your First Mailing
27+
## Setting up a Request Adapter
28+
Because of dependency collision, we have opted to use a request adapter rather than
29+
requiring a request library. This means that your application will need to pass in
30+
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
31+
for a list of supported adapters. If you don't currently use a request library, you will
32+
need to require one and create an adapter from it and pass it along. The example below uses the
33+
GuzzleHttp Client Library.
34+
35+
An Adapter can be setup like so:
36+
```php
37+
use SparkPost\SparkPost;
38+
use GuzzleHttp\Client;
39+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
40+
41+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
42+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
2843
```
29-
SparkPost::setConfig(["key"=>"YOUR API KEY"]);
44+
45+
## Getting Started: Your First Mailing
46+
```php
47+
require 'vendor/autoload.php';
48+
49+
use SparkPost\SparkPost;
50+
use GuzzleHttp\Client;
51+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
52+
53+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
54+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
3055

3156
try {
32-
// Build your email and send it!
33-
Transmission::send(array('campaign'=>'first-mailing',
34-
'from'=>'[email protected]',
35-
'subject'=>'First SDK Mailing',
36-
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
37-
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
38-
'substitutionData'=>array('name'=>'YOUR FIRST NAME'),
39-
'recipients'=>array(array('address'=>array('name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' )))
40-
));
41-
42-
echo 'Woohoo! You just sent your first mailing!';
43-
} catch (Exception $err) {
44-
echo 'Whoops! Something went wrong';
45-
var_dump($err);
57+
// Build your email and send it!
58+
$results = $sparky->transmission->send([
59+
'from'=>'From Envelope <from@sparkpostbox.com>',
60+
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
61+
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
62+
'substitutionData'=>['name'=>'YOUR FIRST NAME']
63+
'subject'=>'First Mailing From PHP',
64+
'recipients'=>[
65+
[
66+
'address'=>[
67+
'name'=>'YOUR FULL NAME',
68+
'email'=>'YOUR EMAIL ADDRESS'
69+
]
70+
]
71+
]
72+
]);
73+
echo 'Woohoo! You just sent your first mailing!';
74+
} catch (\Exception $err) {
75+
echo 'Whoops! Something went wrong';
76+
var_dump($err);
4677
}
4778
```
4879

4980
## Learn More
5081
* For more detailed examples, check our examples:
51-
* [Transmissions](https://github.com/SparkPost/php-sparkpost/tree/master/examples/transmission)
82+
* [Transmissions](https://github.com/SparkPost/php-sparkpost/tree/master/examples/transmission)
5283
* Read our REST API documentation - <http://www.sparkpost.com/docs/introduction>
5384

5485
## Field Descriptions

composer.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "sparkpost/php-sparkpost",
33
"description": "SDK for interfacing with SparkPost APIs",
44
"license": "Apache 2.0",
5+
"version": "0.2.0",
56
"authors": [
67
{
78
"name": "Message Systems, Inc."
@@ -14,17 +15,20 @@
1415
"test": "phpunit ./test/unit/"
1516
},
1617
"require": {
17-
"php": ">=5.3.0",
18-
"guzzlehttp/guzzle": "3.8.1"
18+
"php": ">=5.5.0",
19+
"egeloen/http-adapter": "*"
1920
},
2021
"require-dev": {
21-
"phpunit/phpunit": "4.3.*",
22-
"satooshi/php-coveralls": "dev-master"
22+
"phpunit/phpunit": "4.3.*",
23+
"guzzlehttp/guzzle": "6.*",
24+
"mockery/mockery": "^0.9.4",
25+
"satooshi/php-coveralls": "dev-master"
2326
},
2427
"autoload": {
25-
"psr-4": {
26-
"SparkPost\\": "lib/SparkPost/",
27-
"SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/"
28-
}
28+
"psr-4": {
29+
"SparkPost\\": "lib/SparkPost/",
30+
"SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/",
31+
"SparkPost\\Test\\TestUtils\\": "test/unit/TestUtils/"
32+
}
2933
}
3034
}

0 commit comments

Comments
 (0)