Removed folders that re-appeared.

This commit is contained in:
Travis Swientek 2013-07-24 09:10:28 -07:00
parent 5befeb0f66
commit 0c70ab5a22
5 changed files with 0 additions and 507 deletions

View File

@ -1,89 +0,0 @@
<?PHP
//BatchMessage.php - Extends the Message class and provides continuous recipient addition.
namespace Mailgun\Common;
use Guzzle\Http\Client as Guzzler;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
class BatchMessage extends Message{
private $batchRecipientAttributes;
private $client;
private $autoSend;
public function __construct($client, $debug = false){
parent::__construct($this->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);
}
}
}
}
}
}
?>

View File

@ -1,118 +0,0 @@
<?PHP
namespace Mailgun\Common;
require dirname(__DIR__) . '/globals.php';
use Guzzle\Http\Client as Guzzle;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
class Client{
protected $apiKey;
protected $domain;
protected $client;
protected $debug;
protected $apiEndpoint = API_ENDPOINT;
protected $apiVersion = API_VERSION;
protected $apiUser = API_USER;
protected $sdkVersion = SDK_VERSION;
protected $sdkUserAgent = SDK_USER_AGENT;
public function __construct($apiKey, $domain, $debug = false){
$this->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.
}
}
?>

View File

@ -1,288 +0,0 @@
<?PHP
/*
* Message.php - Message builder for creating a message object. Pass the message object to the client to send the message.
*/
namespace Mailgun\Common;
use Guzzle\Http\Client as Guzzler;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
class Message{
protected $message;
protected $sanitized;
protected $toRecipientCount;
protected $ccRecipientCount;
protected $bccRecipientCount;
protected $attachmentCount;
protected $campaignIdCount;
protected $customOptionCount;
public function __construct(){
$this->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;
}
}
?>

View File

@ -1,6 +0,0 @@
<?php
namespace Mailgun\Exceptions;
class HTTPError extends \Exception{}
?>

View File

@ -1,6 +0,0 @@
<?php
namespace Mailgun\Exceptions;
class NoDomainsConfigured extends \Exception{}
?>