-
Notifications
You must be signed in to change notification settings - Fork 93
Http adapter update #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c0b9e8b
0c4b276
b51ce2d
efe48cc
271d2b4
81b60fa
04f09ee
a436c49
c753d55
97e0d26
2f1b803
6818faa
1c386dc
55d428c
ada533a
63022bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to keep the |
||
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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still missing trailing comma here |
||
'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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing is actually all over the place, maybe because of tabs and spaces mixed at some point, would be nice to clean up for readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree. That was the issue \t & spaces mixed ... think I'm going to write a script to do this because its all over the place. |
||
``` | ||
|
||
## 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "sparkpost/php-sparkpost", | ||
"description": "SDK for interfacing with SparkPost APIs", | ||
"license": "Apache 2.0", | ||
"version": "0.2.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be 1.0 right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I want to talk to @richleland and @aydrian about that. I personally think it should be just because this breaks everything existing. But since its still a 0.* I'm not sure, we may be ok with that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.* versions have all kinds of problems, the sooner we get to 1.x the better imo, for everything (npm init defaults to 1.0.0 now because of how volatile and weird the semver rules are around 0.x versions) |
||
"authors": [ | ||
{ | ||
"name": "Message Systems, Inc." | ||
|
@@ -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/" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put an example composer.json file here too so people can just grab it if they want to use these deps, ie