Skip to content

Commit d3eeaeb

Browse files
committed
MA-1084 #time 30m added function docs and started review
1 parent da6b12d commit d3eeaeb

File tree

3 files changed

+68
-20
lines changed

3 files changed

+68
-20
lines changed

lib/SendGridCompatibility/Email.php

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44
class Email {
55
public $model;
66

7+
8+
/**
9+
* @desc Sets up the model for saving the configuration
10+
*/
711
public function __construct() {
812
$this->model = array();
913
}
1014

15+
/**
16+
* @desc adds addresses as recipients
17+
* @param string $address
18+
* @param string $name optional
19+
* @return \SparkPost\SendGridCompatibility\Email
20+
*/
1121
public function addTo($address, $name = null) {
1222
if (!isset($this->model['recipients'])) {
1323
$this->model['recipients'] = array();
@@ -23,13 +33,18 @@ public function addTo($address, $name = null) {
2333
return $this;
2434
}
2535

36+
/**
37+
* @desc explicitly sets a list of addresses
38+
* @param array $addresses
39+
* @return \SparkPost\SendGridCompatibility\Email
40+
*/
2641
public function setTos(array $addresses) {
2742
$this->model['recipients'] = $addresses;
2843
return $this;
2944
}
3045

3146
/**
32-
*
47+
* @desc sets the from address
3348
* @param string $address
3449
* @return \MessageSystems\SendGridCompatibility\Email
3550
*/
@@ -39,6 +54,7 @@ public function setFrom($address) {
3954
}
4055

4156
/**
57+
* @desc sets the name for the from address
4258
* @param string $name
4359
*/
4460
public function setFromName($name) {
@@ -50,7 +66,7 @@ public function setFromName($name) {
5066
}
5167

5268
/**
53-
*
69+
* @desc sets the reply to field
5470
* @param string $address
5571
* @return \MessageSystems\SendGridCompatibility\Email
5672
*/
@@ -60,38 +76,57 @@ public function setReplyTo ($address) {
6076
}
6177

6278
/**
79+
* @desc throws an error because bcc fields are not yet implemented.
80+
* @throws \Exception
6381
* @param string $address
6482
* @return \MessageSystems\SendGridCompatibility\Email
6583
*/
6684
public function addBcc($address) {
6785
throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a "to" address');
6886
}
6987

88+
/**
89+
* @desc sets the subject header
90+
* @param string $subject
91+
* @return \SparkPost\SendGridCompatibility\Email
92+
*/
7093
public function setSubject($subject) {
7194
$this->model['subject'] = $subject;
7295
return $this;
7396
}
7497

98+
/**
99+
* @desc sets the text body
100+
* @param string $text
101+
* @return \SparkPost\SendGridCompatibility\Email
102+
*/
75103
public function setText($text) {
76104
$this->model['text'] = $text;
77105
return $this;
78106
}
79107

108+
/**
109+
* @desc sets the html body
110+
* @param string $html
111+
* @return \SparkPost\SendGridCompatibility\Email
112+
*/
80113
public function setHtml($html) {
81114
$this->model['html'] = $html;
82115
return $this;
83116
}
84117

118+
/**
119+
* @desc Throws an exception since adding categories is not yet supported
120+
* @throws \Exception
121+
* @param string $category
122+
* @throws \Exception
123+
*/
85124
public function addCategory($category) {
86-
if (!isset($this->model['tags'])) {
87-
$this->model['tags'] = array();
88-
}
89-
array_push($this->model['tags'], $category);
90-
return $this;
125+
throw new \Exception('Adding categories is not yet supported');
91126
}
92127

93128
/**
94-
*
129+
* @desc Throws an exception since adding attachments is not yet supported
95130
* @throws Exception
96131
* @param mixed $attachment
97132
*/
@@ -100,8 +135,10 @@ public function addAttachment($attachment) {
100135
}
101136

102137
/**
103-
* @desc Sets the name attribute on the most recent set email address
138+
* @desc Adds transmission level substitution data
104139
* @param string $name
140+
* @param mixed $values
141+
* @return \SparkPost\SendGridCompatibility\Email
105142
*/
106143
public function addSubstitution($name, $values) {
107144
if (!isset($this->model['substitutionData'])) {
@@ -112,37 +149,50 @@ public function addSubstitution($name, $values) {
112149
return $this;
113150
}
114151

152+
/**
153+
* @desc Adds transmission level substitution data
154+
* @param string $name
155+
* @param mixed $values
156+
*/
115157
public function addSection($name, $values) {
116158
$this->addSubstitution($name, $values);
117159
}
118160

119161
/**
120-
*
162+
* @desc Throws an exception because arguments for third party systems is not supported
121163
* @throws Exception
122-
* @param mixed $attachment
164+
* @param mixed $value
123165
*/
124166
public function addUniqueArg($key, $value) {
125167
throw new \Exception('Adding Unique Arguments is not yet supported');
126168
}
127169

128170
/**
129-
*
171+
* @desc Throws an exception because arguments for third party systems is not supported
130172
* @throws Exception
131-
* @param mixed $attachment
173+
* @param mixed $values
132174
*/
133175
public function setUniqueArgs(array $values) {
134176
throw new \Exception('Setting Unique Arguments is not yet supported');
135177
}
136178

137-
179+
/**
180+
* @desc Adds custom headers to the email header
181+
* @param string $name
182+
* @param string $value
183+
*/
138184
public function addHeader($name, $value) {
139185
if (!isset($this->model['customHeaders'])) {
140186
$this->model['customHeaders'] = array();
141187
}
142188
$this->model['customHeaders'][$name] = $value;
143189
}
144190

145-
public function toMsysTransmission() {
191+
/**
192+
* @desc converts this object to a configuration for a SparkPost transmission
193+
* @return array
194+
*/
195+
public function toSparkPostTransmission() {
146196
return $this->model;
147197
}
148198
}

lib/SendGridCompatibility/SendGrid.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use SparkPost\Configuration;
77

88
class SendGrid{
9-
private $sparkPost;
10-
119
public function __construct($username, $password, $options = null) {
1210
//username isn't used in our system
1311
$opts = array('key'=>$password);
@@ -18,7 +16,7 @@ public function __construct($username, $password, $options = null) {
1816
}
1917

2018
public function send(Email $email) {
21-
Trasmission::send($email->toMsysTransmission());
19+
Trasmission::send($email->toSparkPostTransmission());
2220
}
2321
}
2422
?>

test/unit/SendGridCompatibiility/EmailTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public function testAddHeader() {
151151
$this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']);
152152
}
153153

154-
public function testToMsysTransmission() {
155-
$this->assertInternalType('array', $this->email->toMsysTransmission());
154+
public function testToSparkPostTransmission() {
155+
$this->assertInternalType('array', $this->email->toSparkPostTransmission());
156156
}
157157
}
158158

0 commit comments

Comments
 (0)