Skip to content

Commit b51ce2d

Browse files
committed
finished code updates/refactoring updated examples and began refactoring tests
1 parent 0c4b276 commit b51ce2d

12 files changed

+380
-269
lines changed

examples/transmission/get_all_transmissions.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
use GuzzleHttp\Client;
88
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
99

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

1414
try {
1515
$results = Transmission::all();
16-
var_dump($results);
1716
echo 'Congrats you can use your SDK!';
1817
} catch (\Exception $exception) {
1918
echo $exception->getMessage();

examples/transmission/get_transmission.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\Transmission;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
8+
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
612

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
913

1014
try {
11-
$results = Transmission::find('Your Transmission Id');
15+
$results = Transmission::find('Your Transmission ID');
1216
echo 'Congrats you can use your SDK!';
1317
} catch (\Exception $exception) {
1418
echo $exception->getMessage();
1519
}
16-
?>
20+
?>

examples/transmission/rfc822.php

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\Transmission;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
68

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
912

1013
try {
11-
$results = Transmission::send(array(
12-
'recipients'=>array(
13-
array(
14-
'address'=>array(
15-
'email'=>'john.doe@sample.com'
16-
)
17-
)
18-
),
19-
'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"
20-
));
14+
$results = Transmission::send([
15+
'recipients'=>[
16+
[
17+
'address'=>[
18+
'email'=>'john.doe@example.com'
19+
]
20+
]
21+
],
22+
'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@sparkpostbox.com>\nSubject: Example Email\n\nHello World"
23+
]);
2124
echo 'Congrats you can use your SDK!';
2225
} catch (\Exception $exception) {
2326
echo $exception->getMessage();
2427
}
25-
?>
28+
?>

examples/transmission/send_transmission_all_fields.php

+26-19
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,48 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\Transmission;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
68

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
12+
13+
// TODO: update all from emails to = sandbox domain
914

1015
try{
11-
$results = Transmission::send(array(
16+
$results = Transmission::send([
1217
"campaign"=>"my-campaign",
13-
"metadata"=>array(
18+
"metadata"=>[
1419
"sample_campaign"=>true,
1520
"type"=>"these are custom fields"
16-
),
17-
"substitutionData"=>array(
21+
],
22+
"substitutionData"=>[
1823
"name"=>"Test Name"
19-
),
24+
],
2025
"description"=>"my description",
2126
"replyTo"=>"reply@test.com",
22-
"customHeaders"=>array(
27+
"customHeaders"=>[
2328
"X-Custom-Header"=>"Sample Custom Header"
24-
),
29+
],
2530
"trackOpens"=>false,
2631
"trackClicks"=>false,
27-
"from"=>"From Envelope <from@example.com>",
32+
"from"=>"From Envelope <from@sparkpostbox.com>",
2833
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
2934
"text"=>"Hello World!",
3035
"subject"=>"Example Email: {{name}}",
31-
"recipients"=>array(
32-
array(
33-
"address"=>array(
34-
"email"=>"john.doe@sample.com"
35-
)
36-
)
37-
)
38-
));
36+
"recipients"=>[
37+
[
38+
"address"=>[
39+
"email"=>"john.doe@example.com"
40+
]
41+
]
42+
]
43+
]);
44+
45+
var_dump($results);
3946
echo 'Congrats you can use your SDK!';
4047
} catch (\Exception $exception) {
4148
echo $exception->getMessage();
4249
}
43-
?>
50+
?>

examples/transmission/simple_send.php

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
<?php
2-
namespace Examples\Transmisson;
2+
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

55
use SparkPost\SparkPost;
66
use SparkPost\Transmission;
7+
use GuzzleHttp\Client;
8+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
79

8-
$key = 'YOURAPIKEY';
9-
SparkPost::setConfig(array('key'=>$key));
10+
$key = 'YOUR API KEY';
11+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
12+
SparkPost::configure($httpAdapter, ['key'=>$key]);
1013

1114
try {
12-
$results = Transmission::send(array(
13-
"from"=>"From Envelope <from@example.com>",
14-
"html"=>"<p>Hello World!</p>",
15-
"text"=>"Hello World!",
16-
"subject"=>"Example Email",
17-
"recipients"=>array(
18-
array(
19-
"address"=>array(
20-
"email"=>"john.doe@example.com"
21-
)
22-
)
23-
)
24-
));
15+
$results = Transmission::send([
16+
"from"=>"From Envelope <from@sparkpostbox.com>",
17+
"html"=>"<p>Hello World!</p>",
18+
"text"=>"Hello World!",
19+
"subject"=>"Example Email",
20+
"recipients"=>[
21+
[
22+
"address"=>[
23+
"email"=>"john.doe@example.com"
24+
]
25+
]
26+
]
27+
]);
2528
echo 'Congrats you can use your SDK!';
2629
} catch (\Exception $exception) {
2730
echo $exception->getMessage();
2831
}
29-
?>
32+
?>

examples/transmission/stored_recipients_inline_content.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\Transmission;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
68

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
912

1013
try {
1114

12-
$results = Transmission::send(array(
15+
$results = Transmission::send([
1316
"campaign"=>"my-campaign",
14-
"from"=>"From Envelope <from@example.com>",
17+
"from"=>"From Envelope <from@sparkpostbox.com>",
1518
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
1619
"text"=>"Hello World!",
1720
"subject"=>"Example Email: {{name}}",
1821
"recipientList"=>'Example List'
19-
));
22+
]);
2023

2124
echo 'Congrats you can use your SDK!';
2225
} catch (\Exception $exception) {
2326
echo $exception->getMessage();
2427
}
25-
?>
28+
?>

examples/transmission/stored_template_send.php

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\Transmission;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
68

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
912

1013
try {
11-
$results = Transmission::send(array(
12-
"from"=>"From Envelope <from@example.com>",
13-
"recipients"=>array(
14-
array(
15-
"address"=>array(
16-
"email"=>"john.doe@sample.com"
17-
)
18-
)
19-
),
14+
$results = Transmission::send([
15+
"from"=>"From Envelope <from@sparkpostbox.com>",
16+
"recipients"=>[
17+
[
18+
"address"=>[
19+
"email"=>"john.doe@example.com"
20+
]
21+
]
22+
],
2023
"template"=>"my-template"
21-
));
24+
]);
2225
echo 'Congrats you can use your SDK!';
2326
} catch (\Exception $exception) {
2427
echo $exception->getMessage();
2528
}
26-
?>
29+
?>

examples/unwrapped/create_template.php

+17-10
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44
use SparkPost\SparkPost;
55
use SparkPost\APIResource;
6+
use GuzzleHttp\Client;
7+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
68

7-
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(array('key'=>$key));
9+
$key = 'YOUR API KEY';
10+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
11+
SparkPost::configure($httpAdapter, ['key'=>$key]);
912

1013
try {
1114
// define the endpoint
1215
APIResource::$endpoint = 'templates';
13-
14-
$templateConfig = array(
16+
17+
$templateConfig = [
1518
'name' => 'Summer Sale!',
16-
'content.from' => 'marketing@bounces.company.example',
17-
'content.subject' => 'Summer deals',
18-
'content.html' => '<b>Check out these deals!</b>',
19-
);
20-
$results = APIResource::sendRequest($templateConfig);
19+
'id'=>'summer-sale',
20+
'content'=> [
21+
'from' => 'john.doe@sparkpostbox.com',
22+
'subject' => 'Summer deals',
23+
'html' => '<b>Check out these deals!</b>'
24+
]
25+
];
26+
$results = APIResource::create($templateConfig);
27+
var_dump($results);
2128
echo 'Congrats you can use your SDK!';
2229
} catch (\Exception $exception) {
2330
echo $exception->getMessage();
2431
}
25-
?>
32+
?>

0 commit comments

Comments
 (0)