mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-25 06:16:03 +03:00
Removed dependency on Happyr/AutoDiscovery
This commit is contained in:
parent
ad015ce441
commit
61d03262a9
@ -3,7 +3,9 @@
|
|||||||
"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",
|
||||||
"happyr/http-auto-discovery": "0.1.*"
|
"php-http/adapter-implementation": "^0.1",
|
||||||
|
"php-http/adapter": "^0.1",
|
||||||
|
"php-http/discovery": "^0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
|
@ -4,13 +4,14 @@ 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\Discovery\HttpAdapterDiscovery;
|
||||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||||
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
||||||
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
||||||
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
||||||
use Mailgun\Constants\Api;
|
use Mailgun\Constants\Api;
|
||||||
use Mailgun\Constants\ExceptionMessages;
|
use Mailgun\Constants\ExceptionMessages;
|
||||||
use Happyr\HttpAutoDiscovery\Client as HttpClient;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,9 +25,9 @@ class RestClient
|
|||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var HttpClient
|
* @var HttpAdapter
|
||||||
*/
|
*/
|
||||||
protected $httpClient;
|
protected $httpAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@ -39,21 +40,30 @@ class RestClient
|
|||||||
* @param string $apiVersion
|
* @param string $apiVersion
|
||||||
* @param bool $ssl
|
* @param bool $ssl
|
||||||
*/
|
*/
|
||||||
public function __construct($apiKey, $apiHost, $apiVersion, $ssl)
|
public function __construct($apiKey, $apiHost, $apiVersion, $ssl, HttpAdapter $adapter = null)
|
||||||
{
|
{
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
|
$this->httpAdapter = $httpAdapter;
|
||||||
$this->apiEndpoint = $this->generateEndpoint($apiHost, $apiVersion, $ssl);
|
$this->apiEndpoint = $this->generateEndpoint($apiHost, $apiVersion, $ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a HttpClient.
|
* @param string $method
|
||||||
|
* @param string $uri
|
||||||
|
* @param array $headers
|
||||||
|
* @param array $body
|
||||||
|
* @param array $files
|
||||||
*
|
*
|
||||||
* @return HttpClient
|
* @return \stdClass
|
||||||
|
* @throws GenericHTTPError
|
||||||
|
* @throws InvalidCredentials
|
||||||
|
* @throws MissingEndpoint
|
||||||
|
* @throws MissingRequiredParameters
|
||||||
*/
|
*/
|
||||||
protected function send($method, $uri, array $headers = [], $body = [], $files = [])
|
protected function send($method, $uri, array $headers = [], $body = [], $files = [])
|
||||||
{
|
{
|
||||||
if ($this->httpClient === null) {
|
if ($this->httpAdapter === null) {
|
||||||
$this->httpClient = new HttpClient();
|
$this->httpAdapter = HttpAdapterDiscovery::find();
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION;
|
$headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION;
|
||||||
@ -65,7 +75,7 @@ class RestClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request = new Request($method, $this->apiEndpoint.$uri, $headers, $body);
|
$request = new Request($method, $this->apiEndpoint.$uri, $headers, $body);
|
||||||
$response = $this->httpClient->sendRequest($request);
|
$response = $this->httpAdapter->sendRequest($request);
|
||||||
|
|
||||||
return $this->responseHandler($response);
|
return $this->responseHandler($response);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Mailgun;
|
namespace Mailgun;
|
||||||
|
|
||||||
|
use Http\Adapter\HttpAdapter;
|
||||||
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,9 +34,15 @@ class Mailgun{
|
|||||||
* @param string $apiVersion
|
* @param string $apiVersion
|
||||||
* @param bool $ssl
|
* @param bool $ssl
|
||||||
*/
|
*/
|
||||||
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v3", $ssl = true){
|
public function __construct(
|
||||||
|
$apiKey = null,
|
||||||
|
$apiEndpoint = "api.mailgun.net",
|
||||||
|
$apiVersion = "v3",
|
||||||
|
$ssl = true,
|
||||||
|
HttpAdapter $adapter = null
|
||||||
|
) {
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl);
|
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user