From b4b9f0ec4018db76670e0beceff9e1021880d58c Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Wed, 24 Jul 2013 23:56:18 -0700 Subject: [PATCH] Adjusted the HTTP client --- .gitignore | 1 + src/Mailgun/Connection/HttpBroker.php | 41 +++------------------------ src/Mailgun/Messages/Messages.php | 7 ++++- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 1de03f5..da3d996 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.phar smoketest.php rackspace_logo.jpg mailgun_icon.png +build diff --git a/src/Mailgun/Connection/HttpBroker.php b/src/Mailgun/Connection/HttpBroker.php index ba31b73..506386f 100644 --- a/src/Mailgun/Connection/HttpBroker.php +++ b/src/Mailgun/Connection/HttpBroker.php @@ -28,20 +28,19 @@ class HttpBroker{ $this->apiKey = $apiKey; $this->workingDomain = $domain; $this->debug = $debug; - } - - public function postRequest($endpointUrl, $postData = array(), $files = array()){ if($this->debug){ $this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false)); } else{ $this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); } - + $this->client->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); $this->client->setDefaultOption('exceptions', true); $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); - + } + + public function postRequest($endpointUrl, $postData = array(), $files = array()){ $request = $this->client->post($endpointUrl, array(), $postData); if(isset($files["attachment"])){ @@ -74,17 +73,6 @@ class HttpBroker{ } public function getRequest($endpointUrl, $queryString = array()){ - if($this->debug){ - $this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false)); - } - else{ - $this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); - } - - $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); - $this->client->setDefaultOption('exceptions', true); - $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); - $request = $this->client->get($endpointUrl, $queryString); $response = $request->send(); $httpResponeCode = $response->getStatusCode(); @@ -106,17 +94,6 @@ class HttpBroker{ } public function deleteRequest($endpointUrl){ - if($this->debug){ - $this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false)); - } - else{ - $this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); - } - - $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); - $this->client->setDefaultOption('exceptions', true); - $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); - $request = $this->client->delete($endpointUrl); $response = $request->send(); $httpResponeCode = $response->getStatusCode(); @@ -138,16 +115,6 @@ class HttpBroker{ } public function putRequest($endpointUrl, $queryString){ - if($this->debug){ - $this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false)); - } - else{ - $this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/'); - } - - $this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey)); - $this->client->setDefaultOption('exceptions', true); - $this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion); $request = $this->client->put($endpointUrl, $queryString); $response = $request->send(); $httpResponeCode = $response->getStatusCode(); diff --git a/src/Mailgun/Messages/Messages.php b/src/Mailgun/Messages/Messages.php index e95fea7..e90a121 100644 --- a/src/Mailgun/Messages/Messages.php +++ b/src/Mailgun/Messages/Messages.php @@ -38,7 +38,12 @@ class Messages{ else{ throw new MissingRequiredMIMEParameters("You are missing the minimum parameters to send a message."); } - } + } + + public function setMessage($message = array(), $files = array()){ + $this->message = $message; + $this->files = $files; + } public function MessageBuilder(){ return new MessageBuilder($this->httpBroker);