summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Song <vincent.wsong@gmail.com>2016-06-10 11:50:34 -0400
committerVincent Song <vincent.wsong@gmail.com>2016-06-10 11:50:34 -0400
commit2691ddd138dcbfc7eaca768ed92f911c8afd8b82 (patch)
treeca17d5b5df122f6db4405ad7eae8140e750ab912
parent327bd6f33274e7e6d5714467fcd11a24b6747447 (diff)
downloadphp-sparkpost-2691ddd138dcbfc7eaca768ed92f911c8afd8b82.zip
php-sparkpost-2691ddd138dcbfc7eaca768ed92f911c8afd8b82.tar.gz
php-sparkpost-2691ddd138dcbfc7eaca768ed92f911c8afd8b82.tar.bz2
Cleaned up Transmissions.php according to PSR-2, deleted more test code and comments.
-rw-r--r--lib/SparkPost/Transmission.php146
1 files changed, 30 insertions, 116 deletions
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index d7499f2..a356c9b 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -8,27 +8,32 @@ class Transmission extends Resource
{
protected $endpoint = 'transmission';
- public function __constructor(SparkPost $sparkpost){
+ public function __constructor(SparkPost $sparkpost)
+ {
parent::__construct($sparkpost, $endpoint);
}
public function fixBlindCarbonCopy($payload)
{
-
//TODO: Manage recipients. "Vincent Song <vincentsong@sparkpost.com>"
-
+
$modifiedPayload = $payload;
$bccList = &$modifiedPayload['bcc'];
$recipientsList = &$modifiedPayload['recipients'];
-
- if(isset($modifiedPayload['recipients'][0]['name'])) //if a name exists, then do "name" <email>. Otherwise, just do <email>
+
+ //Format: Original Recipient" <original.recipient@example.com>
+ //if a name exists, then do "name" <email>. Otherwise, just do <email>
+ if(isset($modifiedPayload['recipients'][0]['name']))
{
- $originalRecipient = '"'.$modifiedPayload['recipients'][0]['name'].'" &lt;'.$modifiedPayload['recipients'][0]['address'].'&gt;';
+ $originalRecipient = '"' . $modifiedPayload['recipients'][0]['name']
+ . '" &lt;' . $modifiedPayload['recipients'][0]['address'] . '&gt;';
} else {
- $originalRecipient = '&lt;'.$modifiedPayload['recipients'][0]['address'].'&gt;';
- } //Format: Original Recipient" <original.recipient@example.com>
+ $originalRecipient = '&lt;' . $modifiedPayload['recipients'][0]['address']
+ . '&gt;';
+ }
- foreach ($bccList as $bccRecipient) { //loop through all BCC recipients
+ //loop through all BCC recipients
+ foreach ($bccList as $bccRecipient) {
$newRecipient = [
'address' => $bccRecipient['address'],
'header_to' => $originalRecipient,
@@ -36,24 +41,26 @@ class Transmission extends Resource
array_push($recipientsList, $newRecipient);
}
- unset($modifiedPayload['bcc']); //Delete the BCC object/array
+ //Delete the BCC object/array
+ unset($modifiedPayload['bcc']);
return $modifiedPayload;
}
public function fixCarbonCopy($payload)
{
-
$ccCustomHeadersList = "";
$modifiedPayload = $payload;
$ccList = &$modifiedPayload['cc'];
$recipientsList = &$modifiedPayload['recipients'];
- if(isset($modifiedPayload['recipients'][0]['name'])) //if a name exists, then do "name" <email>. Otherwise, just do <email>
- {
- $originalRecipient = '"'.$modifiedPayload['recipients'][0]['name'].'" &lt;'.$modifiedPayload['recipients'][0]['address'].'&gt;';
+ //if a name exists, then do "name" <email>. Otherwise, just do <email>
+ if(isset($modifiedPayload['recipients'][0]['name'])) {
+ $originalRecipient = '"' . $modifiedPayload['recipients'][0]['name']
+ . '" &lt;' . $modifiedPayload['recipients'][0]['address'] . '&gt;';
} else {
- $originalRecipient = '&lt;'.$modifiedPayload['recipients'][0]['address'].'&gt;';
+ $originalRecipient = '&lt;' . $modifiedPayload['recipients'][0]['address']
+ . '&gt;';
}
foreach ($ccList as $ccRecipient) {
@@ -63,9 +70,9 @@ class Transmission extends Resource
];
//if name exists, then use "Name" <Email> format. Otherwise, just email will suffice.
-
- if(isset($ccRecipient['name'])){
- $ccCustomHeadersList = $ccCustomHeadersList . ' "' . $ccRecipient['name'] . '" &lt;' . $ccRecipient['address'] . '&gt;,';
+ if(isset($ccRecipient['name'])) {
+ $ccCustomHeadersList = $ccCustomHeadersList . ' "' . $ccRecipient['name']
+ . '" &lt;' . $ccRecipient['address'] . '&gt;,';
} else {
$ccCustomHeadersList = $ccCustomHeadersList . ' ' . $ccRecipient['address'];
}
@@ -73,10 +80,11 @@ class Transmission extends Resource
array_push($recipientsList, $newRecipient);
}
- $customHeaders = array("CC" => $ccCustomHeadersList); //Creates customHeaders and adds CSV list of CC emails
+ //Creates customHeaders and adds CSV list of CC emails
+ $customHeaders = array("CC" => $ccCustomHeadersList);
$modifiedPayload['customHeaders'] = $customHeaders;
-
- unset($modifiedPayload['cc']); //delete CC
+ //delete CC
+ unset($modifiedPayload['cc']);
return $modifiedPayload;
}
@@ -87,98 +95,4 @@ class Transmission extends Resource
$modifiedPayload = $this->fixCarbonCopy($modifiedPayload); //Accounts for any CCs
parent::post($modifiedPayload);
}
-}
-
-//$testPayload =
-//[
-// 'content' => [
-// 'from' => [
-// 'name' => 'Sparkpost Team',
-// 'email' => 'from@sparkpostbox.com',
-// ],
-// 'subject' => 'First Mailing From PHP',
-// '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!',
-// ],
-// 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
-// 'recipients' => [
-// [
-// 'address' => 'EMAIL_ADDRESS1',
-// 'name' => 'NAME_1'
-// ],
-// ],
-// 'bcc' => [
-// [
-// 'address' => 'BCC_EMAIL_ADDRESS1',
-// 'name' => 'BCC_NAME1'
-// ],
-// [
-// 'address' => 'BCC_EMAIL_ADDRESS2',
-// 'name' => 'BCC_NAME2'
-// ],
-// ],
-// 'cc' => [
-// [
-// 'address' => 'CC_EMAIL_ADDRESS1',
-// 'name' => 'CC_NAME1'
-// ],
-// [
-// 'address' => 'CC_EMAIL_ADDRESS2',
-// 'name' => 'CC_NAME2'
-// ],
-// [
-// 'address' => 'CC_EMAIL_ADDRESS3',
-// ]
-// ]
-//];
-//$transmission = new Transmission();
-//$transmission->post($testPayload);
-
-//$output =
-//[
-// 'content' => [
-// 'from' => [
-// 'name' => 'Sparkpost Team',
-// 'email' => 'from@sparkpostbox.com',
-// ],
-// 'subject' => 'First Mailing From PHP',
-// '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!',
-// ],
-// 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
-// 'recipients' => [
-// [
-// 'address' => 'EMAIL_ADDRESS1',
-// 'name' => 'NAME_1'
-// ],
-// [
-// 'address' => 'BCC_EMAIL_ADDRESS1',
-// 'header_to' => '"NAME_1" <EMAIL_ADDRESS1>'
-// ],
-// [
-// 'address' => 'BCC_EMAIL_ADDRESS2',
-// 'header_to' => '"NAME_1" <EMAIL_ADDRESS1>'
-// ],
-// [
-// 'address' => 'CC_EMAIL_ADDRESS1',
-// 'header_to' => '"NAME_1" <EMAIL_ADDRESS1>'
-// ],
-// [
-// 'address' => 'CC_EMAIL_ADDRESS2',
-// 'header_to' => '"NAME_1" <EMAIL_ADDRESS1>'
-// ],
-// [
-// 'address' => 'CC_EMAIL_ADDRESS3',
-// 'header_to' => '"NAME_1" <EMAIL_ADDRESS1>'
-// ],
-// ],
-// 'customHeaders' => [
-// 'CC' => '"CC_NAME1" <CC_EMAIL_ADDRESS1>, "CC_NAME2" <CC_EMAIL_ADDRESS2>, CC_EMAIL_ADDRESS3'
-// ]
-//];
-
-
-
-
-
-
+} \ No newline at end of file