Skip to content

Commit 286f9be

Browse files
danil zakablukovskiijasonrhodes
danil zakablukovskii
authored andcommitted
removed test, because it's not needed after added strong-typing to the 'setHttpAdapter' method
1 parent f4ed222 commit 286f9be

File tree

8 files changed

+162
-249
lines changed

8 files changed

+162
-249
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sparkpost/php-sparkpost",
33
"description": "Client library for interfacing with the SparkPost API.",
44
"license": "Apache 2.0",
5-
"version": "1.0.1",
5+
"version": "1.0.2",
66
"authors": [
77
{
88
"name": "Message Systems, Inc."

lib/SendGridCompatibility/Email.php

+43-90
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,146 @@
11
<?php
22
namespace SparkPost\SendGridCompatibility;
33

4-
class Email
5-
{
4+
class Email {
65
public $model;
76

87
/**
98
* Sets up the model for saving the configuration
109
*/
11-
public function __construct()
12-
{
10+
public function __construct() {
1311
$this->model = array();
1412
}
1513

1614
/**
17-
* Adds addresses as recipients
18-
*
15+
* adds addresses as recipients
1916
* @param string $address
2017
* @param string $name optional
21-
* @return \SparkPost\SendGridCompatibility\Email
18+
* @return $this
2219
*/
23-
public function addTo($address, $name = null)
24-
{
20+
public function addTo($address, $name = null) {
2521
if (!isset($this->model['recipients'])) {
2622
$this->model['recipients'] = array();
2723
}
2824

29-
if (isset($name)) {
30-
$address = array('address' => array('email' => $address, 'name' => $name));
25+
if(isset($name)) {
26+
$address = array('address'=>array('email'=>$address, 'name'=>$name));
3127
} else {
32-
$address = array('address' => array('email' => $address));
28+
$address = array('address'=>array('email'=>$address));
3329
}
3430

3531
array_push($this->model['recipients'], $address);
36-
3732
return $this;
3833
}
3934

4035
/**
41-
* Explicitly sets a list of addresses
42-
*
43-
* @param array $addresses
44-
* @return \SparkPost\SendGridCompatibility\Email
45-
*/
46-
public function setTos(array $addresses)
47-
{
36+
* explicitly sets a list of addresses
37+
* @param array $addresses
38+
* @return $this
39+
*/
40+
public function setTos(array $addresses) {
4841
$this->model['recipients'] = $addresses;
49-
5042
return $this;
5143
}
5244

5345
/**
54-
* Sets the from address
55-
*
46+
* sets the from address
5647
* @param string $address
5748
* @return $this
5849
*/
59-
public function setFrom($address)
60-
{
50+
public function setFrom($address) {
6151
$this->model['from'] = array('email' => $address);
62-
6352
return $this;
6453
}
6554

6655
/**
6756
* Sets the name for the from address
68-
*
6957
* @param string $name
7058
* @return $this
7159
* @throws \Exception
7260
*/
73-
public function setFromName($name)
74-
{
75-
if (!isset($this->model['from'])) {
61+
public function setFromName($name) {
62+
if(!isset($this->model['from'])){
7663
throw new \Exception('Must set \'From\' prior to setting \'From Name\'.');
7764
}
7865
$this->model['from']['name'] = $name;
79-
8066
return $this;
8167
}
8268

8369
/**
84-
* Sets the reply to field
85-
*
70+
* sets the reply to field
8671
* @param string $address
8772
* @return $this
8873
*/
89-
public function setReplyTo($address)
90-
{
74+
public function setReplyTo ($address) {
9175
$this->model['replyTo'] = $address;
92-
9376
return $this;
9477
}
9578

9679
/**
97-
* Throws an error because bcc fields are not yet implemented
98-
*
80+
* throws an error because bcc fields are not yet implemented.
9981
* @throws \Exception
10082
* @param string $address
10183
* @return $this
10284
*/
103-
public function addBcc($address)
104-
{
85+
public function addBcc($address) {
10586
throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a \'to\' address');
10687
}
10788

10889
/**
109-
* Sets the subject header
110-
*
90+
* sets the subject header
11191
* @param string $subject
112-
* @return \SparkPost\SendGridCompatibility\Email
92+
* @return $this
11393
*/
114-
public function setSubject($subject)
115-
{
94+
public function setSubject($subject) {
11695
$this->model['subject'] = $subject;
117-
11896
return $this;
11997
}
12098

12199
/**
122-
* Sets the text body
123-
*
100+
* sets the text body
124101
* @param string $text
125-
* @return \SparkPost\SendGridCompatibility\Email
102+
* @return $this
126103
*/
127-
public function setText($text)
128-
{
104+
public function setText($text) {
129105
$this->model['text'] = $text;
130-
131106
return $this;
132107
}
133108

134109
/**
135-
* Sets the html body
136-
*
110+
* sets the html body
137111
* @param string $html
138-
* @return \SparkPost\SendGridCompatibility\Email
112+
* @return $this
139113
*/
140-
public function setHtml($html)
141-
{
114+
public function setHtml($html) {
142115
$this->model['html'] = $html;
143-
144116
return $this;
145117
}
146118

147119
/**
148120
* Throws an exception since adding categories is not yet supported
149-
*
150-
* @throws \Exception
151121
* @param string $category
152122
* @throws \Exception
153123
*/
154-
public function addCategory($category)
155-
{
124+
public function addCategory($category) {
156125
throw new \Exception('Adding categories is not yet supported');
157126
}
158127

159128
/**
160129
* Throws an exception since adding attachments is not yet supported
161-
*
162-
* @param mixed $attachment
163130
* @throws \Exception
131+
* @param mixed $attachment
164132
*/
165-
public function addAttachment($attachment)
166-
{
133+
public function addAttachment($attachment) {
167134
throw new \Exception('Adding attachments is not yet supported');
168135
}
169136

170137
/**
171138
* Adds transmission level substitution data
172-
*
173139
* @param string $name
174140
* @param mixed $values
175-
* @return \SparkPost\SendGridCompatibility\Email
141+
* @return $this
176142
*/
177-
public function addSubstitution($name, $values)
178-
{
143+
public function addSubstitution($name, $values) {
179144
if (!isset($this->model['substitutionData'])) {
180145
$this->model['substitutionData'] = array();
181146
}
@@ -186,61 +151,49 @@ public function addSubstitution($name, $values)
186151

187152
/**
188153
* Adds transmission level substitution data
189-
*
190154
* @param string $name
191155
* @param mixed $values
192156
*/
193-
public function addSection($name, $values)
194-
{
157+
public function addSection($name, $values) {
195158
$this->addSubstitution($name, $values);
196159
}
197160

198161
/**
199162
* Throws an exception because arguments for third party systems is not supported
200-
*
201-
* @param $key
202-
* @param mixed $value
203163
* @throws \Exception
164+
* @param mixed $value
204165
*/
205-
public function addUniqueArg($key, $value)
206-
{
166+
public function addUniqueArg($key, $value) {
207167
throw new \Exception('Adding Unique Arguments is not yet supported');
208168
}
209169

210170
/**
211171
* Throws an exception because arguments for third party systems is not supported
212-
*
213-
* @param mixed $values
214172
* @throws \Exception
173+
* @param mixed $values
215174
*/
216-
public function setUniqueArgs(array $values)
217-
{
175+
public function setUniqueArgs(array $values) {
218176
throw new \Exception('Setting Unique Arguments is not yet supported');
219177
}
220178

221179
/**
222180
* Adds custom headers to the email header
223-
*
224181
* @param string $name
225182
* @param string $value
226183
*/
227-
public function addHeader($name, $value)
228-
{
184+
public function addHeader($name, $value) {
229185
if (!isset($this->model['customHeaders'])) {
230186
$this->model['customHeaders'] = array();
231187
}
232188
$this->model['customHeaders'][$name] = $value;
233189
}
234190

235191
/**
236-
* Converts this object to a configuration for a SparkPost transmission
237-
*
192+
* converts this object to a configuration for a SparkPost transmission
238193
* @return array
239194
*/
240-
public function toSparkPostTransmission()
241-
{
195+
public function toSparkPostTransmission() {
242196
return $this->model;
243197
}
244198
}
245-
246199
?>

lib/SendGridCompatibility/SendGrid.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33

44
use SparkPost\SparkPost;
55

6-
class SendGrid
7-
{
6+
class SendGrid{
87
private $sparky;
98

10-
public function __construct($username, $password, $options = null, $httpAdapter)
11-
{
12-
// username isn't used in our system
13-
$opts = array('key' => $password);
9+
public function __construct($username, $password, $options = null, $httpAdapter) {
10+
//username isn't used in our system
11+
$opts = array('key'=>$password);
1412
if (!is_null($options)) {
1513
$opts = array_merge($opts, $options);
1614
}
1715

1816
$this->sparky = new SparkPost($httpAdapter, $opts);
1917
}
2018

21-
public function send(Email $email)
22-
{
19+
public function send(Email $email) {
2320
$this->sparky->transmission->send($email->toSparkPostTransmission());
2421
}
2522
}
26-
2723
?>

0 commit comments

Comments
 (0)