Skip to content

Commit 68a7e8e

Browse files
committed
MA-946 #time 3h 30m Revamped Transmission object to be stateless,
updated tests and examples.
1 parent de407ac commit 68a7e8e

15 files changed

+236
-862
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
},
2020
"autoload": {
2121
"psr-4": {
22-
"MessageSystems\\": "lib/MessageSystems/",
23-
"SparkPost\\": "lib/"
22+
"MessageSystems\\": "lib/MessageSystems/"
2423
}
2524
}
2625
}

examples/transmission/configuration_based.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

5-
use SparkPost\SparkPost;
5+
use MessageSystems\SparkPost;
6+
use MessageSystems\Transmission;
67

78
$key = 'YOURAPIKEY';
8-
$sdk = new SparkPost(['key'=>$key]);
9-
10-
$transmission = $sdk->Transmission([
11-
"return_path"=>"return@example.com",
12-
"from"=>"From Envelope <from@example.com>",
13-
"html"=>"<p>Hello World!</p>",
14-
"text"=>"Hello World!",
15-
"subject"=>"Example Email",
16-
"recipients"=>[
17-
[
18-
"address"=>[
19-
"email"=>"john.doe@sample.com"
20-
]
21-
]
22-
]
23-
]);
9+
SparkPost::setConfig(['key'=>$key]);
2410

2511
try {
26-
$results = $transmission->send();
12+
$results = Transmission::send([
13+
"returnPath"=>"return@example.com",
14+
"from"=>"From Envelope <from@example.com>",
15+
"html"=>"<p>Hello World!</p>",
16+
"text"=>"Hello World!",
17+
"subject"=>"Example Email",
18+
"recipients"=>[
19+
[
20+
"address"=>[
21+
"email"=>"jordan.nornhold@rackspace.messagesystems.com"
22+
]
23+
]
24+
]
25+
]);
2726
echo 'Congrats you can use your SDK!';
27+
28+
var_dump(Transmission::$structure);
2829
} catch (\Exception $exception) {
2930
echo $exception->getMessage();
3031
}

examples/transmission/get_all_transmissions.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
44

5-
use SparkPost\SparkPost;
5+
use MessageSystems\SparkPost;
6+
use MessageSystems\Transmission;
67

7-
$key = 'YOURAPIKEY';
8-
$sdk = new SparkPost(['key'=>$key]);
9-
10-
$transmission = $sdk->Transmission();
8+
$key = 'YOURAPIKEY';
9+
SparkPost::setConfig(['key'=>$key]);
1110

1211
try {
13-
$results = $transmission->all();
12+
$results = Transmission::all();
1413
echo 'Congrats you can use your SDK!';
1514
} catch (\Exception $exception) {
1615
echo $exception->getMessage();

examples/transmission/get_transmission.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
5-
6-
$key = 'YOURAPIKEY';
7-
$sdk = new SparkPost(['key'=>$key]);
8-
9-
$transmission = $sdk->Transmission();
4+
use MessageSystems\SparkPost;
5+
use MessageSystems\Transmission;
6+
7+
$key = 'YOURAPIKEY';
8+
SparkPost::setConfig(['key'=>$key]);
109

1110
try {
12-
$results = $transmission->find('11860038888980495');
11+
$results = Transmission::find('Your Transmission Id');
1312
echo 'Congrats you can use your SDK!';
1413
} catch (\Exception $exception) {
1514
echo $exception->getMessage();

examples/transmission/mime_parts.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/transmission/rfc822.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
5-
6-
$key = 'YOURAPIKEY';
7-
$sdk = new SparkPost(['key'=>$key]);
8-
9-
10-
11-
$transmission = $sdk->Transmission();
12-
13-
$transmission->setReturnPath('return@example.com')
14-
->addRecipient([
15-
'address'=>[
16-
'email'=>'john.doe@sample.com'
17-
]
18-
])
19-
->setRfc822Content("Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World");
20-
4+
use MessageSystems\SparkPost;
5+
use MessageSystems\Transmission;
6+
7+
$key = 'YOURAPIKEY';
8+
SparkPost::setConfig(['key'=>$key]);
219

2210
try {
23-
$results = $transmission->send();
11+
$results = Transmission::send([
12+
'recipients'=>[
13+
[
14+
'address'=>[
15+
'email'=>'john.doe@sample.com'
16+
]
17+
]
18+
],
19+
'rfc822Part'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"
20+
]);
2421
echo 'Congrats you can use your SDK!';
2522
} catch (\Exception $exception) {
2623
echo $exception->getMessage();

examples/transmission/send_transmission_all_fields.php

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
4+
use MessageSystems\SparkPost;
5+
use MessageSystems\Transmission;
56

67
$key = 'YOURAPIKEY';
7-
$sdk = new SparkPost(['key'=>$key]);
8+
SparkPost::setConfig(['key'=>$key]);
89

9-
10-
11-
$transmission = $sdk->Transmission([
12-
"campaign"=>"my-campaign",
13-
"metadata"=>[
14-
"sample_campaign"=>true,
15-
"type"=>"these are custom fields"
16-
],
17-
"substitutionData"=>[
18-
"name"=>"Test Name"
19-
],
20-
"description"=>"my description",
21-
"return_path"=>"return@example.com",
22-
"replyTo"=>"reply@test.com",
23-
"headers"=>[
24-
"X-Custom-Header"=>"Sample Custom Header"
25-
],
26-
"openTracking"=>false,
27-
"clickTracking"=>false,
28-
"from"=>"From Envelope <from@example.com>",
29-
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
30-
"text"=>"Hello World!",
31-
"subject"=>"Example Email: {{name}}",
32-
"recipients"=>[
33-
[
34-
"address"=>[
35-
"email"=>"john.doe@sample.com"
36-
]
37-
]
38-
]
39-
]);
40-
41-
try {
42-
$results = $transmission->send();
10+
try{
11+
$results = Transmission::send([
12+
"campaign"=>"my-campaign",
13+
"metadata"=>[
14+
"sample_campaign"=>true,
15+
"type"=>"these are custom fields"
16+
],
17+
"substitutionData"=>[
18+
"name"=>"Test Name"
19+
],
20+
"description"=>"my description",
21+
"replyTo"=>"reply@test.com",
22+
"headers"=>[
23+
"X-Custom-Header"=>"Sample Custom Header"
24+
],
25+
"openTracking"=>false,
26+
"clickTracking"=>false,
27+
"from"=>"From Envelope <from@example.com>",
28+
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
29+
"text"=>"Hello World!",
30+
"subject"=>"Example Email: {{name}}",
31+
"recipients"=>[
32+
[
33+
"address"=>[
34+
"email"=>"john.doe@sample.com"
35+
]
36+
]
37+
]
38+
]);
4339
echo 'Congrats you can use your SDK!';
4440
} catch (\Exception $exception) {
4541
echo $exception->getMessage();

examples/transmission/send_transmission_all_fields_method_based.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/transmission/stored_recipients_inline_content.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
4+
use MessageSystems\SparkPost;
5+
use MessageSystems\Transmission;
6+
7+
$key = 'YOURAPIKEY';
8+
SparkPost::setConfig(['key'=>$key]);
9+
510

6-
$key = 'YOURAPIKEY';
7-
$sdk = new SparkPost(['key'=>$key]);
811

12+
try {
913

14+
$results = Transmission::send([
15+
"campaign"=>"my-campaign",
16+
"from"=>"From Envelope <from@example.com>",
17+
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
18+
"text"=>"Hello World!",
19+
"subject"=>"Example Email: {{name}}",
20+
"recipientList"=>'Example List'
21+
]);
1022

11-
$transmission = $sdk->Transmission();
12-
13-
$transmission->setCampaign('my campaign')
14-
->setReturnPath('return@example.com')
15-
->setFrom('From Envelope <from@example.com>')
16-
->useRecipientList('Example List')
17-
->setSubject('Example Email')
18-
->setHTMLContent('<p>Hello World!</p>')
19-
->setTextContent('Hello World!');
20-
21-
try {
22-
$results = $transmission->send();
2323
echo 'Congrats you can use your SDK!';
2424
} catch (\Exception $exception) {
2525
echo $exception->getMessage();

examples/transmission/stored_template_send.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
<?php
22
namespace Examples\Transmisson;
33
require_once (dirname(__FILE__).'/../bootstrap.php');
4-
use SparkPost\SparkPost;
5-
6-
7-
$key = 'YOURAPIKEY';
8-
$sdk = new SparkPost(['key'=>$key]);
9-
10-
11-
12-
$transmission = $sdk->Transmission();
13-
14-
$transmission->setReturnPath('return@example.com')
15-
->setFrom('From Envelope <from@example.com>')
16-
->addRecipient([
17-
"address"=>[
18-
"email"=>"john.doe@sample.com"
19-
]
20-
])
21-
->useStoredTemplate('my-template');
4+
use MessageSystems\SparkPost;
5+
use MessageSystems\Transmission;
6+
7+
$key = 'YOURAPIKEY';
8+
SparkPost::setConfig(['key'=>$key]);
229

2310
try {
24-
$results = $transmission->send();
11+
$results = Transmission::send([
12+
"from"=>"From Envelope <from@example.com>",
13+
"recipients"=>[
14+
[
15+
"address"=>[
16+
"email"=>"john.doe@sample.com"
17+
]
18+
]
19+
],
20+
"template"=>"my-template"
21+
]);
2522
echo 'Congrats you can use your SDK!';
2623
} catch (\Exception $exception) {
2724
echo $exception->getMessage();

0 commit comments

Comments
 (0)