From 0c70ab5a22b18a5a2a42f53ed435c6360279e74f Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Wed, 24 Jul 2013 09:10:28 -0700 Subject: [PATCH] Removed folders that re-appeared. --- src/Mailgun/Common/BatchMessage.php | 89 ------ src/Mailgun/Common/Client.php | 118 ------- src/Mailgun/Common/Message.php | 288 ------------------ src/Mailgun/Exceptions/HTTPError.php | 6 - .../Exceptions/NoDomainsConfigured.php | 6 - 5 files changed, 507 deletions(-) delete mode 100644 src/Mailgun/Common/BatchMessage.php delete mode 100644 src/Mailgun/Common/Client.php delete mode 100644 src/Mailgun/Common/Message.php delete mode 100644 src/Mailgun/Exceptions/HTTPError.php delete mode 100644 src/Mailgun/Exceptions/NoDomainsConfigured.php diff --git a/src/Mailgun/Common/BatchMessage.php b/src/Mailgun/Common/BatchMessage.php deleted file mode 100644 index ca5e55e..0000000 --- a/src/Mailgun/Common/BatchMessage.php +++ /dev/null @@ -1,89 +0,0 @@ -client); - $this->batchRecipientAttributes = array(); - $this->client = $client; - $this->debug = $debug; - } - - public function addBatchRecipient($address, $attributes){ - //Check for maximum recipient count - if($this->toRecipientCount == 1000){ - //If autoSend is off, do things here. - if($this->debug == true){ - $this->batchRecipientAttributes = array(); - $this->toRecipientCount = 0; - unset($this->message['to']); - } - else{ - //Send current set and reset recipient parameters - $this->sendBatchMessage(); - $this->batchRecipientAttributes = array(); - $this->toRecipientCount = 0; - unset($this->message['to']); - } - } - if(array_key_exists("first", $attributes)){ - $name = $attributes["first"]; - if(array_key_exists("last", $attributes)){ - $name = $attributes["first"] . " " . $attributes["last"]; - } - } - - $addr = $name . " <" . $address . ">"; - - if(isset($this->message["to"])){ - array_push($this->message["to"], $addr); - } - else{ - $this->message["to"] = array($addr); - } - $attributes["id"] = $this->toRecipientCount; - $this->batchRecipientAttributes["$address"] = $attributes; - $this->toRecipientCount++; - return true; - } - - public function endBatchMessage(){ - if($this->debug == true){ - $this->batchRecipientAttributes = array(); - $this->toRecipientCount = 0; - $this->message = array(); - return true; - } - $this->sendBatchMessage(); - $this->batchRecipientAttributes = array(); - $this->toRecipientCount = 0; - $this->message = array(); - return true; - } - - private function sendBatchMessage(){ - if(array_key_exists("from", $this->message)){ - if($this->toRecipientCount > 0){ - if(array_key_exists("subject", $this->message)){ - if(array_key_exists("text", $this->message) || array_key_exists("html", $this->message)){ - $this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes); - return $this->client->sendMessage($this->message); - } - } - } - } - } -} -?> \ No newline at end of file diff --git a/src/Mailgun/Common/Client.php b/src/Mailgun/Common/Client.php deleted file mode 100644 index cb68bec..0000000 --- a/src/Mailgun/Common/Client.php +++ /dev/null @@ -1,118 +0,0 @@ -apiKey = $apiKey; - $this->domain = $domain; - $this->debug = $debug; - if($this->debug){ - $this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false)); - $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); - $this->client->setDefaultOption('exceptions', false); - $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); - $this->validateCredentials(); - } - else{ - $this->client = new Guzzle('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(); - - if($response->getStatusCode() == 200){ - $jsonResp = $response ->json(); - foreach ($jsonResp as $key => $value){ - $object->$key = $value; - } - if($object->total_count > 0){ - return true; - } - else{ - throw new NoDomainsConfigured("You don't have any domains on your account!"); - return false; - } - } - elseif($response->getStatusCode() == 401){ - //Need to override Guzzle's Error Handling - throw new HTTPError("Your credentials are incorrect."); - } - else{ - throw new HTTPError("An HTTP Error has occurred! Try again."); - return false; - } - } - - public function sendMessage($message){ - // This is the grand daddy function to send the message and flush all data from variables. - if(array_key_exists("from", $message) && - array_key_exists("to", $message) && - array_key_exists("subject", $message) && - (array_key_exists("text", $message) || array_key_exists("html", $message))){ - $domain = $this->domain; - if($this->debug){ - $request = $this->client->post("$domain/messages", array(), $message); - if(isset($message["attachment"])){ - foreach($message["attachment"] as $attachments){ - $request->addPostFile("attachment", $attachments); - } - unset($message["attachment"]); - } - if(isset($message["inline"])){ - foreach($message["inline"] as $inlineAttachments){ - $request->addPostFile("inline", $inlineAttachments); - } - } - $response = $request->send(); - } - else{ - $request = $this->client->post("$domain/messages", array(), $message); - if(isset($message["attachment"])){ - foreach($message["attachment"] as $attachments){ - $request->addPostFile("attachment", $attachments); - } - unset($message["attachment"]); - } - if(isset($message["inline"])){ - foreach($message["inline"] as $inlineAttachments){ - $request->addPostFile("inline", $inlineAttachments); - } - } - $response = $request->send(); - } - return $response; - } - //Throw an exception here! Missing required parameters. - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Common/Message.php b/src/Mailgun/Common/Message.php deleted file mode 100644 index 7adca38..0000000 --- a/src/Mailgun/Common/Message.php +++ /dev/null @@ -1,288 +0,0 @@ -message = array(); - $this->toRecipientCount = 0; - $this->ccRecipientCount = 0; - $this->bccRecipientCount = 0; - $this->attachmentCount = 0; - $this->campaignIdCount = 0; - $this->customOptionCount = 0; - } - - public function addToRecipient($address, $attributes){ - if($this->toRecipientCount < 1000){ - if(is_array($attributes)){ - if(array_key_exists("first", $attributes)){ - $name = $attributes["first"]; - if(array_key_exists("last", $attributes)){ - $name = $attributes["first"] . " " . $attributes["last"]; - } - } - } - if(isset($name)){ - $addr = $name . " <" . $address . ">"; - } - else{ - $addr = $address; - } - if(isset($this->message["to"])){ - array_push($this->message["to"], $addr); - } - else{ - $this->message["to"] = array($addr); - } - $this->toRecipientCount++; - return true; - } - else{ - //DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS - } - } - - public function addCcRecipient($address, $attributes){ - if($this->ccRecipientCount < 1000){ - if(is_array($attributes)){ - if(array_key_exists("first", $attributes)){ - $name = $attributes["first"]; - if(array_key_exists("last", $attributes)){ - $name = $attributes["first"] . " " . $attributes["last"]; - } - } - } - if(isset($name)){ - $addr = $name . " <" . $address . ">"; - } - else{ - $addr = $address; - } - if(isset($this->message["cc"])){ - array_push($this->message["cc"], $addr); - } - else{ - $this->message["cc"] = array($addr); - } - $this->ccRecipientCount++; - return true; - } - else{ - //DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS - } - } - public function addBccRecipient($address, $attributes){ - if($this->bccRecipientCount < 1000){ - if(is_array($attributes)){ - if(array_key_exists("first", $attributes)){ - $name = $attributes["first"]; - if(array_key_exists("last", $attributes)){ - $name = $attributes["first"] . " " . $attributes["last"]; - } - } - } - if(isset($name)){ - $addr = $name . " <" . $address . ">"; - } - else{ - $addr = $address; - } - if(isset($this->message["bcc"])){ - array_push($this->message["bcc"], $addr); - } - else{ - $this->message["bcc"] = array($addr); - } - $this->bccRecipientCount++; - return true; - } - else{ - //DIE HERE WITH EXCEPTION! TOO MANY RECIPIENTS - } - } - public function setFromAddress($address, $attributes){ - if(is_array($attributes)){ - if(array_key_exists("first", $attributes)){ - $name = $attributes["first"]; - if(array_key_exists("last", $attributes)){ - $name = $attributes["first"] . " " . $attributes["last"]; - } - } - } - if(isset($name)){ - $addr = $name . " <" . $address . ">"; - } - else{ - $addr = $address; - } - $this->message['from'] = $addr; - return true; - } - public function setSubject($data = NULL){ - if($data == NULL || $data == ""){ - $data = " "; - } - $this->message['subject'] = $data; - return true; - } - public function addCustomHeader($headerName, $data){ - if(!preg_match("/^h:/i", $headerName)){ - $headerName = "h:" . $headerName; - } - - $this->message[$headerName] = array($data); - return true; - } - - //Content - public function setTextBody($data){ - if($data == NULL || $data == ""){ - $data = " "; - } - $this->message['text'] = $data; - return true; - } - public function setHtmlBody($data){ - if($data == NULL || $data == ""){ - $data = " "; - } - $this->message['html'] = $data; - return true; - } - public function addAttachment($data){ - if(isset($this->message["attachment"])){ - array_push($this->message["attachment"], $data); - } - else{ - $this->message["attachment"] = array($data); - } - return true; - } - public function addInlineImage($data){ - if(isset($this->message['inline'])){ - array_push($this->message['inline'] , $data); - return true; - } - else{ - $this->message['inline'] = array($data); - return true; - } - } - - //Options - public function setTestMode($data){ - if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ - $data = "yes"; - } - else{ - $data = "no"; - } - $this->message['o:testmode'] = $data; - return true; - } - public function addCampaignId($data){ - if($this->campaignIdCount < 3){ - if(isset($this->message['o:campaign'])){ - array_push($this->message['o:campaign'] , $data); - } - else{ - $this->message['o:campaign'] = array($data); - } - $this->campaignIdCount++; - return true; - } - else{ - //THROW AN EXCEPTION HERE!! CANT HAVE MORE THAN 3 CAMPAIGNS - } - } - 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(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ - $data = "yes"; - } - else{ - $data = "no"; - } - $this->message['o:tracking-opens'] = $data; - return true; - } - public function setClickTracking($data){ - if(filter_var($data, FILTER_VALIDATE_BOOLEAN)){ - $data = "yes"; - } - else{ - $data = "no"; - } - $this->message['o:tracking-clicks'] = $data; - return true; - } - public function setDeliveryTime($timeDate, $timeZone = NULL){ - if(isset($timeZone)){ - $timeZoneObj = new \DateTimeZone("$timeZone"); - } - else{ - $timeZoneObj = new \DateTimeZone(\DEFAULT_TIME_ZONE); - } - - $dateTimeObj = new \DateTime($timeDate, $timeZoneObj); - $formattedTimeDate = $dateTimeObj->format(\DateTime::RFC2822); - $this->message['o:deliverytime'] = $formattedTimeDate; - return true; - } - //Handlers for any new features not defined as a concrete function. - public function addCustomData($customName, $data){ - if(is_array($data)){ - $jsonArray = json_encode($data); - $this->message['v:'.$customName] = $jsonArray; - } - else{ - //throw exception here data is not in an array form! - return false; - } - - } - public function addCustomOption($optionName, $data){ - if(!preg_match("/^o:/i", $optionName)){ - $optionName = "o:" . $optionName; - } - 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 getMessage(){ - return $this->message; - } -} -?> \ No newline at end of file diff --git a/src/Mailgun/Exceptions/HTTPError.php b/src/Mailgun/Exceptions/HTTPError.php deleted file mode 100644 index 5c3f890..0000000 --- a/src/Mailgun/Exceptions/HTTPError.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/src/Mailgun/Exceptions/NoDomainsConfigured.php b/src/Mailgun/Exceptions/NoDomainsConfigured.php deleted file mode 100644 index a5d6021..0000000 --- a/src/Mailgun/Exceptions/NoDomainsConfigured.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file