Skip to content

Commit

Permalink
[FIX] Compatibility issues with Guzzle 7
Browse files Browse the repository at this point in the history
  • Loading branch information
robregonm committed Feb 22, 2021
1 parent 15f8c81 commit c91b10c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"require": {
"php": ">=7.0.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5 || ^7.0",
"illuminate/cache": ">=5.1.0",
"illuminate/container": ">=5.1.0",
Expand Down
18 changes: 12 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Client
protected $apiUrl = '';
protected $downloadUrl;
protected $recommendedPartSize;

protected $authorizationValues;

protected $client;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function __construct(string $accountId, array $authorizationValues, array

// initialize cache
$this->createCacheContainer();

$this->authorizationValues = $authorizationValues;

$this->authorizeAccount(false);
Expand Down Expand Up @@ -336,7 +336,7 @@ public function download(array $options)

if (isset($options['stream'])) {
$requestOptions['stream'] = $options['stream'];
$response = $this->request('GET', $requestUrl, $requestOptions, false, false);
$response = $this->request('GET', $requestUrl, $requestOptions, false);
} else {
$response = $this->request('GET', $requestUrl, $requestOptions, false);
}
Expand Down Expand Up @@ -733,7 +733,7 @@ public function createKey($key)
public function authorizeAccount(bool $forceRefresh = false)
{
$keyId = $this->authorizationValues['keyId'];
$applicationKey = $this->authorizationValues['applicationKey'];
$applicationKey = $this->authorizationValues['applicationKey'];

$baseApiUrl = 'https://api.backblazeb2.com';
$versionPath = '/b2api/v' . $this->version;
Expand Down Expand Up @@ -764,7 +764,7 @@ function () use ($keyId, $applicationKey, $baseApiUrl, $versionPath) {
* @param bool $wantsGetContents
* @return mixed|string
*/
protected function request($method, $uri = null, array $options = [], $asJson = true, $wantsGetContents = true)
protected function request($method, $uri = null, array $options = [], $asJson = true)
{
$headers = [];

Expand All @@ -783,6 +783,12 @@ protected function request($method, $uri = null, array $options = [], $asJson =
$fullUri = $this->apiUrl . $uri;
}

return $this->client->request($method, $fullUri, $options, $asJson, $wantsGetContents);
$response = $this->client->request($method, $fullUri, $options);

if ($asJson) {
return json_decode($response->getBody(), true);
}

return $response->getBody();
}
}
2 changes: 1 addition & 1 deletion src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public function request(string $method, $uri = '', array $options = []): Respons
ErrorHandler::handleErrorResponse($response);
}

return $response->getBody();
return $response;
}
}

0 comments on commit c91b10c

Please sign in to comment.