Updated the php-http lib

This commit is contained in:
Tobias Nyholm 2015-10-30 14:28:43 +01:00
parent b8420451c7
commit 78f252761e
3 changed files with 17 additions and 16 deletions

View File

@ -3,14 +3,14 @@
"description": "The Mailgun SDK provides methods for all API functions.", "description": "The Mailgun SDK provides methods for all API functions.",
"require": { "require": {
"guzzlehttp/psr7": "~1.2", "guzzlehttp/psr7": "~1.2",
"php-http/adapter-implementation": "^0.1", "php-http/httplug": "@dev",
"php-http/adapter": "^0.1", "php-http/client-implementation": "@dev",
"php-http/discovery": "^0.1" "php-http/discovery": "@dev"
}, },
"require-dev": { "require-dev": {
"php": ">=5.4.0", "php": ">=5.4.0",
"phpunit/phpunit": "~4.6", "phpunit/phpunit": "~4.6",
"php-http/guzzle5-adapter": "^0.1.0" "php-http/guzzle6-adapter": "@dev"
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {

View File

@ -4,7 +4,7 @@ namespace Mailgun\Connection;
use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use Http\Adapter\HttpAdapter; use Http\Client\HttpClient;
use Http\Discovery\HttpAdapterDiscovery; use Http\Discovery\HttpAdapterDiscovery;
use Mailgun\Connection\Exceptions\GenericHTTPError; use Mailgun\Connection\Exceptions\GenericHTTPError;
use Mailgun\Connection\Exceptions\InvalidCredentials; use Mailgun\Connection\Exceptions\InvalidCredentials;
@ -25,9 +25,9 @@ class RestClient
private $apiKey; private $apiKey;
/** /**
* @var HttpAdapter * @var HttpClient
*/ */
protected $httpAdapter; protected $httpClient;
/** /**
* @var string * @var string
@ -39,12 +39,12 @@ class RestClient
* @param string $apiHost * @param string $apiHost
* @param string $apiVersion * @param string $apiVersion
* @param bool $ssl * @param bool $ssl
* @param HttpAdapter $adapter * @param HttpClient $httpClient
*/ */
public function __construct($apiKey, $apiHost, $apiVersion, $ssl, HttpAdapter $adapter = null) public function __construct($apiKey, $apiHost, $apiVersion, $ssl, HttpClient $httpClient = null)
{ {
$this->apiKey = $apiKey; $this->apiKey = $apiKey;
$this->httpAdapter = $adapter; $this->httpClient = $httpClient;
$this->apiEndpoint = $this->generateEndpoint($apiHost, $apiVersion, $ssl); $this->apiEndpoint = $this->generateEndpoint($apiHost, $apiVersion, $ssl);
} }
@ -64,8 +64,8 @@ class RestClient
*/ */
protected function send($method, $uri, $body = null, $files = [], array $headers = []) protected function send($method, $uri, $body = null, $files = [], array $headers = [])
{ {
if ($this->httpAdapter === null) { if ($this->httpClient === null) {
$this->httpAdapter = HttpAdapterDiscovery::find(); $this->httpClient = HttpAdapterDiscovery::find();
} }
$headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION; $headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION;
@ -77,7 +77,7 @@ class RestClient
} }
$request = new Request($method, $this->apiEndpoint.$uri, $headers, $body); $request = new Request($method, $this->apiEndpoint.$uri, $headers, $body);
$response = $this->httpAdapter->sendRequest($request); $response = $this->httpClient->sendRequest($request);
return $this->responseHandler($response); return $this->responseHandler($response);
} }

View File

@ -3,6 +3,7 @@
namespace Mailgun; namespace Mailgun;
use Http\Adapter\HttpAdapter; use Http\Adapter\HttpAdapter;
use Http\Client\HttpClient;
use Mailgun\Constants\ExceptionMessages; use Mailgun\Constants\ExceptionMessages;
use Mailgun\Messages\Exceptions; use Mailgun\Messages\Exceptions;
use Mailgun\Connection\RestClient; use Mailgun\Connection\RestClient;
@ -33,17 +34,17 @@ class Mailgun{
* @param string $apiEndpoint * @param string $apiEndpoint
* @param string $apiVersion * @param string $apiVersion
* @param bool $ssl * @param bool $ssl
* @param HttpAdapter $adapter * @param HttpAdapter $httpClient
*/ */
public function __construct( public function __construct(
$apiKey = null, $apiKey = null,
$apiEndpoint = "api.mailgun.net", $apiEndpoint = "api.mailgun.net",
$apiVersion = "v3", $apiVersion = "v3",
$ssl = true, $ssl = true,
HttpAdapter $adapter = null HttpClient $httpClient = null
) { ) {
$this->apiKey = $apiKey; $this->apiKey = $apiKey;
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $adapter); $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $httpClient);
} }
/** /**