Skip to content

Commit

Permalink
Safer Code for returning PDFs + Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Feb 28, 2022
1 parent 299e89b commit 525e0df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -95,6 +95,7 @@ $client->singleCall("GET", $guzzleParameterArray);

## Changelog

* 0.1.15 Enable returning PDFs (thx ewaldmedia)
* 0.1.14 Add _short period write limit reached_ error handling (thx resslinger)
* 0.1.13 Change from [Laravels `str_contains`](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php#L181) to [PHPs `stripos()`](https://www.php.net/manual/de/function.stripos.php) because [it doesn't require `ext-mbstring`](https://github.com/repat/plentymarkets-rest-client/pull/16#issuecomment-880731813) (thx DanMan)
* 0.1.12 Remove `danielstjules/stringy` dependency, copy over [Laravels `str_contains`](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php#L181) instead
Expand Down
14 changes: 1 addition & 13 deletions composer.json
Expand Up @@ -5,24 +5,12 @@
"keywords": ["plentymarkets", "pm", "rest", "api", "client", "sdk"],
"homepage": "https://github.com/repat/plentymarkets-rest-client",
"license": "MIT",
"version" : "0.1.14",
"version" : "0.1.15",
"authors": [
{
"name": "repat",
"email": "repat@repat.de",
"role": "Developer"
},
{
"name": "hepisec",
"role": "Contributor"
},
{
"name": "daniel-mannheimer",
"role": "Contributor"
},
{
"name": "fwehrhausen",
"role": "Contributor"
}
],
"require": {
Expand Down
11 changes: 8 additions & 3 deletions src/PlentymarketsRestClient/PlentymarketsRestClient.php
Expand Up @@ -115,11 +115,16 @@ public function singleCall($method, $path, $params = [])
$this->handleRateLimiting($response);
}

if($response->getHeaders()['Content-Type'][0] == 'application/pdf'){
$headers = $response->getHeaders();

if (is_array($headers)
&& array_key_exists('Content-Type', $headers)
&& array_key_exists(0, $headers['Content-Type'])
&& $headers['Content-Type'][0] === 'application/pdf') {
return $response->getBody()->getContents();
}else{
return json_decode($response->getBody(), true);
}

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

public function get($path, $array = [])
Expand Down

0 comments on commit 525e0df

Please sign in to comment.