Fixed GET Requests

This commit is contained in:
Travis Swientek 2013-08-02 12:43:50 -07:00
parent 017f4fcd92
commit 7ef8533aab
6 changed files with 35 additions and 20 deletions

View File

@ -20,6 +20,10 @@ Next, require Composer's autoloader, in your application, to automatically load
```PHP ```PHP
require 'vendor/autoload.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 Usage
----- -----

View File

@ -1,5 +1,5 @@
{ {
"name": "mailgun/mailgun-sdk-php", "name": "mailgun/mailgun-php",
"description": "The Mailgun SDK provides methods for all API functions.", "description": "The Mailgun SDK provides methods for all API functions.",
"require": { "require": {
"guzzle/guzzle": "3.7.1" "guzzle/guzzle": "3.7.1"

View File

@ -13,7 +13,7 @@ class Address{
public function __construct($httpBroker){ public function __construct($httpBroker){
$this->httpBroker = $httpBroker; $this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/address"; $this->endpointUrl = "address";
} }
public function validateAddress($address){ public function validateAddress($address){

View File

@ -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;
```

View File

@ -24,22 +24,7 @@ class HttpBroker{
$this->apiKey = $apiKey; $this->apiKey = $apiKey;
$this->workingDomain = $workingDomain; $this->workingDomain = $workingDomain;
$this->debugMode = $debugMode; $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 . '/'); $this->mgClient = new Guzzle('https://' . API_ENDPOINT . '/' . API_VERSION . '/');
}
/*
* !!WARNING, REMOVE DEBUG CODE BEFORE GOING GA!!
*/
$this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true));
$this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey)); $this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey));
$this->mgClient->setDefaultOption('exceptions', true); $this->mgClient->setDefaultOption('exceptions', true);
@ -65,7 +50,10 @@ class HttpBroker{
} }
public function getRequest($endpointUrl, $queryString = array()){ 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(); $response = $request->send();
return $this->responseHandler($response); return $this->responseHandler($response);
} }

View File

@ -8,7 +8,7 @@ const SDK_VERSION = "0.1";
const SDK_USER_AGENT = "mailgun-sdk-php"; const SDK_USER_AGENT = "mailgun-sdk-php";
const DEFAULT_TIME_ZONE = "UTC"; const DEFAULT_TIME_ZONE = "UTC";
//Exception Messages //Common Exception Messages
const EXCEPTION_INVALID_CREDENTIALS = "Your credentials are incorrect."; 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."; const EXCEPTION_GENERIC_HTTP_ERROR = "An HTTP Error has occurred! Check your network connection and try again.";