Skip to content

Commit fa4f9b2

Browse files
committed
MA-1084 #time 3h updated to be usable with php 5.3
1 parent a916601 commit fa4f9b2

File tree

16 files changed

+429
-85
lines changed

16 files changed

+429
-85
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"minimum-stability": "stable",
1111
"require": {
12-
"php": ">=5.6.1",
12+
"php": ">=5.3.0",
1313
"guzzlehttp/guzzle": "5.0.1"
1414
},
1515
"require-dev": {
@@ -18,7 +18,8 @@
1818
},
1919
"autoload": {
2020
"psr-4": {
21-
"SparkPost\\": "lib/SparkPost/"
21+
"SparkPost\\": "lib/SparkPost/",
22+
"SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/"
2223
}
2324
}
2425
}

examples/transmission/configuration_based.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
use SparkPost\Transmission;
77

88
$key = 'YOURAPIKEY';
9-
SparkPost::setConfig(['key'=>$key]);
9+
SparkPost::setConfig(array('key'=>$key));
1010

1111
try {
12-
$results = Transmission::send([
12+
$results = Transmission::send(array(
1313
"from"=>"From Envelope <from@example.com>",
1414
"html"=>"<p>Hello World!</p>",
1515
"text"=>"Hello World!",
1616
"subject"=>"Example Email",
17-
"recipients"=>[
18-
[
19-
"address"=>[
17+
"recipients"=>array(
18+
array(
19+
"address"=>array(
2020
"email"=>"john.doe@example.com"
21-
]
22-
]
23-
]
24-
]);
21+
)
22+
)
23+
)
24+
));
2525
echo 'Congrats you can use your SDK!';
2626
} catch (\Exception $exception) {
2727
echo $exception->getMessage();

examples/transmission/get_all_transmissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use SparkPost\Transmission;
77

88
$key = 'YOURAPIKEY';
9-
SparkPost::setConfig(['key'=>$key]);
9+
SparkPost::setConfig(array('key'=>$key));
1010

1111
try {
1212
$results = Transmission::all();

examples/transmission/get_transmission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use SparkPost\Transmission;
66

77
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(['key'=>$key]);
8+
SparkPost::setConfig(array('key'=>$key));
99

1010
try {
1111
$results = Transmission::find('Your Transmission Id');

examples/transmission/rfc822.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
use SparkPost\Transmission;
66

77
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(['key'=>$key]);
8+
SparkPost::setConfig(array('key'=>$key));
99

1010
try {
11-
$results = Transmission::send([
12-
'recipients'=>[
13-
[
14-
'address'=>[
11+
$results = Transmission::send(array(
12+
'recipients'=>array(
13+
array(
14+
'address'=>array(
1515
'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-
]);
16+
)
17+
)
18+
),
19+
'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"
20+
));
2121
echo 'Congrats you can use your SDK!';
2222
} catch (\Exception $exception) {
2323
echo $exception->getMessage();

examples/transmission/send_transmission_all_fields.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55
use SparkPost\Transmission;
66

77
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(['key'=>$key]);
8+
SparkPost::setConfig(array('key'=>$key));
99

1010
try{
11-
$results = Transmission::send([
11+
$results = Transmission::send(array(
1212
"campaign"=>"my-campaign",
13-
"metadata"=>[
13+
"metadata"=>array(
1414
"sample_campaign"=>true,
1515
"type"=>"these are custom fields"
16-
],
17-
"substitutionData"=>[
16+
),
17+
"substitutionData"=>array(
1818
"name"=>"Test Name"
19-
],
19+
),
2020
"description"=>"my description",
2121
"replyTo"=>"reply@test.com",
22-
"customHeaders"=>[
22+
"customHeaders"=>array(
2323
"X-Custom-Header"=>"Sample Custom Header"
24-
],
24+
),
2525
"trackOpens"=>false,
2626
"trackClicks"=>false,
2727
"from"=>"From Envelope <from@example.com>",
2828
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
2929
"text"=>"Hello World!",
3030
"subject"=>"Example Email: {{name}}",
31-
"recipients"=>[
32-
[
33-
"address"=>[
31+
"recipients"=>array(
32+
array(
33+
"address"=>array(
3434
"email"=>"john.doe@sample.com"
35-
]
36-
]
37-
]
38-
]);
35+
)
36+
)
37+
)
38+
));
3939
echo 'Congrats you can use your SDK!';
4040
} catch (\Exception $exception) {
4141
echo $exception->getMessage();

examples/transmission/stored_recipients_inline_content.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
use SparkPost\Transmission;
66

77
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(['key'=>$key]);
8+
SparkPost::setConfig(array('key'=>$key));
99

1010
try {
1111

12-
$results = Transmission::send([
12+
$results = Transmission::send(array(
1313
"campaign"=>"my-campaign",
1414
"from"=>"From Envelope <from@example.com>",
1515
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
1616
"text"=>"Hello World!",
1717
"subject"=>"Example Email: {{name}}",
1818
"recipientList"=>'Example List'
19-
]);
19+
));
2020

2121
echo 'Congrats you can use your SDK!';
2222
} catch (\Exception $exception) {

examples/transmission/stored_template_send.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
use SparkPost\Transmission;
66

77
$key = 'YOURAPIKEY';
8-
SparkPost::setConfig(['key'=>$key]);
8+
SparkPost::setConfig(array('key'=>$key));
99

1010
try {
11-
$results = Transmission::send([
11+
$results = Transmission::send(array(
1212
"from"=>"From Envelope <from@example.com>",
13-
"recipients"=>[
14-
[
15-
"address"=>[
13+
"recipients"=>array(
14+
array(
15+
"address"=>array(
1616
"email"=>"john.doe@sample.com"
17-
]
18-
]
19-
],
17+
)
18+
)
19+
),
2020
"template"=>"my-template"
21-
]);
21+
));
2222
echo 'Congrats you can use your SDK!';
2323
} catch (\Exception $exception) {
2424
echo $exception->getMessage();
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
namespace SparkPost\SendGridCompatibility;
3+
4+
class Email {
5+
public $model;
6+
7+
public function __construct() {
8+
$this->model = array();
9+
}
10+
11+
public function addTo($address, $name = null) {
12+
if (!isset($this->model['recipients'])) {
13+
$this->model['recipients'] = array();
14+
}
15+
16+
if(isset($name)) {
17+
$address = array('address'=>array('email'=>$address, 'name'=>$name));
18+
} else {
19+
$address = array('address'=>array('email'=>$address));
20+
}
21+
22+
array_push($this->model['recipients'], $address);
23+
return $this;
24+
}
25+
26+
public function setTos(array $addresses) {
27+
$this->model['recipients'] = $addresses;
28+
return $this;
29+
}
30+
31+
/**
32+
*
33+
* @param string $address
34+
* @return \MessageSystems\SendGridCompatibility\Email
35+
*/
36+
public function setFrom($address) {
37+
$this->model['from'] = array('email' => $address);
38+
return $this;
39+
}
40+
41+
/**
42+
* @param string $name
43+
*/
44+
public function setFromName($name) {
45+
if(!isset($this->model['from'])){
46+
throw new \Exception('Must set "From" prior to setting "From Name".');
47+
}
48+
$this->model['from']['name'] = $name;
49+
return $this;
50+
}
51+
52+
/**
53+
*
54+
* @param string $address
55+
* @return \MessageSystems\SendGridCompatibility\Email
56+
*/
57+
public function setReplyTo ($address) {
58+
$this->model['replyTo'] = $address;
59+
return $this;
60+
}
61+
62+
/**
63+
* TODO: Does this work?
64+
*
65+
*
66+
* @param string $address
67+
* @return \MessageSystems\SendGridCompatibility\Email
68+
*/
69+
public function addBcc($address) {
70+
if (!isset($this->model['bcc'])) {
71+
$this->model['bcc'] = array();
72+
}
73+
array_push($this->model['bcc'], $address);
74+
return $this;
75+
}
76+
77+
public function setSubject($subject) {
78+
$this->model['subject'] = $subject;
79+
return $this;
80+
}
81+
82+
public function setText($text) {
83+
$this->model['text'] = $text;
84+
return $this;
85+
}
86+
87+
public function setHtml($html) {
88+
$this->model['html'] = $html;
89+
return $this;
90+
}
91+
92+
public function addCategory($category) {
93+
if (!isset($this->model['tags'])) {
94+
$this->model['tags'] = array();
95+
}
96+
array_push($this->model['tags'], $category);
97+
return $this;
98+
}
99+
100+
/**
101+
*
102+
* @throws Exception
103+
* @param mixed $attachment
104+
*/
105+
public function addAttachment($attachment) {
106+
throw new \Exception('Adding attachments is not yet supported');
107+
}
108+
109+
/**
110+
* @desc Sets the name attribute on the most recent set email address
111+
* @param string $name
112+
*/
113+
public function addSubstitution($name, $values) {
114+
if (!isset($this->model['substitutionData'])) {
115+
$this->model['substitutionData'] = array();
116+
}
117+
$this->model['substitutionData'][$name] = $values;
118+
119+
return $this;
120+
}
121+
122+
public function addSection($name, $values) {
123+
$this->addSubstitution($name, $values);
124+
}
125+
126+
/**
127+
*
128+
* @throws Exception
129+
* @param mixed $attachment
130+
*/
131+
public function addUniqueArg($key, $value) {
132+
throw new \Exception('Adding Unique Arguments is not yet supported');
133+
}
134+
135+
/**
136+
*
137+
* @throws Exception
138+
* @param mixed $attachment
139+
*/
140+
public function setUniqueArgs(array $values) {
141+
throw new \Exception('Setting Unique Arguments is not yet supported');
142+
}
143+
144+
145+
public function addHeader($name, $value) {
146+
if (!isset($this->model['customHeaders'])) {
147+
$this->model['customHeaders'] = array();
148+
}
149+
$this->model['customHeaders'][$name] = $value;
150+
}
151+
152+
public function toMsysTransmission() {
153+
return $this->model;
154+
}
155+
}
156+
?>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace SparkPost\SendGridCompatibility;
3+
4+
use SparkPost\Transmission;
5+
use SparkPost\SendGridCompatibility\Email;
6+
use SparkPost\Configuration;
7+
8+
class SendGrid{
9+
private $sparkPost;
10+
11+
public function __construct($username, $password, $options = null) {
12+
//username isn't used in our system
13+
$opts = array('key'=>$password);
14+
if (!is_null($options)) {
15+
$opts = array_merge($opts, $options);
16+
}
17+
Configuration::setConfig($opts);
18+
}
19+
20+
public function send(Email $email) {
21+
Trasmission::send($email->toMsysTransmission());
22+
}
23+
}
24+
?>

0 commit comments

Comments
 (0)