From 2cc6ee8c773f008590ce9e627acf406e600f17fb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 15:15:09 +0200 Subject: [PATCH 1/2] Completly removed depenency on Guzzle and made discovery easier --- composer.json | 4 ++-- src/Mailgun/Connection/RestClient.php | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index a703505..504a2db 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,9 @@ "description": "The Mailgun SDK provides methods for all API functions.", "require": { "php": "^5.5|^7.0", - "guzzlehttp/psr7": "~1.2", "php-http/httplug": "^1.0", - "php-http/discovery": "^0.8" + "php-http/multipart-stream-builder": "^0.1", + "php-http/discovery": "^1.0" }, "require-dev": { "phpunit/phpunit": "~4.6", diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 634c674..2bcd8f9 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -2,10 +2,10 @@ namespace Mailgun\Connection; -use GuzzleHttp\Psr7\MultipartStream; -use GuzzleHttp\Psr7\Request; use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\MessageFactoryDiscovery; +use Http\Message\MultipartStream\MultipartStreamBuilder; use Mailgun\Connection\Exceptions\GenericHTTPError; use Mailgun\Connection\Exceptions\InvalidCredentials; use Mailgun\Connection\Exceptions\MissingRequiredParameters; @@ -15,7 +15,7 @@ use Mailgun\Constants\ExceptionMessages; use Psr\Http\Message\ResponseInterface; /** - * This class is a wrapper for the Guzzle (HTTP Client Library). + * This class is a wrapper for the HTTP client. */ class RestClient { @@ -79,14 +79,18 @@ class RestClient $headers['Authorization'] = 'Basic '.base64_encode(sprintf('%s:%s', Api::API_USER, $this->apiKey)); if (!empty($files)) { - $body = new MultipartStream($files); - $headers['Content-Type'] = 'multipart/form-data; boundary='.$body->getBoundary(); + $builder = new MultipartStreamBuilder(); + foreach ($files as $file) { + $builder->addResource($file['name'], $file['contents'], $file); + } + $body = $builder->build(); + $headers['Content-Type'] = 'multipart/form-data; boundary='.$builder->getBoundary(); } elseif (is_array($body)) { $body = http_build_query($body); $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } - $request = new Request($method, $this->getApiUrl($uri), $headers, $body); + $request = MessageFactoryDiscovery::find()->createRequest($method, $this->getApiUrl($uri), $headers, $body); $response = $this->getHttpClient()->sendRequest($request); return $this->responseHandler($response); From e42219576985611ba5782b65c5bf41c7696c3162 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 15:17:08 +0200 Subject: [PATCH 2/2] Removed Puli form docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ce4614..98f546d 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ $mailgun = new \Mailgun\Mailgun('api_key', $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. +means that we will try to find an installed client automatically. **For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).**