Updates to the php-http library

This commit is contained in:
Tobias Nyholm 2015-10-30 14:36:08 +01:00
parent 78f252761e
commit a0edd0eb30
2 changed files with 22 additions and 9 deletions

View File

@ -2,15 +2,16 @@
"name": "mailgun/mailgun-php",
"description": "The Mailgun SDK provides methods for all API functions.",
"require": {
"php": ">=5.4.0",
"guzzlehttp/psr7": "~1.2",
"php-http/httplug": "@dev",
"php-http/client-implementation": "@dev",
"php-http/discovery": "@dev"
"php-http/discovery": "dev-master"
},
"require-dev": {
"php": ">=5.4.0",
"phpunit/phpunit": "~4.6",
"php-http/guzzle6-adapter": "@dev"
"php-http/guzzle6-adapter": "dev-master",
"php-http/httplug": "dev-master",
"php-http/message-factory": "dev-master"
},
"autoload": {
"psr-0": {

View File

@ -5,7 +5,7 @@ namespace Mailgun\Connection;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use Http\Client\HttpClient;
use Http\Discovery\HttpAdapterDiscovery;
use Http\Discovery\HttpClientDiscovery;
use Mailgun\Connection\Exceptions\GenericHTTPError;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
@ -64,9 +64,7 @@ class RestClient
*/
protected function send($method, $uri, $body = null, $files = [], array $headers = [])
{
if ($this->httpClient === null) {
$this->httpClient = HttpAdapterDiscovery::find();
}
$client = $this->getHttpClient();
$headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION;
$headers['Authorization'] = 'Basic '.base64_encode(sprintf('%s:%s', Api::API_USER, $this->apiKey));
@ -77,7 +75,7 @@ class RestClient
}
$request = new Request($method, $this->apiEndpoint.$uri, $headers, $body);
$response = $this->httpClient->sendRequest($request);
$response = $client->sendRequest($request);
return $this->responseHandler($response);
}
@ -267,4 +265,18 @@ class RestClient
'filename' => $filename,
];
}
/**
*
* @return HttpClient
*/
protected function getHttpClient()
{
if ($this->httpClient === null) {
$this->httpClient = HttpClientDiscovery::find();
}
return $this->httpClient;
}
}