mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-25 06:16:03 +03:00
Updated the php-http lib
This commit is contained in:
parent
b8420451c7
commit
78f252761e
@ -3,14 +3,14 @@
|
||||
"description": "The Mailgun SDK provides methods for all API functions.",
|
||||
"require": {
|
||||
"guzzlehttp/psr7": "~1.2",
|
||||
"php-http/adapter-implementation": "^0.1",
|
||||
"php-http/adapter": "^0.1",
|
||||
"php-http/discovery": "^0.1"
|
||||
"php-http/httplug": "@dev",
|
||||
"php-http/client-implementation": "@dev",
|
||||
"php-http/discovery": "@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"php": ">=5.4.0",
|
||||
"phpunit/phpunit": "~4.6",
|
||||
"php-http/guzzle5-adapter": "^0.1.0"
|
||||
"php-http/guzzle6-adapter": "@dev"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
|
@ -4,7 +4,7 @@ namespace Mailgun\Connection;
|
||||
|
||||
use GuzzleHttp\Psr7\MultipartStream;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use Http\Adapter\HttpAdapter;
|
||||
use Http\Client\HttpClient;
|
||||
use Http\Discovery\HttpAdapterDiscovery;
|
||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
||||
@ -25,9 +25,9 @@ class RestClient
|
||||
private $apiKey;
|
||||
|
||||
/**
|
||||
* @var HttpAdapter
|
||||
* @var HttpClient
|
||||
*/
|
||||
protected $httpAdapter;
|
||||
protected $httpClient;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -39,12 +39,12 @@ class RestClient
|
||||
* @param string $apiHost
|
||||
* @param string $apiVersion
|
||||
* @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->httpAdapter = $adapter;
|
||||
$this->httpClient = $httpClient;
|
||||
$this->apiEndpoint = $this->generateEndpoint($apiHost, $apiVersion, $ssl);
|
||||
}
|
||||
|
||||
@ -64,8 +64,8 @@ class RestClient
|
||||
*/
|
||||
protected function send($method, $uri, $body = null, $files = [], array $headers = [])
|
||||
{
|
||||
if ($this->httpAdapter === null) {
|
||||
$this->httpAdapter = HttpAdapterDiscovery::find();
|
||||
if ($this->httpClient === null) {
|
||||
$this->httpClient = HttpAdapterDiscovery::find();
|
||||
}
|
||||
|
||||
$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);
|
||||
$response = $this->httpAdapter->sendRequest($request);
|
||||
$response = $this->httpClient->sendRequest($request);
|
||||
|
||||
return $this->responseHandler($response);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Mailgun;
|
||||
|
||||
use Http\Adapter\HttpAdapter;
|
||||
use Http\Client\HttpClient;
|
||||
use Mailgun\Constants\ExceptionMessages;
|
||||
use Mailgun\Messages\Exceptions;
|
||||
use Mailgun\Connection\RestClient;
|
||||
@ -33,17 +34,17 @@ class Mailgun{
|
||||
* @param string $apiEndpoint
|
||||
* @param string $apiVersion
|
||||
* @param bool $ssl
|
||||
* @param HttpAdapter $adapter
|
||||
* @param HttpAdapter $httpClient
|
||||
*/
|
||||
public function __construct(
|
||||
$apiKey = null,
|
||||
$apiEndpoint = "api.mailgun.net",
|
||||
$apiVersion = "v3",
|
||||
$ssl = true,
|
||||
HttpAdapter $adapter = null
|
||||
HttpClient $httpClient = null
|
||||
) {
|
||||
$this->apiKey = $apiKey;
|
||||
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $adapter);
|
||||
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $httpClient);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user