summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbeardyman <nornholdj@gmail.com>2015-10-03 11:05:25 -0400
committerbeardyman <nornholdj@gmail.com>2015-10-03 11:05:25 -0400
commitada533a743125008474de854a3f6bcec5c104fbe (patch)
treec640e50d2a4d9cacae7c7964260f18c3af5258a8
parent55d428cb95c10c7b94225760a663f28d50190091 (diff)
downloadphp-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.zip
php-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.tar.gz
php-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.tar.bz2
replaced tabs with two spaces. normalized quotes
-rw-r--r--AUTHORS.md2
-rw-r--r--README.md22
-rw-r--r--composer.json10
-rw-r--r--examples/transmission/get_all_transmissions.php6
-rw-r--r--examples/transmission/get_transmission.php6
-rw-r--r--examples/transmission/rfc822.php22
-rw-r--r--examples/transmission/send_transmission_all_fields.php58
-rw-r--r--examples/transmission/simple_send.php28
-rw-r--r--examples/transmission/stored_recipients_inline_content.php20
-rw-r--r--examples/transmission/stored_template_send.php22
-rw-r--r--examples/unwrapped/create_template.php22
-rw-r--r--lib/SendGridCompatibility/Email.php386
-rw-r--r--lib/SendGridCompatibility/SendGrid.php18
-rw-r--r--lib/SparkPost/APIResource.php268
-rw-r--r--lib/SparkPost/SparkPost.php18
-rw-r--r--lib/SparkPost/Transmission.php176
-rw-r--r--phpunit.xml52
-rw-r--r--test/unit/APIResourceTest.php16
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php310
-rw-r--r--test/unit/SparkPostTest.php12
-rw-r--r--test/unit/TransmissionTest.php8
21 files changed, 741 insertions, 741 deletions
diff --git a/AUTHORS.md b/AUTHORS.md
index 1601056..3e269ef 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -2,6 +2,6 @@ php-sparkpost is maintained by Message Systems.
# Contributors
-* Jordan Nornhold <jordan.norhold@messagesystems.com>
+* Jordan Nornhold <jordan.nornhold@messagesystems.com>, @beardyman
* Rich Leland <rich.leland@messagesystems.com>, @richleland
* Matthew April <matthew.japril@gmail.com>
diff --git a/README.md b/README.md
index 13cf9aa..0be005b 100644
--- a/README.md
+++ b/README.md
@@ -56,21 +56,21 @@ $sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
try {
// Build your email and send it!
$results = $sparky->transmission->send([
- 'from'=>'From Envelope <from@sparkpostbox.com>',
- 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
- 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
+ 'from'=>'From Envelope <from@sparkpostbox.com>',
+ 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
+ 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
'substitutionData'=>['name'=>'YOUR FIRST NAME']
- 'subject'=>'First Mailing From PHP',
- 'recipients'=>[
- [
- 'address'=>[
+ 'subject'=>'First Mailing From PHP',
+ 'recipients'=>[
+ [
+ 'address'=>[
'name'=>'YOUR FULL NAME',
'email'=>'YOUR EMAIL ADDRESS'
]
- ]
- ]
- ]);
- echo 'Woohoo! You just sent your first mailing!';
+ ]
+ ]
+ ]);
+ echo 'Woohoo! You just sent your first mailing!';
} catch (\Exception $err) {
echo 'Whoops! Something went wrong';
var_dump($err);
diff --git a/composer.json b/composer.json
index 7bb7a6e..211fa90 100644
--- a/composer.json
+++ b/composer.json
@@ -22,13 +22,13 @@
"phpunit/phpunit": "4.3.*",
"guzzlehttp/guzzle": "6.*",
"mockery/mockery": "^0.9.4",
- "satooshi/php-coveralls": "dev-master"
+ "satooshi/php-coveralls": "dev-master"
},
"autoload": {
- "psr-4": {
- "SparkPost\\": "lib/SparkPost/",
- "SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/",
+ "psr-4": {
+ "SparkPost\\": "lib/SparkPost/",
+ "SparkPost\\SendGridCompatibility\\": "lib/SendGridCompatibility/",
"SparkPost\\Test\\TestUtils\\": "test/unit/TestUtils/"
- }
+ }
}
}
diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php
index 73eed92..afbe5aa 100644
--- a/examples/transmission/get_all_transmissions.php
+++ b/examples/transmission/get_all_transmissions.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,8 +15,8 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->all();
- echo 'Congrats you can use your SDK!';
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php
index f6af649..0bda953 100644
--- a/examples/transmission/get_transmission.php
+++ b/examples/transmission/get_transmission.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,8 +15,8 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->find('Your Transmission ID');
- echo 'Congrats you can use your SDK!';
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php
index 8221097..1054c57 100644
--- a/examples/transmission/rfc822.php
+++ b/examples/transmission/rfc822.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,17 +15,17 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->send([
- 'recipients'=>[
- [
- 'address'=>[
- 'email'=>'john.doe@example.com'
+ 'recipients'=>[
+ [
+ 'address'=>[
+ 'email'=>'john.doe@example.com'
]
- ]
- ],
- 'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@sparkpostbox.com>\nSubject: Example Email\n\nHello World"
- ]);
- echo 'Congrats you can use your SDK!';
+ ]
+ ],
+ 'rfc822'=>'Content-Type: text/plain\nFrom: From Envelope <from@sparkpostbox.com>\nSubject: Example Email\n\nHello World'
+ ]);
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php
index bbd6f6b..749f0cb 100644
--- a/examples/transmission/send_transmission_all_fields.php
+++ b/examples/transmission/send_transmission_all_fields.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,36 +15,36 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try{
$results = $sparky->transmission->send([
- "campaign"=>"my-campaign",
- "metadata"=>[
- "sample_campaign"=>true,
- "type"=>"these are custom fields"
- ],
- "substitutionData"=>[
- "name"=>"Test Name"
- ],
- "description"=>"my description",
- "replyTo"=>"reply@test.com",
- "customHeaders"=>[
- "X-Custom-Header"=>"Sample Custom Header"
- ],
- "trackOpens"=>false,
- "trackClicks"=>false,
- "from"=>"From Envelope <from@sparkpostbox.com>",
- "html"=>"<p>Hello World! Your name is: {{name}}</p>",
- "text"=>"Hello World!",
- "subject"=>"Example Email: {{name}}",
- "recipients"=>[
- [
- "address"=>[
- "email"=>"john.doe@example.com"
+ 'campaign'=>'my-campaign',
+ 'metadata'=>[
+ 'sample_campaign'=>true,
+ 'type'=>'these are custom fields'
+ ],
+ 'substitutionData'=>[
+ 'name'=>'Test Name'
+ ],
+ 'description'=>'my description',
+ 'replyTo'=>'reply@test.com',
+ 'customHeaders'=>[
+ 'X-Custom-Header'=>'Sample Custom Header'
+ ],
+ 'trackOpens'=>false,
+ 'trackClicks'=>false,
+ 'from'=>'From Envelope <from@sparkpostbox.com>',
+ 'html'=>'<p>Hello World! Your name is: {{name}}</p>',
+ 'text'=>'Hello World!',
+ 'subject'=>'Example Email: {{name}}',
+ 'recipients'=>[
+ [
+ 'address'=>[
+ 'email'=>'john.doe@example.com'
]
- ]
- ]
- ]);
+ ]
+ ]
+ ]);
- echo 'Congrats you can use your SDK!';
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/simple_send.php b/examples/transmission/simple_send.php
index 30b5c4e..5844ecc 100644
--- a/examples/transmission/simple_send.php
+++ b/examples/transmission/simple_send.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,20 +15,20 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->send([
- "from"=>"From Envelope <from@sparkpostbox.com>",
- "html"=>"<p>Hello World!</p>",
- "text"=>"Hello World!",
- "subject"=>"Example Email",
- "recipients"=>[
- [
- "address"=>[
- "email"=>"john.doe@example.com"
+ 'from'=>'From Envelope <from@sparkpostbox.com>',
+ 'html'=>'<p>Hello World!</p>',
+ 'text'=>'Hello World!',
+ 'subject'=>'Example Email',
+ 'recipients'=>[
+ [
+ 'address'=>[
+ 'email'=>'john.doe@example.com'
]
- ]
- ]
- ]);
- echo 'Congrats you can use your SDK!';
+ ]
+ ]
+ ]);
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php
index 8a30d7e..9348f9b 100644
--- a/examples/transmission/stored_recipients_inline_content.php
+++ b/examples/transmission/stored_recipients_inline_content.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -16,16 +16,16 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->send([
- "campaign"=>"my-campaign",
- "from"=>"From Envelope <from@sparkpostbox.com>",
- "html"=>"<p>Hello World! Your name is: {{name}}</p>",
- "text"=>"Hello World!",
- "subject"=>"Example Email: {{name}}",
- "recipientList"=>'Example List'
- ]);
+ 'campaign'=>'my-campaign',
+ 'from'=>'From Envelope <from@sparkpostbox.com>',
+ 'html'=>'<p>Hello World! Your name is: {{name}}</p>',
+ 'text'=>'Hello World!',
+ 'subject'=>'Example Email: {{name}}',
+ 'recipientList'=>'Example List'
+ ]);
- echo 'Congrats you can use your SDK!';
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php
index 5cf1cf3..2e22609 100644
--- a/examples/transmission/stored_template_send.php
+++ b/examples/transmission/stored_template_send.php
@@ -3,7 +3,7 @@ namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,18 +15,18 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
$results = $sparky->transmission->send([
- "from"=>"From Envelope <from@sparkpostbox.com>",
- "recipients"=>[
- [
- "address"=>[
- "email"=>"john.doe@example.com"
+ 'from'=>'From Envelope <from@sparkpostbox.com>',
+ 'recipients'=>[
+ [
+ 'address'=>[
+ 'email'=>'john.doe@example.com'
]
]
- ],
- "template"=>"my-first-email"
- ]);
- echo 'Congrats you can use your SDK!';
+ ],
+ 'template'=>'my-first-email'
+ ]);
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/examples/unwrapped/create_template.php b/examples/unwrapped/create_template.php
index d92b294..a3431d4 100644
--- a/examples/unwrapped/create_template.php
+++ b/examples/unwrapped/create_template.php
@@ -3,7 +3,7 @@ namespace Examples\Unwrapped;
require_once (dirname(__FILE__).'/../bootstrap.php');
//pull in API key config
-$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json");
+$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
@@ -15,20 +15,20 @@ $sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]);
try {
// define the endpoint
- $sparky->setupUnwrapped('templates');
+ $sparky->setupUnwrapped('templates');
- $templateConfig = [
- 'name' => 'Summer Sale!',
+ $templateConfig = [
+ 'name' => 'Summer Sale!',
'id'=>'jordan-test-summer-sale',
- 'content'=> [
+ 'content'=> [
'from' => 'from@sparkpostbox.com',
- 'subject' => 'Summer deals',
- 'html' => '<b>Check out these deals!</b>'
+ 'subject' => 'Summer deals',
+ 'html' => '<b>Check out these deals!</b>'
]
- ];
- $results = $sparky->templates->create($templateConfig);
- echo 'Congrats you can use your SDK!';
+ ];
+ $results = $sparky->templates->create($templateConfig);
+ echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getMessage();
}
?>
diff --git a/lib/SendGridCompatibility/Email.php b/lib/SendGridCompatibility/Email.php
index 5576176..251b7f2 100644
--- a/lib/SendGridCompatibility/Email.php
+++ b/lib/SendGridCompatibility/Email.php
@@ -3,197 +3,197 @@ 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();
- }
-
- if(isset($name)) {
- $address = array('address'=>array('email'=>$address, 'name'=>$name));
- } else {
- $address = array('address'=>array('email'=>$address));
- }
-
- array_push($this->model['recipients'], $address);
- 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
- */
- public function setFrom($address) {
- $this->model['from'] = array('email' => $address);
- return $this;
- }
-
- /**
- * @desc sets the name for the from address
- * @param string $name
- */
- public function setFromName($name) {
- if(!isset($this->model['from'])){
- throw new \Exception('Must set "From" prior to setting "From Name".');
- }
- $this->model['from']['name'] = $name;
- return $this;
- }
-
- /**
- * @desc sets the reply to field
- * @param string $address
- * @return \MessageSystems\SendGridCompatibility\Email
- */
- public function setReplyTo ($address) {
- $this->model['replyTo'] = $address;
- return $this;
- }
-
- /**
- * @desc throws an error because bcc fields are not yet implemented.
- * @throws \Exception
- * @param string $address
- * @return \MessageSystems\SendGridCompatibility\Email
- */
- public function addBcc($address) {
- 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) {
- 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
- */
- public function addAttachment($attachment) {
- throw new \Exception('Adding attachments is not yet supported');
- }
-
- /**
- * @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'])) {
- $this->model['substitutionData'] = array();
- }
- $this->model['substitutionData'][$name] = $values;
-
- 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 $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 $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();
- }
- $this->model['customHeaders'][$name] = $value;
- }
-
- /**
- * @desc converts this object to a configuration for a SparkPost transmission
- * @return array
- */
- public function toSparkPostTransmission() {
- return $this->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();
+ }
+
+ if(isset($name)) {
+ $address = array('address'=>array('email'=>$address, 'name'=>$name));
+ } else {
+ $address = array('address'=>array('email'=>$address));
+ }
+
+ array_push($this->model['recipients'], $address);
+ 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
+ */
+ public function setFrom($address) {
+ $this->model['from'] = array('email' => $address);
+ return $this;
+ }
+
+ /**
+ * @desc sets the name for the from address
+ * @param string $name
+ */
+ public function setFromName($name) {
+ if(!isset($this->model['from'])){
+ throw new \Exception('Must set \'From\' prior to setting \'From Name\'.');
+ }
+ $this->model['from']['name'] = $name;
+ return $this;
+ }
+
+ /**
+ * @desc sets the reply to field
+ * @param string $address
+ * @return \MessageSystems\SendGridCompatibility\Email
+ */
+ public function setReplyTo ($address) {
+ $this->model['replyTo'] = $address;
+ return $this;
+ }
+
+ /**
+ * @desc throws an error because bcc fields are not yet implemented.
+ * @throws \Exception
+ * @param string $address
+ * @return \MessageSystems\SendGridCompatibility\Email
+ */
+ public function addBcc($address) {
+ 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) {
+ 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
+ */
+ public function addAttachment($attachment) {
+ throw new \Exception('Adding attachments is not yet supported');
+ }
+
+ /**
+ * @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'])) {
+ $this->model['substitutionData'] = array();
+ }
+ $this->model['substitutionData'][$name] = $values;
+
+ 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 $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 $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();
+ }
+ $this->model['customHeaders'][$name] = $value;
+ }
+
+ /**
+ * @desc converts this object to a configuration for a SparkPost transmission
+ * @return array
+ */
+ public function toSparkPostTransmission() {
+ return $this->model;
+ }
}
-?> \ No newline at end of file
+?>
diff --git a/lib/SendGridCompatibility/SendGrid.php b/lib/SendGridCompatibility/SendGrid.php
index 25e5d54..7f8697a 100644
--- a/lib/SendGridCompatibility/SendGrid.php
+++ b/lib/SendGridCompatibility/SendGrid.php
@@ -8,17 +8,17 @@ class SendGrid{
private $sparky;
public function __construct($username, $password, $options = null, $httpAdapter) {
- //username isn't used in our system
- $opts = array('key'=>$password);
- if (!is_null($options)) {
- $opts = array_merge($opts, $options);
- }
+ //username isn't used in our system
+ $opts = array('key'=>$password);
+ if (!is_null($options)) {
+ $opts = array_merge($opts, $options);
+ }
$this->sparky = new SparkPost($httpAdapter, $opts);
- }
+ }
- public function send(Email $email) {
- $this->sparky->transmission->send($email->toSparkPostTransmission());
- }
+ public function send(Email $email) {
+ $this->sparky->transmission->send($email->toSparkPostTransmission());
+ }
}
?>
diff --git a/lib/SparkPost/APIResource.php b/lib/SparkPost/APIResource.php
index d500963..3747f6d 100644
--- a/lib/SparkPost/APIResource.php
+++ b/lib/SparkPost/APIResource.php
@@ -9,69 +9,69 @@ use SparkPost\SparkPost;
class APIResource {
/**
- * @desc name of the API endpoint, mainly used for URL construction.
+ * @desc name of the API endpoint, mainly used for URL construction.
* This is public to provide an interface
*
- * @var string
- */
- public $endpoint;
-
- /**
- * @desc Mapping for values passed into the send method to the values needed for the respective API
- * @var array
- */
- protected static $parameterMappings = [];
-
- /**
- * @desc Sets up default structure and default values for the model that is acceptable by the API
- * @var array
- */
- protected static $structure = [];
+ * @var string
+ */
+ public $endpoint;
+
+ /**
+ * @desc Mapping for values passed into the send method to the values needed for the respective API
+ * @var array
+ */
+ protected static $parameterMappings = [];
+
+ /**
+ * @desc Sets up default structure and default values for the model that is acceptable by the API
+ * @var array
+ */
+ protected static $structure = [];
/**
* @desc SparkPost reference for httpAdapters and configs
*/
protected $sparkpost;
- /**
- * @desc Initializes config and httpAdapter for use later.
+ /**
+ * @desc Initializes config and httpAdapter for use later.
* @param $sparkpost SparkPost\SparkPost provides api configuration information
- */
- public function __construct(SparkPost $sparkpost) {
+ */
+ public function __construct(SparkPost $sparkpost) {
$this->sparkpost = $sparkpost;
}
- /**
- * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter
+ /**
+ * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter
*
* @param array $model (pass by reference) the set of values to map
* @param string $mapKey a dot syntax path determining which value to set
* @param mixed $value value for the given path
- */
- protected function setMappedValue (&$model, $mapKey, $value) {
- //get mapping
- if( empty(static::$parameterMappings) ) {
- // if parameterMappings is empty we can assume that no wrapper is defined
- // for the current endpoint and we will use the mapKey to define the mappings directly
- $mapPath = $mapKey;
- }elseif(array_key_exists($mapKey, static::$parameterMappings)) {
- // use only defined parameter mappings to construct $model
- $mapPath = static::$parameterMappings[$mapKey];
- } else {
- return;
- }
-
- $path = explode('.', $mapPath);
- $temp = &$model;
- foreach( $path as $key ) {
- if( !isset($temp[$key]) ){
- $temp[$key] = null;
- }
- $temp = &$temp[$key];
- }
- $temp = $value;
-
- }
+ */
+ protected function setMappedValue (&$model, $mapKey, $value) {
+ //get mapping
+ if( empty(static::$parameterMappings) ) {
+ // if parameterMappings is empty we can assume that no wrapper is defined
+ // for the current endpoint and we will use the mapKey to define the mappings directly
+ $mapPath = $mapKey;
+ }elseif(array_key_exists($mapKey, static::$parameterMappings)) {
+ // use only defined parameter mappings to construct $model
+ $mapPath = static::$parameterMappings[$mapKey];
+ } else {
+ return;
+ }
+
+ $path = explode('.', $mapPath);
+ $temp = &$model;
+ foreach( $path as $key ) {
+ if( !isset($temp[$key]) ){
+ $temp[$key] = null;
+ }
+ $temp = &$temp[$key];
+ }
+ $temp = $value;
+
+ }
/**
* @desc maps values from the passed in model to those needed for the request
@@ -79,52 +79,52 @@ class APIResource {
* @param $model the set of defaults
* @return array A model ready for the body of a request
*/
- protected function buildRequestModel(Array $requestConfig, Array $model=[] ) {
- foreach($requestConfig as $key => $value) {
- $this->setMappedValue($model, $key, $value);
- }
- return $model;
- }
-
- /**
- * @desc posts to the api with a supplied body
+ protected function buildRequestModel(Array $requestConfig, Array $model=[] ) {
+ foreach($requestConfig as $key => $value) {
+ $this->setMappedValue($model, $key, $value);
+ }
+ return $model;
+ }
+
+ /**
+ * @desc posts to the api with a supplied body
* @param body post body for the request
* @return array Result of the request
- */
- public function create(Array $body=[]) {
- return $this->callResource( 'post', null, ['body'=>$body]);
- }
+ */
+ public function create(Array $body=[]) {
+ return $this->callResource( 'post', null, ['body'=>$body]);
+ }
/**
* @desc Makes a put request to the api with a supplied body
* @param body Put body for the request
* @return array Result of the request
- */
- public function update( $resourcePath, Array $body=[]) {
- return $this->callResource( 'put', $resourcePath, ['body'=>$body]);
- }
-
- /**
- * @desc Wrapper method for issuing GET request to current API endpoint
- *
- * @param string $resourcePath (optional) string resource path of specific resource
- * @param array $options (optional) query string parameters
- * @return array Result of the request
- */
- public function get( $resourcePath=null, Array $query=[] ) {
- return $this->callResource( 'get', $resourcePath, ['query'=>$query] );
- }
-
- /**
- * @desc Wrapper method for issuing DELETE request to current API endpoint
- *
- * @param string $resourcePath (optional) string resource path of specific resource
- * @param array $options (optional) query string parameters
- * @return array Result of the request
- */
- public function delete( $resourcePath=null, Array $query=[] ) {
- return $this->callResource( 'delete', $resourcePath, ['query'=>$query] );
- }
+ */
+ public function update( $resourcePath, Array $body=[]) {
+ return $this->callResource( 'put', $resourcePath, ['body'=>$body]);
+ }
+
+ /**
+ * @desc Wrapper method for issuing GET request to current API endpoint
+ *
+ * @param string $resourcePath (optional) string resource path of specific resource
+ * @param array $options (optional) query string parameters
+ * @return array Result of the request
+ */
+ public function get( $resourcePath=null, Array $query=[] ) {
+ return $this->callResource( 'get', $resourcePath, ['query'=>$query] );
+ }
+
+ /**
+ * @desc Wrapper method for issuing DELETE request to current API endpoint
+ *
+ * @param string $resourcePath (optional) string resource path of specific resource
+ * @param array $options (optional) query string parameters
+ * @return array Result of the request
+ */
+ public function delete( $resourcePath=null, Array $query=[] ) {
+ return $this->callResource( 'delete', $resourcePath, ['query'=>$query] );
+ }
/**
@@ -156,59 +156,59 @@ class APIResource {
private function buildBody($options) {
$body = null;
if( !empty($options['body']) ) {
- $model = static::$structure;
- $requestModel = $this->buildRequestModel( $options['body'], $model );
- $body = json_encode($requestModel);
- }
+ $model = static::$structure;
+ $requestModel = $this->buildRequestModel( $options['body'], $model );
+ $body = json_encode($requestModel);
+ }
return $body;
}
- /**
- * @desc Private Method for issuing GET and DELETE request to current API endpoint
- *
- * This method is responsible for getting the collection _and_
- * a specific entity from the API endpoint
- *
- * If resourcePath parameter is omitted, then we fetch the collection
- *
- * @param string $action HTTP method type
- * @param string $resourcePath (optional) string resource path of specific resource
- * @param array $options (optional) query string parameters
- * @return array Result set of action performed on resource
- */
- private function callResource( $action, $resourcePath=null, $options=[] ) {
- $action = strtoupper($action); // normalize
-
- if( !in_array($action, ['POST', 'PUT', 'GET', 'DELETE'])) {
- throw new \Exception('Invalid resource action');
- }
-
- $url = $this->buildUrl($resourcePath, $options);
- $body = $this->buildBody($options);
-
- //make request
- try {
- $response = $this->sparkpost->httpAdapter->send($url, $action, $this->sparkpost->getHttpHeaders(), $body);
- return json_decode($response->getBody()->getContents(), true);
- }
- /*
- * Handles 4XX responses
+ /**
+ * @desc Private Method for issuing GET and DELETE request to current API endpoint
+ *
+ * This method is responsible for getting the collection _and_
+ * a specific entity from the API endpoint
+ *
+ * If resourcePath parameter is omitted, then we fetch the collection
+ *
+ * @param string $action HTTP method type
+ * @param string $resourcePath (optional) string resource path of specific resource
+ * @param array $options (optional) query string parameters
+ * @return array Result set of action performed on resource
+ */
+ private function callResource( $action, $resourcePath=null, $options=[] ) {
+ $action = strtoupper($action); // normalize
+
+ if( !in_array($action, ['POST', 'PUT', 'GET', 'DELETE'])) {
+ throw new \Exception('Invalid resource action');
+ }
+
+ $url = $this->buildUrl($resourcePath, $options);
+ $body = $this->buildBody($options);
+
+ //make request
+ try {
+ $response = $this->sparkpost->httpAdapter->send($url, $action, $this->sparkpost->getHttpHeaders(), $body);
+ return json_decode($response->getBody()->getContents(), true);
+ }
+ /*
+ * Handles 4XX responses
*/
catch (HttpAdapterException $exception) {
- $response = $exception->getResponse();
- $statusCode = $response->getStatusCode();
- if($statusCode === 404) {
- throw new \Exception("The specified resource does not exist", 404);
- }
- throw new \Exception("Received bad response from ".ucfirst($this->endpoint)." API: ". $statusCode );
- }
- /*
- * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
- */
- catch (\Exception $exception) {
- throw new \Exception("Unable to contact ".ucfirst($this->endpoint)." API: ". $exception->getMessage());
- }
- }
+ $response = $exception->getResponse();
+ $statusCode = $response->getStatusCode();
+ if($statusCode === 404) {
+ throw new \Exception('The specified resource does not exist', 404);
+ }
+ throw new \Exception('Received bad response from '.ucfirst($this->endpoint).' API: '. $statusCode );
+ }
+ /*
+ * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
+ */
+ catch (\Exception $exception) {
+ throw new \Exception('Unable to contact '.ucfirst($this->endpoint).' API: '. $exception->getMessage());
+ }
+ }
}
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index d9dc3c8..b3cef5e 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -21,13 +21,13 @@ class SparkPost {
* @desc Default config values. Passed in values will override these.
*/
private static $apiDefaults = [
- 'host'=>'api.sparkpost.com',
- 'protocol'=>'https',
- 'port'=>443,
- 'strictSSL'=>true,
- 'key'=>'',
- 'version'=>'v1'
- ];
+ 'host'=>'api.sparkpost.com',
+ 'protocol'=>'https',
+ 'port'=>443,
+ 'strictSSL'=>true,
+ 'key'=>'',
+ 'version'=>'v1'
+ ];
/**
* @desc sets up httpAdapter and config
@@ -37,7 +37,7 @@ class SparkPost {
* @param Ivory\HttpAdapter $httpAdapter - An adapter for making http requests
* @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost
*/
- public function __construct($httpAdapter, $settingsConfig) {
+ public function __construct($httpAdapter, $settingsConfig) {
//config needs to be setup before adapter because of default adapter settings
$this->setConfig($settingsConfig);
$this->setHttpAdapter($httpAdapter);
@@ -85,7 +85,7 @@ class SparkPost {
*/
private function getHttpConfig($config) {
// get composer.json to extract version number
- $composerFile = file_get_contents(dirname(__FILE__) . "/../../composer.json");
+ $composerFile = file_get_contents(dirname(__FILE__) . '/../../composer.json');
$composer = json_decode($composerFile, true);
// create Configuration for http adapter
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index f811cdf..613ec12 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -10,99 +10,99 @@ class Transmission extends APIResource {
public $endpoint = 'transmissions';
- /**
- * @desc Mapping for values passed into the send method to the values needed for the Transmission API
- * @var array
- */
- protected static $parameterMappings = [
- 'campaign'=>'campaign_id',
- 'metadata'=>'metadata',
- 'substitutionData'=>'substitution_data',
- 'description'=>'description',
- 'returnPath'=>'return_path',
- 'replyTo'=>'content.reply_to',
- 'subject'=>'content.subject',
- 'from'=>'content.from',
- 'html'=>'content.html',
- 'text'=>'content.text',
- 'rfc822'=>'content.email_rfc822',
- 'customHeaders'=>'content.headers',
- 'recipients'=>'recipients',
- 'recipientList'=>'recipients.list_id',
- 'template'=>'content.template_id',
- 'trackOpens'=>'options.open_tracking',
- 'trackClicks'=>'options.click_tracking',
- 'useDraftTemplate'=>'use_draft_template'
- ];
+ /**
+ * @desc Mapping for values passed into the send method to the values needed for the Transmission API
+ * @var array
+ */
+ protected static $parameterMappings = [
+ 'campaign'=>'campaign_id',
+ 'metadata'=>'metadata',
+ 'substitutionData'=>'substitution_data',
+ 'description'=>'description',
+ 'returnPath'=>'return_path',
+ 'replyTo'=>'content.reply_to',
+ 'subject'=>'content.subject',
+ 'from'=>'content.from',
+ 'html'=>'content.html',
+ 'text'=>'content.text',
+ 'rfc822'=>'content.email_rfc822',
+ 'customHeaders'=>'content.headers',
+ 'recipients'=>'recipients',
+ 'recipientList'=>'recipients.list_id',
+ 'template'=>'content.template_id',
+ 'trackOpens'=>'options.open_tracking',
+ 'trackClicks'=>'options.click_tracking',
+ 'useDraftTemplate'=>'use_draft_template'
+ ];
- /**
- * @desc Sets up default structure and default values for the model that is acceptable by the API
- * @var array
- */
- protected static $structure = [
- 'return_path'=>"default@sparkpostmail.com",
- 'content'=>[
- 'html'=>null,
- 'text'=>null,
- 'email_rfc822'=>null
- ],
- 'use_draft_template'=>false
- ];
+ /**
+ * @desc Sets up default structure and default values for the model that is acceptable by the API
+ * @var array
+ */
+ protected static $structure = [
+ 'return_path'=>'default@sparkpostmail.com',
+ 'content'=>[
+ 'html'=>null,
+ 'text'=>null,
+ 'email_rfc822'=>null
+ ],
+ 'use_draft_template'=>false
+ ];
- /**
- * @desc Method for issuing POST request to the Transmissions API
- *
- * This method assumes that all the appropriate fields have
- * been populated by the user through configuration. Acceptable
- * configuration values are:
- * 'campaign': string,
- * 'metadata': array,
- * 'substitutionData': array,
- * 'description': string,
- * 'replyTo': string,
- * 'subject': string,
- * 'from': string,
- * 'html': string,
- * 'text': string,
- * 'rfc822': string,
- * 'customHeaders': array,
- * 'recipients': array,
- * 'recipientList': string,
- * 'template': string,
- * 'trackOpens': boolean,
- * 'trackClicks': boolean,
- * 'useDraftTemplate': boolean
- *
- * @return array API repsonse represented as key-value pairs
- */
- public function send( $transmissionConfig ) {
- return $this->create( $transmissionConfig );
- }
+ /**
+ * @desc Method for issuing POST request to the Transmissions API
+ *
+ * This method assumes that all the appropriate fields have
+ * been populated by the user through configuration. Acceptable
+ * configuration values are:
+ * 'campaign': string,
+ * 'metadata': array,
+ * 'substitutionData': array,
+ * 'description': string,
+ * 'replyTo': string,
+ * 'subject': string,
+ * 'from': string,
+ * 'html': string,
+ * 'text': string,
+ * 'rfc822': string,
+ * 'customHeaders': array,
+ * 'recipients': array,
+ * 'recipientList': string,
+ * 'template': string,
+ * 'trackOpens': boolean,
+ * 'trackClicks': boolean,
+ * 'useDraftTemplate': boolean
+ *
+ * @return array API repsonse represented as key-value pairs
+ */
+ public function send( $transmissionConfig ) {
+ return $this->create( $transmissionConfig );
+ }
- /**
- * @desc Method for retrieving information about all transmissions
- * Wrapper method for a cleaner interface
- *
- * @return array result Set of transmissions
- */
- public function all( $campaignID=null, $templateID=null ) {
- $options = [];
- if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID;
- if( $templateID !== NULL ) $options['template_id'] = $templateID;
+ /**
+ * @desc Method for retrieving information about all transmissions
+ * Wrapper method for a cleaner interface
+ *
+ * @return array result Set of transmissions
+ */
+ public function all( $campaignID=null, $templateID=null ) {
+ $options = [];
+ if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID;
+ if( $templateID !== NULL ) $options['template_id'] = $templateID;
- return $this->get( null, $options );
- }
+ return $this->get( null, $options );
+ }
- /**
- * @desc Method for retrieving information about a single transmission
- * Wrapper method for a cleaner interface
- *
- * @param string $transmissionID Identifier of the transmission to be found
- * @return array result Single transmission represented in key-value pairs
- */
- public function find($transmissionID) {
- return $this->get($transmissionID);
- }
+ /**
+ * @desc Method for retrieving information about a single transmission
+ * Wrapper method for a cleaner interface
+ *
+ * @param string $transmissionID Identifier of the transmission to be found
+ * @return array result Single transmission represented in key-value pairs
+ */
+ public function find($transmissionID) {
+ return $this->get($transmissionID);
+ }
}
?>
diff --git a/phpunit.xml b/phpunit.xml
index 3ca0cc3..e0d0cbf 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,33 +1,33 @@
<phpunit
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
- backupGlobals="true"
- backupStaticAttributes="false"
- bootstrap="test/unit/bootstrap.php"
- cacheTokens="false"
- colors="always"
- convertErrorsToExceptions="true"
- convertNoticesToExceptions="true"
- convertWarningsToExceptions="true"
- forceCoversAnnotation="false"
- mapTestClassNameToCoveredClassName="false"
- printerClass="PHPUnit_TextUI_ResultPrinter"
- processIsolation="false"
- stopOnError="false"
- stopOnFailure="false"
- stopOnIncomplete="false"
- stopOnSkipped="false"
- stopOnRisky="false"
- testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
- timeoutForSmallTests="1"
- timeoutForMediumTests="10"
- timeoutForLargeTests="60"
- verbose="false">
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xsi:noNamespaceSchemaLocation='http://schema.phpunit.de/4.5/phpunit.xsd'
+ backupGlobals='true'
+ backupStaticAttributes='false'
+ bootstrap='test/unit/bootstrap.php'
+ cacheTokens='false'
+ colors='always'
+ convertErrorsToExceptions='true'
+ convertNoticesToExceptions='true'
+ convertWarningsToExceptions='true'
+ forceCoversAnnotation='false'
+ mapTestClassNameToCoveredClassName='false'
+ printerClass='PHPUnit_TextUI_ResultPrinter'
+ processIsolation='false'
+ stopOnError='false'
+ stopOnFailure='false'
+ stopOnIncomplete='false'
+ stopOnSkipped='false'
+ stopOnRisky='false'
+ testSuiteLoaderClass='PHPUnit_Runner_StandardTestSuiteLoader'
+ timeoutForSmallTests='1'
+ timeoutForMediumTests='10'
+ timeoutForLargeTests='60'
+ verbose='false'>
<logging>
- <log type="coverage-html" target="test/output/report"/>
- <log type="coverage-clover" target="test/output/clover.xml"/>
+ <log type='coverage-html' target='test/output/report'/>
+ <log type='coverage-clover' target='test/output/clover.xml'/>
</logging>
<filter>
<blacklist>
diff --git a/test/unit/APIResourceTest.php b/test/unit/APIResourceTest.php
index b64093d..8253b1e 100644
--- a/test/unit/APIResourceTest.php
+++ b/test/unit/APIResourceTest.php
@@ -19,11 +19,11 @@ class APIResourceTest extends \PHPUnit_Framework_TestCase {
}
/**
- * (non-PHPdoc)
- * @before
- * @see PHPUnit_Framework_TestCase::setUp()
- */
- public function setUp() {
+ * (non-PHPdoc)
+ * @before
+ * @see PHPUnit_Framework_TestCase::setUp()
+ */
+ public function setUp() {
$this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function($mock) {
$mock->shouldReceive('getHttpHeaders')->andReturn([]);
});
@@ -45,7 +45,7 @@ class APIResourceTest extends \PHPUnit_Framework_TestCase {
public function testCreate() {
$testInput = ['test'=>'body'];
- $testBody = ["results"=>["my"=>"test"]];
+ $testBody = ['results'=>['my'=>'test']];
$responseMock = Mockery::mock();
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
@@ -59,7 +59,7 @@ class APIResourceTest extends \PHPUnit_Framework_TestCase {
public function testUpdate() {
$testInput = ['test'=>'body'];
- $testBody = ["results"=>["my"=>"test"]];
+ $testBody = ['results'=>['my'=>'test']];
$responseMock = Mockery::mock();
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
@@ -71,7 +71,7 @@ class APIResourceTest extends \PHPUnit_Framework_TestCase {
}
public function testGet() {
- $testBody = ["results"=>["my"=>"test"]];
+ $testBody = ['results'=>['my'=>'test']];
$responseMock = Mockery::mock();
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
index 1c7311d..2b86d7a 100644
--- a/test/unit/SendGridCompatibiility/EmailTest.php
+++ b/test/unit/SendGridCompatibiility/EmailTest.php
@@ -2,160 +2,160 @@
use SparkPost\SendGridCompatibility\Email;
class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
-
- private $email;
-
- public function setup() {
- $this->email = new Email();
- }
-
- public function testConstruct() {
- $email = new Email();
-
- $this->assertInstanceOf('SparkPost\SendGridCompatibility\Email', $email);
- $this->assertInternalType('array', $email->model);
- }
-
- public function testAddTo() {
- $fakeEmail = 'joe.schmoe@test.com';
- $this->email->addTo($fakeEmail);
-
- $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail))), $this->email->model['recipients']);
- }
-
- public function testAddToWithName() {
- $fakeEmail = 'joe.schmoe@test.com';
- $fakeName = 'Joe Schmoe';
- $this->email->addTo($fakeEmail, $fakeName);
-
- $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail, 'name'=>$fakeName))), $this->email->model['recipients']);
- }
-
- public function testSetTos() {
- $tos = array();
- array_push($tos, array('address'=>array('email'=>'joe.schmoe@test.com', 'name'=>'Joe Schmoe')));
- array_push($tos, array('address'=>array('email'=>'jill.schmoe@test.com', 'name'=>'Jill Schmoe')));
- $this->email->setTos($tos);
-
- $this->assertEquals($tos, $this->email->model['recipients']);
- }
-
- public function testSetFrom() {
- $this->email->setFrom('test@email.com');
-
- $this->assertEquals(array('email'=>'test@email.com'), $this->email->model['from']);
- }
-
-
- public function testSetFromName() {
- $this->email->setFrom('test@email.com');
- $this->email->setFromName('Test Bot');
-
- $this->assertEquals(array('email'=>'test@email.com', 'name'=>'Test Bot'), $this->email->model['from']);
- }
-
- /**
- * @desc Tests that setting the fromName prior to setting the From field throws an exception
- * @expectedException Exception
- * @expectedExceptionMessage Must set "From" prior to setting "From Name".
- */
- public function testSetFromNameWithoutAddress() {
- $this->email->setFromName('Test Bot');
- }
-
- public function testSetReplyto() {
- $this->email->setReplyTo('test@email.com');
-
- $this->assertEquals('test@email.com', $this->email->model['replyTo']);
- }
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Adding bcc recipients is not yet supported, try adding them as a "to" address
- */
- public function testAddBcc() {
- $this->email->addBcc('test@email.com');
- }
-
- public function testSetSubject() {
- $this->email->setSubject('Awesome Subject');
-
- $this->assertEquals('Awesome Subject', $this->email->model['subject']);
- }
-
- public function testSetText() {
- $value = 'This is some plain/text';
- $this->email->setText($value);
-
- $this->assertEquals($value, $this->email->model['text']);
- }
-
- public function testSetHtml() {
- $value = '<html><body><p>This is some html</p></body></html>';
- $this->email->setHtml($value);
-
- $this->assertEquals($value, $this->email->model['html']);
- }
-
- /**
- * @desc test that adding a category throws an exception since we don't support tags at transmission level yet
- * @expectedException Exception
- * @expectedExceptionMessage Adding categories is not yet supported
- */
- public function testAddCategory() {
- $this->email->addCategory('');
- }
-
- /**
- * @desc Tests that setting an attachment throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Adding attachments is not yet supported
- */
- public function testAddAttachment() {
- $this->email->addAttachment('blah');
- }
-
- public function testAddSubstitution() {
- $this->email->addSubstitution('item', 'baseball bat');
-
- $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
- }
-
- public function testAddSection() {
- $this->email->addSection('item', 'baseball bat');
-
- $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
- }
-
- /**
- * @desc Tests that setting an attachment throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Adding Unique Arguments is not yet supported
- */
- public function testAddUniqueArguement() {
- $this->email->addUniqueArg('blah', 'someblah');
- }
-
-
- /**
- * @desc Tests that setting an unique argument throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Setting Unique Arguments is not yet supported
- */
- public function testSetUniqueArgs() {
- $this->email->setUniqueArgs(array('blah', 'andBlah'));
- }
-
-
- public function testAddHeader() {
- $value = 'My Header';
- $this->email->addHeader('X-header', $value);
-
- $this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']);
- }
-
- public function testToSparkPostTransmission() {
- $this->assertInternalType('array', $this->email->toSparkPostTransmission());
- }
+
+ private $email;
+
+ public function setup() {
+ $this->email = new Email();
+ }
+
+ public function testConstruct() {
+ $email = new Email();
+
+ $this->assertInstanceOf('SparkPost\SendGridCompatibility\Email', $email);
+ $this->assertInternalType('array', $email->model);
+ }
+
+ public function testAddTo() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $this->email->addTo($fakeEmail);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail))), $this->email->model['recipients']);
+ }
+
+ public function testAddToWithName() {
+ $fakeEmail = 'joe.schmoe@test.com';
+ $fakeName = 'Joe Schmoe';
+ $this->email->addTo($fakeEmail, $fakeName);
+
+ $this->assertEquals(array(array('address'=>array('email'=>$fakeEmail, 'name'=>$fakeName))), $this->email->model['recipients']);
+ }
+
+ public function testSetTos() {
+ $tos = array();
+ array_push($tos, array('address'=>array('email'=>'joe.schmoe@test.com', 'name'=>'Joe Schmoe')));
+ array_push($tos, array('address'=>array('email'=>'jill.schmoe@test.com', 'name'=>'Jill Schmoe')));
+ $this->email->setTos($tos);
+
+ $this->assertEquals($tos, $this->email->model['recipients']);
+ }
+
+ public function testSetFrom() {
+ $this->email->setFrom('test@email.com');
+
+ $this->assertEquals(array('email'=>'test@email.com'), $this->email->model['from']);
+ }
+
+
+ public function testSetFromName() {
+ $this->email->setFrom('test@email.com');
+ $this->email->setFromName('Test Bot');
+
+ $this->assertEquals(array('email'=>'test@email.com', 'name'=>'Test Bot'), $this->email->model['from']);
+ }
+
+ /**
+ * @desc Tests that setting the fromName prior to setting the From field throws an exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Must set 'From' prior to setting 'From Name'.
+ */
+ public function testSetFromNameWithoutAddress() {
+ $this->email->setFromName('Test Bot');
+ }
+
+ public function testSetReplyto() {
+ $this->email->setReplyTo('test@email.com');
+
+ $this->assertEquals('test@email.com', $this->email->model['replyTo']);
+ }
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding bcc recipients is not yet supported, try adding them as a 'to' address
+ */
+ public function testAddBcc() {
+ $this->email->addBcc('test@email.com');
+ }
+
+ public function testSetSubject() {
+ $this->email->setSubject('Awesome Subject');
+
+ $this->assertEquals('Awesome Subject', $this->email->model['subject']);
+ }
+
+ public function testSetText() {
+ $value = 'This is some plain/text';
+ $this->email->setText($value);
+
+ $this->assertEquals($value, $this->email->model['text']);
+ }
+
+ public function testSetHtml() {
+ $value = '<html><body><p>This is some html</p></body></html>';
+ $this->email->setHtml($value);
+
+ $this->assertEquals($value, $this->email->model['html']);
+ }
+
+ /**
+ * @desc test that adding a category throws an exception since we don't support tags at transmission level yet
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding categories is not yet supported
+ */
+ public function testAddCategory() {
+ $this->email->addCategory('');
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding attachments is not yet supported
+ */
+ public function testAddAttachment() {
+ $this->email->addAttachment('blah');
+ }
+
+ public function testAddSubstitution() {
+ $this->email->addSubstitution('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ public function testAddSection() {
+ $this->email->addSection('item', 'baseball bat');
+
+ $this->assertEquals(array('item'=>'baseball bat'), $this->email->model['substitutionData']);
+ }
+
+ /**
+ * @desc Tests that setting an attachment throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding Unique Arguments is not yet supported
+ */
+ public function testAddUniqueArguement() {
+ $this->email->addUniqueArg('blah', 'someblah');
+ }
+
+
+ /**
+ * @desc Tests that setting an unique argument throws a meaningful exception
+ * @expectedException Exception
+ * @expectedExceptionMessage Setting Unique Arguments is not yet supported
+ */
+ public function testSetUniqueArgs() {
+ $this->email->setUniqueArgs(array('blah', 'andBlah'));
+ }
+
+
+ public function testAddHeader() {
+ $value = 'My Header';
+ $this->email->addHeader('X-header', $value);
+
+ $this->assertEquals(array('X-header'=>$value), $this->email->model['customHeaders']);
+ }
+
+ public function testToSparkPostTransmission() {
+ $this->assertInternalType('array', $this->email->toSparkPostTransmission());
+ }
}
-?> \ No newline at end of file
+?>
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index cd45c5a..d4b1129 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -34,14 +34,14 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @desc Ensures that the configuration class is not instantiable.
- */
- public function testConstructorSetsUpTransmissions() {
- $sparky = new SparkPost(new CurlHttpAdapter(), ['key'=>'a key']);
- $this->assertEquals('SparkPost\Transmission', get_class($sparky->transmission));
+ * @desc Ensures that the configuration class is not instantiable.
+ */
+ public function testConstructorSetsUpTransmissions() {
+ $sparky = new SparkPost(new CurlHttpAdapter(), ['key'=>'a key']);
+ $this->assertEquals('SparkPost\Transmission', get_class($sparky->transmission));
$adapter = self::$utils->getProperty($this->resource, 'httpAdapter');
$this->assertRegExp('/php-sparkpost.*/', $adapter->getConfiguration()->getUserAgent());
- }
+ }
/**
* @expectedException Exception
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index f09db7d..d262ee0 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -31,7 +31,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
public function testSend() {
$responseMock = Mockery::mock();
$body = ['text'=>'awesomesauce', 'content'=>['subject'=>'awesomeness']];
- $responseBody = ["results"=>"yay"];
+ $responseBody = ['results'=>'yay'];
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
@@ -45,7 +45,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
public function testAllWithFilter() {
$responseMock = Mockery::mock();
- $responseBody = ["results"=>"yay"];
+ $responseBody = ['results'=>'yay'];
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
with('/.*transmissions.*?campaign_id=campaign&template_id=template/', 'GET', Mockery::type('array'), null)->
@@ -58,7 +58,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
public function testAllWithOutFilter() {
$responseMock = Mockery::mock();
- $responseBody = ["results"=>"yay"];
+ $responseBody = ['results'=>'yay'];
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
with('/.*\/transmissions/', 'GET', Mockery::type('array'), null)->
@@ -71,7 +71,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
public function testFind() {
$responseMock = Mockery::mock();
- $responseBody = ["results"=>"yay"];
+ $responseBody = ['results'=>'yay'];
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
with('/.*\/transmissions.*\/test/', 'GET', Mockery::type('array'), null)->