Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

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

{
  "require": {
    "sparkpost/php-sparkpost": "~1.0",
    "egeloen/http-adapter": "0.8.0",
    "guzzlehttp/guzzle": "6.1.0",
    "php-http/guzzle6-adapter": "0.1.0"
  }
}

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to keep the require 'vendor/autoload.php'; at the top here just for completeness...

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']
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be 1.0 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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."
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