diff --git a/README.md b/README.md index cdbfbb5..f8c7d46 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,20 @@ find adapters to use. For more information about virtual packages please refer t [Httplug](http://docs.httplug.io/en/latest/virtual-package/). Example: ```bash -php composer.phar require php-http/guzzle6-adapter:dev-master +php composer.phar require php-http/guzzle6-adapter:^1.0 ``` +When creating a new `Mailgun` object you must provide an instance of the `HttpClient`. + +```php +$client = new \Http\Adapter\Guzzle6\Client(); +$mailgun = new \Mailgun\Mailgun('api_key', null, null, true, $client); +``` + +You could also rely on the [auto discovery feature of Httplug](http://docs.php-http.org/en/latest/discovery.html). This +means that you need to install `puli/composer-plugin` and put a puli.phar in your project root. + + **For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).** **Rather just download the files? [Library Download](https://9f67cbbd1116d8afb399-7760483f5d1e5f28c2d253278a2a5045.ssl.cf2.rackcdn.com/mailgun-php-1.7.2.zip).** diff --git a/composer.json b/composer.json index 83ccde4..8c6fccc 100644 --- a/composer.json +++ b/composer.json @@ -4,13 +4,13 @@ "require": { "php": ">=5.4.0", "guzzlehttp/psr7": "~1.2", - "php-http/client-implementation": "1.0", - "php-http/discovery": "^0.4" + "php-http/httplug": "^1.0", + "php-http/client-implementation": "^1.0", + "php-http/discovery": "^0.8" }, "require-dev": { "phpunit/phpunit": "~4.6", - "php-http/guzzle5-adapter": "dev-master", - "php-http/httplug": "v1.0.0-beta" + "php-http/guzzle6-adapter": "^1.0" }, "autoload": { "psr-0": { diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index d86d709..e35f9da 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -64,8 +64,6 @@ class RestClient */ protected function send($method, $uri, $body = null, $files = [], array $headers = []) { - $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)); @@ -75,7 +73,7 @@ class RestClient } $request = new Request($method, $this->apiEndpoint.$uri, $headers, $body); - $response = $client->sendRequest($request); + $response = $this->getHttpClient()->sendRequest($request); return $this->responseHandler($response); } diff --git a/src/Mailgun/Mailgun.php b/src/Mailgun/Mailgun.php index cee46db..2b8ebf8 100644 --- a/src/Mailgun/Mailgun.php +++ b/src/Mailgun/Mailgun.php @@ -37,11 +37,19 @@ class Mailgun{ */ public function __construct( $apiKey = null, - $apiEndpoint = "api.mailgun.net", - $apiVersion = "v3", + $apiEndpoint = null, + $apiVersion = null, $ssl = true, HttpClient $httpClient = null ) { + if (empty($apiEndpoint)) { + $apiEndpoint = "api.mailgun.net"; + } + + if (empty($apiVersion)) { + $apiVersion = "v3"; + } + $this->apiKey = $apiKey; $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl, $httpClient); }