diff options
author | nornholdj <nornholdj@gmail.com> | 2014-11-13 14:57:52 -0500 |
---|---|---|
committer | nornholdj <nornholdj@gmail.com> | 2014-11-13 14:57:52 -0500 |
commit | d3eeaebd1d4d5d6db1428c2b9b3cc35fdf71ef4a (patch) | |
tree | 13a879bee893bcd9a6d2ec0314bb0e85f421e2af | |
parent | da6b12d6650868ea48afcb5a960ab6214ed6004f (diff) | |
download | php-sparkpost-d3eeaebd1d4d5d6db1428c2b9b3cc35fdf71ef4a.zip php-sparkpost-d3eeaebd1d4d5d6db1428c2b9b3cc35fdf71ef4a.tar.gz php-sparkpost-d3eeaebd1d4d5d6db1428c2b9b3cc35fdf71ef4a.tar.bz2 |
MA-1084 #time 30m added function docs and started review
-rw-r--r-- | lib/SendGridCompatibility/Email.php | 80 | ||||
-rw-r--r-- | lib/SendGridCompatibility/SendGrid.php | 4 | ||||
-rw-r--r-- | test/unit/SendGridCompatibiility/EmailTest.php | 4 |
3 files changed, 68 insertions, 20 deletions
diff --git a/lib/SendGridCompatibility/Email.php b/lib/SendGridCompatibility/Email.php index 0b78c22..5351324 100644 --- a/lib/SendGridCompatibility/Email.php +++ b/lib/SendGridCompatibility/Email.php @@ -4,10 +4,20 @@ namespace SparkPost\SendGridCompatibility; class Email { public $model; + + /** + * @desc Sets up the model for saving the configuration + */ public function __construct() { $this->model = array(); } + /** + * @desc adds addresses as recipients + * @param string $address + * @param string $name optional + * @return \SparkPost\SendGridCompatibility\Email + */ public function addTo($address, $name = null) { if (!isset($this->model['recipients'])) { $this->model['recipients'] = array(); @@ -23,13 +33,18 @@ class Email { return $this; } + /** + * @desc explicitly sets a list of addresses + * @param array $addresses + * @return \SparkPost\SendGridCompatibility\Email + */ public function setTos(array $addresses) { $this->model['recipients'] = $addresses; return $this; } /** - * + * @desc sets the from address * @param string $address * @return \MessageSystems\SendGridCompatibility\Email */ @@ -39,6 +54,7 @@ class Email { } /** + * @desc sets the name for the from address * @param string $name */ public function setFromName($name) { @@ -50,7 +66,7 @@ class Email { } /** - * + * @desc sets the reply to field * @param string $address * @return \MessageSystems\SendGridCompatibility\Email */ @@ -60,6 +76,8 @@ class Email { } /** + * @desc throws an error because bcc fields are not yet implemented. + * @throws \Exception * @param string $address * @return \MessageSystems\SendGridCompatibility\Email */ @@ -67,31 +85,48 @@ class Email { throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a "to" address'); } + /** + * @desc sets the subject header + * @param string $subject + * @return \SparkPost\SendGridCompatibility\Email + */ public function setSubject($subject) { $this->model['subject'] = $subject; return $this; } + /** + * @desc sets the text body + * @param string $text + * @return \SparkPost\SendGridCompatibility\Email + */ public function setText($text) { $this->model['text'] = $text; return $this; } + /** + * @desc sets the html body + * @param string $html + * @return \SparkPost\SendGridCompatibility\Email + */ public function setHtml($html) { $this->model['html'] = $html; return $this; } + /** + * @desc Throws an exception since adding categories is not yet supported + * @throws \Exception + * @param string $category + * @throws \Exception + */ public function addCategory($category) { - if (!isset($this->model['tags'])) { - $this->model['tags'] = array(); - } - array_push($this->model['tags'], $category); - return $this; + throw new \Exception('Adding categories is not yet supported'); } /** - * + * @desc Throws an exception since adding attachments is not yet supported * @throws Exception * @param mixed $attachment */ @@ -100,8 +135,10 @@ class Email { } /** - * @desc Sets the name attribute on the most recent set email address + * @desc Adds transmission level substitution data * @param string $name + * @param mixed $values + * @return \SparkPost\SendGridCompatibility\Email */ public function addSubstitution($name, $values) { if (!isset($this->model['substitutionData'])) { @@ -112,29 +149,38 @@ class Email { return $this; } + /** + * @desc Adds transmission level substitution data + * @param string $name + * @param mixed $values + */ public function addSection($name, $values) { $this->addSubstitution($name, $values); } /** - * + * @desc Throws an exception because arguments for third party systems is not supported * @throws Exception - * @param mixed $attachment + * @param mixed $value */ public function addUniqueArg($key, $value) { throw new \Exception('Adding Unique Arguments is not yet supported'); } /** - * + * @desc Throws an exception because arguments for third party systems is not supported * @throws Exception - * @param mixed $attachment + * @param mixed $values */ public function setUniqueArgs(array $values) { throw new \Exception('Setting Unique Arguments is not yet supported'); } - + /** + * @desc Adds custom headers to the email header + * @param string $name + * @param string $value + */ public function addHeader($name, $value) { if (!isset($this->model['customHeaders'])) { $this->model['customHeaders'] = array(); @@ -142,7 +188,11 @@ class Email { $this->model['customHeaders'][$name] = $value; } - public function toMsysTransmission() { + /** + * @desc converts this object to a configuration for a SparkPost transmission + * @return array + */ + public function toSparkPostTransmission() { return $this->model; } } diff --git a/lib/SendGridCompatibility/SendGrid.php b/lib/SendGridCompatibility/SendGrid.php index 1fccda0..a85337a 100644 --- a/lib/SendGridCompatibility/SendGrid.php +++ b/lib/SendGridCompatibility/SendGrid.php @@ -6,8 +6,6 @@ use SparkPost\SendGridCompatibility\Email; use SparkPost\Configuration; class SendGrid{ - private $sparkPost; - public function __construct($username, $password, $options = null) { //username isn't used in our system $opts = array('key'=>$password); @@ -18,7 +16,7 @@ class SendGrid{ } public function send(Email $email) { - Trasmission::send($email->toMsysTransmission()); + Trasmission::send($email->toSparkPostTransmission()); } } ?>
\ No newline at end of file diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php index bc34402..26e5108 100644 --- a/test/unit/SendGridCompatibiility/EmailTest.php +++ b/test/unit/SendGridCompatibiility/EmailTest.php @@ -151,8 +151,8 @@ class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']); } - public function testToMsysTransmission() { - $this->assertInternalType('array', $this->email->toMsysTransmission()); + public function testToSparkPostTransmission() { + $this->assertInternalType('array', $this->email->toSparkPostTransmission()); } } |