Skip to content

Commit

Permalink
Merge pull request #22 from SparkPost/http-adapter-update
Browse files Browse the repository at this point in the history
Http adapter update
  • Loading branch information
beardyman committed Oct 10, 2015
2 parents c2e4758 + 63022bf commit 7c39c1e
Show file tree
Hide file tree
Showing 26 changed files with 1,817 additions and 1,328 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php
php:
- '5.5'
- '5.4'
- '5.6'
install:
- composer install
before_script:
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ php-sparkpost is maintained by Message Systems.

# Contributors

* Jordan Nornhold <jordan.norhold@messagesystems.com>
* Jordan Nornhold <jordan.nornhold@messagesystems.com>, @beardyman
* Rich Leland <rich.leland@messagesystems.com>, @richleland
* Matthew April <matthew.japril@gmail.com>
67 changes: 49 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,67 @@ Next, run the Composer command to install the SparkPost PHP SDK:
composer require sparkpost/php-sparkpost
```
After installing, you need to require Composer's autoloader:
```
```php
require 'vendor/autoload.php';
use SparkPost\SparkPost;
```

## Getting Started: Your First Mailing
## 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:
```php
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;

$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
```
SparkPost::setConfig(["key"=>"YOUR API KEY"]);

## Getting Started: Your First Mailing
```php
require 'vendor/autoload.php';

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);
// Build your email and send it!
$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'=>['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);
}
```

## Learn More
* For more detailed examples, check our examples:
* [Transmissions](https://github.com/SparkPost/php-sparkpost/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
Expand Down
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "sparkpost/php-sparkpost",
"description": "SDK for interfacing with SparkPost APIs",
"license": "Apache 2.0",
"version": "0.2.0",
"authors": [
{
"name": "Message Systems, Inc."
Expand All @@ -14,17 +15,20 @@
"test": "phpunit ./test/unit/"
},
"require": {
"php": ">=5.3.0",
"guzzlehttp/guzzle": "3.8.1"
"php": ">=5.5.0",
"egeloen/http-adapter": "*"
},
"require-dev": {
"phpunit/phpunit": "4.3.*",
"satooshi/php-coveralls": "dev-master"
"phpunit/phpunit": "4.3.*",
"guzzlehttp/guzzle": "6.*",
"mockery/mockery": "^0.9.4",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-4": {
"SparkPost\\": "lib/SparkPost/",
"SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/"
}
"psr-4": {
"SparkPost\\": "lib/SparkPost/",
"SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/",
"SparkPost\\Test\\TestUtils\\": "test/unit/TestUtils/"
}
}
}
Loading

0 comments on commit 7c39c1e

Please sign in to comment.