From 7ef8533aabca2a6ce7f9b3190d6c2a28942ff378 Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Fri, 2 Aug 2013 12:43:50 -0700 Subject: [PATCH] Fixed GET Requests --- README.md | 4 ++++ composer.json | 2 +- src/Mailgun/Address/Address.php | 2 +- src/Mailgun/Address/README.md | 23 +++++++++++++++++++++++ src/Mailgun/Connection/HttpBroker.php | 22 +++++----------------- src/Mailgun/Globals.php | 2 +- 6 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 src/Mailgun/Address/README.md diff --git a/README.md b/README.md index 55b3940..a5cb1ba 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Next, require Composer's autoloader, in your application, to automatically load ```PHP require 'vendor/autoload.php'; ``` +For shared hosts with SSH access, you might need to run this instead (contact your shared host for assistance): +``` +php -d detect_unicode=Off -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));" +``` Usage ----- diff --git a/composer.json b/composer.json index bcce307..6a5c1aa 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "mailgun/mailgun-sdk-php", + "name": "mailgun/mailgun-php", "description": "The Mailgun SDK provides methods for all API functions.", "require": { "guzzle/guzzle": "3.7.1" diff --git a/src/Mailgun/Address/Address.php b/src/Mailgun/Address/Address.php index 09f2270..ee10dc5 100644 --- a/src/Mailgun/Address/Address.php +++ b/src/Mailgun/Address/Address.php @@ -13,7 +13,7 @@ class Address{ public function __construct($httpBroker){ $this->httpBroker = $httpBroker; - $this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/address"; + $this->endpointUrl = "address"; } public function validateAddress($address){ diff --git a/src/Mailgun/Address/README.md b/src/Mailgun/Address/README.md new file mode 100644 index 0000000..b983f02 --- /dev/null +++ b/src/Mailgun/Address/README.md @@ -0,0 +1,23 @@ +Mailgun-PHP/Address +=================== + +This is the Mailgun PHP *Email Validation* endpoint. Given an arbitrary address, we will validate the address based on: Syntax checks (RFC defined grammar), DNS validation, Spell checks, Email Service Provider (ESP) specific local-part grammar (if available). + +The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. + +Address Usage +------------- +Here's how to use the "Address" API endpoint: + +```php +# First, instantiate the client with your PUBLIC API credentials and domain. +$mgClient = new MailgunClient("pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7", "samples.mailgun.org"); + +# Next, instantiate an Address object on the Address API endpoint. +$address = $mgClient->Address(); + +# Now, validate the address and store the result in $result. +$result = $address->validateAddress("me@samples.mailgun.org"); + +echo $result; +``` diff --git a/src/Mailgun/Connection/HttpBroker.php b/src/Mailgun/Connection/HttpBroker.php index e984291..485cd2f 100644 --- a/src/Mailgun/Connection/HttpBroker.php +++ b/src/Mailgun/Connection/HttpBroker.php @@ -24,22 +24,7 @@ class HttpBroker{ $this->apiKey = $apiKey; $this->workingDomain = $workingDomain; $this->debugMode = $debugMode; - - /* - * !!WARNING, REMOVE DEBUG CODE BEFORE GOING GA!! - */ - - if($this->debugMode){ - $this->mgClient = new Guzzle('https://api.ninomail.com/' . API_VERSION . '/', array('ssl.certificate_authority' => false)); - } - else{ - $this->mgClient = new Guzzle('https://' . API_ENDPOINT . '/' . API_VERSION . '/'); - } - - /* - * !!WARNING, REMOVE DEBUG CODE BEFORE GOING GA!! - */ - + $this->mgClient = new Guzzle('https://' . API_ENDPOINT . '/' . API_VERSION . '/'); $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); $this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey)); $this->mgClient->setDefaultOption('exceptions', true); @@ -65,7 +50,10 @@ class HttpBroker{ } public function getRequest($endpointUrl, $queryString = array()){ - $request = $this->mgClient->get($endpointUrl, $queryString); + $request = $this->mgClient->get($endpointUrl); + foreach($queryString as $queryKey=>$queryValue){ + $request->getQuery()->set($queryKey, $queryValue); + } $response = $request->send(); return $this->responseHandler($response); } diff --git a/src/Mailgun/Globals.php b/src/Mailgun/Globals.php index 8b21778..f2ed591 100644 --- a/src/Mailgun/Globals.php +++ b/src/Mailgun/Globals.php @@ -8,7 +8,7 @@ const SDK_VERSION = "0.1"; const SDK_USER_AGENT = "mailgun-sdk-php"; const DEFAULT_TIME_ZONE = "UTC"; -//Exception Messages +//Common Exception Messages const EXCEPTION_INVALID_CREDENTIALS = "Your credentials are incorrect."; const EXCEPTION_GENERIC_HTTP_ERROR = "An HTTP Error has occurred! Check your network connection and try again.";