From 7635cc6176f963364c8e1b7acae814e9dcb88ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Forg=C3=A1cs?= Date: Mon, 22 Jul 2019 15:09:30 +0200 Subject: [PATCH] cURL options can be passed by configuration. --- config/config.php | 6 ++++++ src/Internal/Client.php | 11 +++++++---- tests/Client/TestCase.php | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/config.php b/config/config.php index 11036d3..09b4bb2 100644 --- a/config/config.php +++ b/config/config.php @@ -40,6 +40,12 @@ 'read_timeout' => env('LARAVEL_UNAS_READ_TIMEOUT', 120), ], + // cURL options passed to Guzzle client. + 'curl' => [ + + ], + + 'events' => [ // Add or remove events here. diff --git a/src/Internal/Client.php b/src/Internal/Client.php index 19d0d38..deb7f39 100644 --- a/src/Internal/Client.php +++ b/src/Internal/Client.php @@ -215,6 +215,10 @@ protected function sendRequest($uri, $body = [], $headers = []) $options['body'] = $body; } + if (isset($this->config['curl']) && !empty($this->config['curl'])) { + $options['curl'] = $this->config['curl']; + } + // Apply token. if ($this->token) { @@ -267,7 +271,7 @@ protected function request($uri, string &$parsedContent = null, $body = [], $hea } // Parse response. - $body = $response->getBody()->getContents() ?? null; + $body = (string)$response->getBody() ?? null; if ($body) { @@ -329,8 +333,7 @@ protected function premiumAuthorization(bool $silent = false) try { $rawResponse = (string)$this ->sendRequest('login', PayloadBuilder::forPremiumAuthorization($this->key)) - ->getBody() - ->getContents(); + ->getBody(); } catch (RequestException $exception) { @@ -338,7 +341,7 @@ protected function premiumAuthorization(bool $silent = false) throw $exception; } - $rawResponse = (string)$exception->getResponse()->getBody()->getContents() ?? null; + $rawResponse = (string)$exception->getResponse()->getBody() ?? null; throw_if(!$rawResponse, $exception); } diff --git a/tests/Client/TestCase.php b/tests/Client/TestCase.php index 45efafc..1674a95 100644 --- a/tests/Client/TestCase.php +++ b/tests/Client/TestCase.php @@ -70,7 +70,7 @@ function (Mockery\MockInterface $mock) use (&$cb) { ->makePartial(); $mock - ->shouldReceive('sendRequest->getBody->getContents') + ->shouldReceive('sendRequest->getBody') ->andReturnUsing(function () { return $this->getResponseSnapshot(); });