mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Merge pull request #139 from Nyholm/no-guzzle
Do not depend on Guzzle/PSR7
This commit is contained in:
commit
698a64c658
@ -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).**
|
||||
|
@ -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",
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user