From 72c10a5428b65c10cd4442dbfc92e07d70c8c189 Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Sat, 30 Nov 2013 11:47:03 -0800 Subject: [PATCH] Added ability to disable SSL for testing against a Postbin or other endpoint. --- src/Mailgun/Connection/RestClient.php | 13 +++++++++++-- src/Mailgun/Mailgun.php | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 7955c78..65cf7b9 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -20,9 +20,9 @@ class RestClient{ private $apiKey; protected $mgClient; - public function __construct($apiKey, $apiEndpoint, $apiVersion){ + public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl){ $this->apiKey = $apiKey; - $this->mgClient = new Guzzle('https://' . $apiEndpoint . '/' . $apiVersion . '/'); + $this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl)); $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); $this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey)); $this->mgClient->setDefaultOption('exceptions', false); @@ -97,6 +97,15 @@ class RestClient{ $result->http_response_code = $httpResponseCode; return $result; } + + private function generateEndpoint($apiEndpoint, $apiVersion, $ssl){ + if(!$ssl){ + return "http://" . $apiEndpoint . "/" . $apiVersion . "/"; + } + else{ + return "https://" . $apiEndpoint . "/" . $apiVersion . "/"; + } + } } ?> \ No newline at end of file diff --git a/src/Mailgun/Mailgun.php b/src/Mailgun/Mailgun.php index f722c0f..45bf736 100644 --- a/src/Mailgun/Mailgun.php +++ b/src/Mailgun/Mailgun.php @@ -22,8 +22,8 @@ class Mailgun{ protected $workingDomain; protected $restClient; - public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2"){ - $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion); + public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2", $ssl = true){ + $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl); } public function sendMessage($workingDomain, $postData, $postFiles = array()){