Skip to content

Commit

Permalink
cURL options can be passed by configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
sykorax committed Jul 22, 2019
1 parent 587443d commit 7635cc6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions src/Internal/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -329,16 +333,15 @@ protected function premiumAuthorization(bool $silent = false)
try {
$rawResponse = (string)$this
->sendRequest('login', PayloadBuilder::forPremiumAuthorization($this->key))
->getBody()
->getContents();
->getBody();
}
catch (RequestException $exception) {

if ($exception->getCode() >= 500 || !$exception->hasResponse()) {
throw $exception;
}

$rawResponse = (string)$exception->getResponse()->getBody()->getContents() ?? null;
$rawResponse = (string)$exception->getResponse()->getBody() ?? null;
throw_if(!$rawResponse, $exception);

}
Expand Down
2 changes: 1 addition & 1 deletion tests/Client/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function (Mockery\MockInterface $mock) use (&$cb) {
->makePartial();

$mock
->shouldReceive('sendRequest->getBody->getContents')
->shouldReceive('sendRequest->getBody')
->andReturnUsing(function () {
return $this->getResponseSnapshot();
});
Expand Down

0 comments on commit 7635cc6

Please sign in to comment.