From 313f154c4c340b1ce6836468c9142cede208bd82 Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Fri, 19 Jul 2013 17:00:07 -0700 Subject: [PATCH] Closing the day --- GitHub_Logo.png | Bin 0 -> 20444 bytes Mailgun/Common/Client.php | 73 ++++------ Mailgun/Common/Messages.php | 271 ++++++++++++++++-------------------- test.php | 34 ++++- 4 files changed, 178 insertions(+), 200 deletions(-) create mode 100644 GitHub_Logo.png diff --git a/GitHub_Logo.png b/GitHub_Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8a23e7ebb5f33a39d951dddd18a627e418abd65e GIT binary patch literal 20444 zcmeHv2UJr{)9_6K3B7|TEp$YBFVeg8-bF|P1X3UgT|^O4u^^y;BBF>OD5z9L5k&+Q z1REeAf+A8B6a`dT{+m$L=Y8IC-v4~(eCK>F-o3N4GrP01vwL%A?n-@0eZ#-aA{HAA z05&%A022TJYybd(0T2*+#sGq=Fc*k`f-nrkp8+rUDjo{LJgYE`hkq5O(QSe-(%UHl zVWCy{G6>84!mA2_0!R>74PI&>%m?0IfERW@1D$sagppvwO!U9qi!1<_EC8(CP0++3 z4ALo-NFkC#i4jOMS1qKReIN=;pdmH`YAUMgdMX-vs#-`8(9qOV*8;#n9YfG^Kt)YW z6>@fEtW+vEzOyTRqQN@YDl7uRD+vz3R^^6+h_$g1K-t#D77fC`jtv4`X>S*ZhpxiS zyeq9)gEtTjtlgIBlOqcLO@2&aHBE`}08!+!>0zMya#3=R;4NuYorEJ%YxR$v7>%?fNxgVA^bsA4Eh z<_I(%O@o_3_&{_N283aDAe3*}LQ!-I zM1=>E&`2{PJ|d712LLN$rf~s0G~FUWC2OhbYH2B|DS_%=Pye!Vo$6l$w7FfO`07lb zGl)R@Pux%5pEzP60O-tux;gd}7jzN;>h=MEVBb%i)L8)FOaXw}&R@nOK(m)n3ME2M zSve*qMhS~SDbW)(trfC9Z+6Tc0Bz-YijA(=JqUyK^!&FBnhqABWNZkM zhBk9?L!zQc(KHxb6SRyG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diff --git a/Mailgun/Common/Client.php b/Mailgun/Common/Client.php index 88a1d90..53994ea 100644 --- a/Mailgun/Common/Client.php +++ b/Mailgun/Common/Client.php @@ -1,4 +1,4 @@ -apiKey = $apiKey; $this->domain = $domain; - $this->client = new Guzzler('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); - $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); - $this->client->setDefaultOption('exceptions', false); - $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); - $this->validateCredentials(); + $this->debug = $debug; + if($this->debug){ + $this->client = new Guzzler('http://postbin.ryanbigg.com/'); + $this->client->setDefaultOption('exceptions', false); + $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); + } + else{ + $this->client = new Guzzler('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); + $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); + $this->client->setDefaultOption('exceptions', false); + $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); + $this->validateCredentials(); + } } public function validateCredentials(){ $url = "domains"; - + $data = null; $request = $this->client->get($url, array(), $data); $response = $request->send(); @@ -59,43 +68,19 @@ class Client{ } } - public function getRequest($options, $data){ + public function sendMessage($message){ + // This is the grand daddy function to send the message and flush all data from variables. + $domain = $this->domain; + if($this->debug){ + $request = $this->client->post("303980cc", array(), $message); + $response = $request->send(); + } + else{ + $request = $this->client->post("$domain/messages", array(), $message); + $response = $request->send(); + } + return $response; - $url = $options['url']; - - $request = $this->client->get($url, array(), $data); - - $response = $request->send(); - - return $response->getBody(); - } - public function postRequest($options, $data){ - - $url = $options['url']; - - $request = $this->client->post($url, array(), $data); - - $response = $request->send(); - - return $response->getBody(); - } - public function putRequest($options, $data){ - $url = $options['url']; - - $request = $this->client->put($url, array(), $data); - - $response = $request->send(); - - return $response->getBody(); - } - public function deleteRequest($options){ - $url = $options['url']; - - $request = $this->client->delete($url); - - $response = $request->send(); - - return $response->getBody(); } } diff --git a/Mailgun/Common/Messages.php b/Mailgun/Common/Messages.php index 79c6edf..968cf3d 100644 --- a/Mailgun/Common/Messages.php +++ b/Mailgun/Common/Messages.php @@ -12,222 +12,193 @@ use Mailgun\Exceptions\HTTPError; class Message{ - private $message = array(); - private $toRecipient = array(); - private $ccRecipient = array(); - private $bccRecipient = array(); - private $fromAddress; - private $subject; - private $customHeader = array(); - private $textBody; - private $htmlBody; - private $attachment = array(); - private $inlineImage = array(); - private $options = array(); - private $customData = array(); - private $customOption = array(); + private $message; + private $sanitized; + private $toRecipientCount; + private $ccRecipientCount; + private $bccRecipientCount; + private $attachmentCount; + private $campaignIdCount; + private $customOptionCount; - - public function __construct($headers = NULL, $content = NULL, $options = NULL){ - + public function __construct($message = null){ + $this->message = array(); + $this->toRecipientCount = 0; + $this->ccRecipientCount = 0; + $this->bccRecipientCount = 0; + $this->attachmentCount = 0; + $this->campaignIdCount = 0; + $this->customOptionCount = 0; } - /* - This section includes all headers that can be programmatically - added to the email. Each attribute is broken down in to a single - function to make it easier and more intuitive for new users. - Dealing with complex arrays on the client side is usually no fun. - Plus most people iterate through an array of data from a database, so - why not just iterate and add each recipient to the "Message" object instead? - */ - - // This function adds a recipient item to the recipient array. If the name is Null, - // the address will be included in the typical name field so it displays nicely. public function addToRecipient($address, $name = NULL){ if($name != NULL){ $addr = $name . " <" . $address . ">"; - array_push($this->toRecipient, $addr); - return true; } else{ $addr = $address . " <" . $address . ">"; - array_push($this->toRecipient, $addr); - return true; } + $arr = "to[".$this->toRecipientCount."]"; + $this->message[$arr] = $addr; + $this->toRecipientCount++; + return true; } public function addCcRecipient($address, $name = NULL){ if($name != NULL){ $addr = $name . " <" . $address . ">"; - array_push($this->ccRecipient, $addr); - return true; } else{ $addr = $address . " <" . $address . ">"; - array_push($this->ccRecipient, $addr); - return true; } + $arr = "cc[".$this->ccRecipientCount."]"; + $this->message[$arr] = $addr; + $this->ccRecipientCount++; + return true; } public function addBccRecipient($address, $name = NULL){ if($name != NULL){ $addr = $name . " <" . $address . ">"; - array_push($this->bccRecipient, $addr); - return true; } else{ $addr = $address . " <" . $address . ">"; - array_push($this->bccRecipient, $addr); - return true; } + $arr = "bcc[".$this->bccRecipientCount."]"; + $this->message[$arr] = $addr; + $this->bccRecipientCount++; + return true; } public function setFromAddress($address, $name = NULL){ if($name != NULL){ - $this->fromAddress = $name . " <" . $address . ">"; - return true; + $addr = $name . " <" . $address . ">"; } else{ - $this->fromAddress = $address . " <" . $address . ">"; - return true; + $addr = $address . " <" . $address . ">"; } + $this->message['from'] = $addr; + return true; } public function setSubject($data = NULL){ - if($data != NULL){ - $this->subject = $data; - return true; - } - else{ - $this->subject = ""; - return false; + if($data == NULL || $data == ""){ + $data = " "; } + $this->message['subject'] = $data; + return true; } - public function addCustomHeader($data){ - //Need to check if "X-Mailgun" exists via Regular Expression. Then either add it or not. - //if(preg_match("\^X-Mailgun", $data)){ - if(true){ - array_push($this->customHeader, $data); - return true; + public function addCustomHeader($headerName, $data){ + if(!preg_match("/^h:/i", $headerName)){ + $headerName = "h:" . $headerName; } - else{ - $header = "X-Mailgun-" . $data; - array_push($this->customHeader, $header); - return true; - } - return; + + $this->addCustomOption($headerName, $data); + return true; } //Content public function setTextBody($data){ - //Not sure what validation we should do here. Just assigning the data for now. - $this->textBody = $data; + if($data == NULL || $data == ""){ + $data = " "; + } + $this->message['text'] = $data; return true; - } - public function setHTMLBody($data){ - //Not sure what validation we should do here. Just assigning the data for now. - $this->htmlBody = $data; + public function setHtmlBody($data){ + if($data == NULL || $data == ""){ + $data = " "; + } + $this->message['html'] = $data; return true; - } public function addAttachment($data){ - $postFields["attachment[$j]"] ="@/path-to-doc/".$mailObj["filenames"][$j]; - + $arr = "attachment[".$this->attachmentCount."]"; + $this->message[$arr] = $data; + $this->attachmentCount++; + return true; } - public function addInlineImage(){} - - //Options - public function setTestMode($data){ - if(is_bool($data)){ - if($data == true){ - array_push($this->options, array("o:testmode" => true)); - } + public function addInlineImage($data){ + if(isset($this->message['inline'])){ + array_push($this->message['inline'] , $data); + return true; } - return; - } - public function setCampaignId($data){ - if(is_array(isset($this->options['o:campaign']))){ - $arrCount = count($this->options['o:campaign']); - if($arrCount <= 3){ - $this->options['o:campaign'] = $data; - } - else{ - return false; - } - } - else { - $this->options['o:campaign'] = $data; + else{ + $this->message['inline'] = array($data); return true; } } - public function setDKIM(){ - if(is_bool($data)){ - if($data == true){ - array_push($this->options, array("o:dkim" => true)); - } - else{ - array_push($this->options, array("o:dkim" => false)); - } + + //Options + public function setTestMode($data){ + if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ + $data = "yes"; } - return; + else{ + $data = "no"; + } + $this->message['o:testmode'] = $data; + return true; + } + public function addCampaignId($data){ + if($this->campaignIdCount < 3){ + $arr = "o:campaign[".$this->campaignIdCount."]"; + $this->message[$arr] = $data; + $this->campaignIdCount++; + return true; + } + } + public function setDkim($data){ + if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ + $data = "yes"; + } + else{ + $data = "no"; + } + $this->message["o:dkim"] = $data; + return true; } public function setOpenTracking($data){ - if(is_bool($data)){ - if($data == true){ - array_push($this->options, array("o:tracking-opens" => true)); - } - else{ - array_push($this->options, array("o:tracking-opens" => false)); - } + if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ + $data = "yes"; } - return; + else{ + $data = "no"; + } + $this->message['o:tracking-opens'] = $data; + return true; } public function setClickTracking($data){ - if(is_bool($data)){ - if($data == true){ - array_push($this->options, array("o:tracking-clicks" => true)); - } - else{ - array_push($this->options, array("o:tracking-clicks" => false)); - } + if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ + $data = "yes"; } - return; + else{ + $data = "no"; + } + $this->message['o:tracking-clicks'] = $data; + return true; + } + + public function setDeliveryTime($data){ + //BLAH } //Handlers for any new features not defined as a concrete function. public function addCustomData(){} - public function addCustomOptions(){} - public function sendMessage(){ - // This is the grand daddy function to send the message and flush all data from variables. - - + public function addCustomOption($optionName, $data){ + if(isset($this->message['options'][$optionName])){ + array_push($this->message['options'][$optionName], $data); + return true; + } + else{ + $this->message['options'][$optionName] = array($data); + return true; + } } - - public function getToRecipients(){ - return $this->toRecipient; - } - - public function getCcRecipients(){ - return $this->ccRecipient; - } - public function getBccRecipients(){ - return $this->bccRecipient; - } - public function getFromAddress(){ - return $this->bccRecipient; - } - public function getSubject(){ - return $this->subject; - } - public function getTextBody(){ - return $this->textBody; - } - public function getHTMLBody(){ - return $this->htmlBody; - } - public function getCampaignId(){ - return $this->options; - } + + public function getMessage(){ + + return $this->message; + } } diff --git a/test.php b/test.php index 90974b9..46eab58 100644 --- a/test.php +++ b/test.php @@ -1,13 +1,16 @@ postRequest(array('url' => 'trstx.com/unsubscribes'), array('address' => 'travis@whatever.com', 'tag' => '*')); echo $client->postRequest(array('url' => 'trstx.com/bounces'), array('address' => 'travis@whatever.com')); echo $client->deleteRequest(array('url' => 'trstx.com/bounces/travis@whatever.com')); -*/ + require('Mailgun/Common/Messages.php'); +$client = new Common\Client("key-6e4jujnt879vqn2gx702wov0kg2hl1a6", "trstx.com", true); +echo $client->sendMessage($email); + $message = new Mailgun\Common\Message(); +$message->addToRecipient("travis@tswientek.com", "travis swientek"); +$message->addCcRecipient("travis@trstx.com", "CC Recipient"); +$message->addBccRecipient("travis@trstx.com", "BCC Recipient"); +$message->setFromAddress("travis@tswientek.com", "From Name"); +$message->setSubject("This is the subject of the message!"); +$message->setTextBody("This is the text body of the message!"); +$message->setHtmlBody("This is the html body of the message!"); +$message->addAttachment("@GitHub_Logo.png"); +$message->setTestMode("yes"); +$message->setDkim("yes"); +$message->setOpenTracking("yes"); +$message->setClickTracking("yes"); +$message->addCustomOption("o:myoption", "true"); +$message->addCampaignId("askldf"); -$message->setCampaignId("My-Super-Awesome-Campaign"); -var_dump($message->getCampaignId()); - - +$email = $message->getMessage(); +var_dump($email); +echo $client->sendMessage($email); +*/ +$client = new Common\Client("key-6e4jujnt879vqn2gx702wov0kg2hl1a6", "trstx.com", false); +echo $client->sendMessage(array("from" => "travis@trstx.com", "to" => "travis@tswientek.com", "subject" => "This is the email subject!", "text" => "Hi from the SDK!")); ?> \ No newline at end of file