Updated to latest version of Httplug and made auto discovery optional

This commit is contained in:
Tobias Nyholm 2016-02-26 12:04:54 +01:00
parent 6ea7e9325f
commit b961cfb4eb
4 changed files with 27 additions and 10 deletions

View File

@ -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).**

View File

@ -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": {

View File

@ -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);
}

View File

@ -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);
}