Skip to content

Commit efe48cc

Browse files
committed
Removed most static methods and adopted an instance based implementation. Updated all examples and compatibility later to reflect these changes.
1 parent b51ce2d commit efe48cc

File tree

12 files changed

+233
-213
lines changed

12 files changed

+233
-213
lines changed

examples/transmission/get_all_transmissions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
$key = 'YOUR API KEY';
1111
$httpAdapter = new Guzzle6HttpAdapter(new Client());
12-
SparkPost::configure($httpAdapter, ['key'=>$key]);
12+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1313

1414
try {
15-
$results = Transmission::all();
15+
$results = $sparky->transmission->all();
1616
echo 'Congrats you can use your SDK!';
1717
} catch (\Exception $exception) {
1818
echo $exception->getMessage();

examples/transmission/get_transmission.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4+
45
use SparkPost\SparkPost;
56
use SparkPost\Transmission;
67
use GuzzleHttp\Client;
78
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
89

910
$key = 'YOUR API KEY';
1011
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
12-
12+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1313

1414
try {
15-
$results = Transmission::find('Your Transmission ID');
15+
$results = $sparky->transmission->find('Your Transmission ID');
1616
echo 'Congrats you can use your SDK!';
1717
} catch (\Exception $exception) {
1818
echo $exception->getMessage();

examples/transmission/rfc822.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
$key = 'YOUR API KEY';
1010
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
11+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1212

1313
try {
14-
$results = Transmission::send([
14+
$results = $sparky->transmission->send([
1515
'recipients'=>[
1616
[
1717
'address'=>[
1818
'email'=>'john.doe@example.com'
19-
]
19+
]
2020
]
2121
],
2222
'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@sparkpostbox.com>\nSubject: Example Email\n\nHello World"

examples/transmission/send_transmission_all_fields.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
$key = 'YOUR API KEY';
1010
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
11+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1212

1313
// TODO: update all from emails to = sandbox domain
1414

1515
try{
16-
$results = Transmission::send([
16+
$results = $sparky->transmission->send([
1717
"campaign"=>"my-campaign",
1818
"metadata"=>[
1919
"sample_campaign"=>true,
@@ -37,12 +37,11 @@
3737
[
3838
"address"=>[
3939
"email"=>"john.doe@example.com"
40-
]
40+
]
4141
]
4242
]
4343
]);
4444

45-
var_dump($results);
4645
echo 'Congrats you can use your SDK!';
4746
} catch (\Exception $exception) {
4847
echo $exception->getMessage();

examples/transmission/simple_send.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
$key = 'YOUR API KEY';
1111
$httpAdapter = new Guzzle6HttpAdapter(new Client());
12-
SparkPost::configure($httpAdapter, ['key'=>$key]);
12+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1313

1414
try {
15-
$results = Transmission::send([
15+
$results = $sparky->transmission->send([
1616
"from"=>"From Envelope <from@sparkpostbox.com>",
1717
"html"=>"<p>Hello World!</p>",
1818
"text"=>"Hello World!",
@@ -21,7 +21,7 @@
2121
[
2222
"address"=>[
2323
"email"=>"john.doe@example.com"
24-
]
24+
]
2525
]
2626
]
2727
]);

examples/transmission/stored_recipients_inline_content.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
$key = 'YOUR API KEY';
1010
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
11+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1212

1313
try {
1414

15-
$results = Transmission::send([
15+
$results = $sparky->transmission->send([
1616
"campaign"=>"my-campaign",
1717
"from"=>"From Envelope <from@sparkpostbox.com>",
1818
"html"=>"<p>Hello World! Your name is: {{name}}</p>",

examples/transmission/stored_template_send.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
$key = 'YOUR API KEY';
1010
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
11+
$sparky = new SparkPost($httpAdapter, ['key'=>$key]);
1212

1313
try {
14-
$results = Transmission::send([
14+
$results = $sparky->transmission->send([
1515
"from"=>"From Envelope <from@sparkpostbox.com>",
1616
"recipients"=>[
1717
[
1818
"address"=>[
1919
"email"=>"john.doe@example.com"
20-
]
20+
]
2121
]
2222
],
23-
"template"=>"my-template"
23+
"template"=>"my-first-email"
2424
]);
2525
echo 'Congrats you can use your SDK!';
2626
} catch (\Exception $exception) {

examples/unwrapped/create_template.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
<?php
22
namespace Examples\Unwrapped;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
5-
use SparkPost\APIResource;
64
use GuzzleHttp\Client;
75
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
86

97
$key = 'YOUR API KEY';
108
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11-
SparkPost::configure($httpAdapter, ['key'=>$key]);
9+
$resource = new \SparkPost\APIResource($httpAdapter, ['key'=>$key]);
1210

1311
try {
1412
// define the endpoint
15-
APIResource::$endpoint = 'templates';
13+
$resource->endpoint = 'templates';
1614

1715
$templateConfig = [
1816
'name' => 'Summer Sale!',
1917
'id'=>'summer-sale',
2018
'content'=> [
21-
'from' => 'john.doe@sparkpostbox.com',
19+
'from' => 'from@sparkpostbox.com',
2220
'subject' => 'Summer deals',
2321
'html' => '<b>Check out these deals!</b>'
2422
]
2523
];
26-
$results = APIResource::create($templateConfig);
27-
var_dump($results);
24+
$results = $resource->create($templateConfig);
2825
echo 'Congrats you can use your SDK!';
2926
} catch (\Exception $exception) {
3027
echo $exception->getMessage();
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?php
22
namespace SparkPost\SendGridCompatibility;
33

4-
use SparkPost\Transmission;
4+
use SparkPost\SparkPost;
55
use SparkPost\SendGridCompatibility\Email;
6-
use SparkPost\Configuration;
76

87
class SendGrid{
9-
public function __construct($username, $password, $options = null) {
8+
private $sparky;
9+
10+
public function __construct($username, $password, $options = null, $httpAdapter) {
1011
//username isn't used in our system
1112
$opts = array('key'=>$password);
1213
if (!is_null($options)) {
1314
$opts = array_merge($opts, $options);
1415
}
15-
Configuration::setConfig($opts);
16+
17+
$this->sparky = new SparkPost($httpAdapter, $opts);
1618
}
17-
19+
1820
public function send(Email $email) {
19-
Trasmission::send($email->toSparkPostTransmission());
21+
$this->sparky->transmission->send($email->toSparkPostTransmission());
2022
}
2123
}
22-
?>
24+
?>

0 commit comments

Comments
 (0)