From b7685740f86033c2335dd1fdc69d9e3ed662ef4d Mon Sep 17 00:00:00 2001 From: filipcujanovic <29860740+filipcujanovic@users.noreply.github.com> Date: Mon, 23 Jan 2023 22:04:06 +0100 Subject: [PATCH 1/5] refactor(guzzle): upgrade to version 7.5 --- composer.json | 5 ++--- src/Foxy/FoxyClient/FoxyClient.php | 14 ++++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 154b492..4f0434b 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,8 @@ } ], "require": { - "guzzlehttp/guzzle": "~5.2", - "guzzlehttp/cache-subscriber": "0.1.*@dev", - "php": ">=5.3.3" + "guzzlehttp/guzzle": "^7.5", + "php": "^7.2.5 || ^8.0" }, "autoload": { "psr-0": {"Foxy\\FoxyClient": "src/"} diff --git a/src/Foxy/FoxyClient/FoxyClient.php b/src/Foxy/FoxyClient/FoxyClient.php index cc3f884..69c2ad3 100644 --- a/src/Foxy/FoxyClient/FoxyClient.php +++ b/src/Foxy/FoxyClient/FoxyClient.php @@ -190,11 +190,6 @@ public function get($uri = "", $post = null) return $this->go('GET', $uri, $post); } - public function put($uri, $post = null) - { - return $this->go('PUT', $uri, $post); - } - public function post($uri, $post = null) { return $this->go('POST', $uri, $post); @@ -241,7 +236,7 @@ private function go($method, $uri, $post, $is_retry = false) if ($method === "GET" && $post !== null) { $guzzle_args['query'] = $post; } elseif ($post !== null) { - $guzzle_args['body'] = $post; + $guzzle_args['form_params'] = $post; } if (!$this->handle_exceptions) { @@ -262,14 +257,13 @@ private function go($method, $uri, $post, $is_retry = false) private function processRequest($method, $uri, $post, $guzzle_args, $is_retry = false) { // special case for PATCHing a Downloadable File - if ($post !== null && is_array($post) && array_key_exists('file', $post) && $method == 'PATCH') { + if ($post !== null && array_key_exists('file', $post) && $method == 'PATCH') { $method = 'POST'; $guzzle_args['headers']['X-HTTP-Method-Override'] = 'PATCH'; } - $api_request = $this->guzzle->createRequest($method, $uri, $guzzle_args); - $this->last_response = $this->guzzle->send($api_request); - $data = $this->last_response->json(); + $this->last_response = $this->guzzle->request($method, $uri, $guzzle_args); + $data = json_decode($this->last_response->getBody()->getContents(),true); $this->saveLinks($data); if ($this->hasExpiredAccessTokenError($data) && !$this->shouldRefreshToken()) { if (!$is_retry) { From 88a196bf96fa46979eb2a297d3b5bed555a5857a Mon Sep 17 00:00:00 2001 From: filipcujanovic <29860740+filipcujanovic@users.noreply.github.com> Date: Tue, 24 Jan 2023 17:47:24 +0100 Subject: [PATCH 2/5] fix(guzzle): allow string params --- src/Foxy/FoxyClient/FoxyClient.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Foxy/FoxyClient/FoxyClient.php b/src/Foxy/FoxyClient/FoxyClient.php index 69c2ad3..8edbd93 100644 --- a/src/Foxy/FoxyClient/FoxyClient.php +++ b/src/Foxy/FoxyClient/FoxyClient.php @@ -236,7 +236,11 @@ private function go($method, $uri, $post, $is_retry = false) if ($method === "GET" && $post !== null) { $guzzle_args['query'] = $post; } elseif ($post !== null) { - $guzzle_args['form_params'] = $post; + if (is_array($post)) { + $guzzle_args['form_params'] = $post; + } else { + $guzzle_args['body'] = $post; + } } if (!$this->handle_exceptions) { @@ -257,7 +261,7 @@ private function go($method, $uri, $post, $is_retry = false) private function processRequest($method, $uri, $post, $guzzle_args, $is_retry = false) { // special case for PATCHing a Downloadable File - if ($post !== null && array_key_exists('file', $post) && $method == 'PATCH') { + if ($post !== null && is_array($post) && array_key_exists('file', $post) && $method == 'PATCH') { $method = 'POST'; $guzzle_args['headers']['X-HTTP-Method-Override'] = 'PATCH'; } From 6719b844beb7ee673b01f9c4eafca6e8e9d7385b Mon Sep 17 00:00:00 2001 From: filipcujanovic <29860740+filipcujanovic@users.noreply.github.com> Date: Tue, 24 Jan 2023 20:17:39 +0100 Subject: [PATCH 3/5] fix(foxyclient): add put request --- src/Foxy/FoxyClient/FoxyClient.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Foxy/FoxyClient/FoxyClient.php b/src/Foxy/FoxyClient/FoxyClient.php index 8edbd93..faf45a9 100644 --- a/src/Foxy/FoxyClient/FoxyClient.php +++ b/src/Foxy/FoxyClient/FoxyClient.php @@ -200,6 +200,11 @@ public function patch($uri, $post = null) return $this->go('PATCH', $uri, $post); } + public function put($uri, $post = null) + { + return $this->go('PUT', $uri, $post); + } + public function delete($uri, $post = null) { return $this->go('DELETE', $uri, $post); From 64e842ec971e6fa2e0dcebde6b8f6116bf7e387d Mon Sep 17 00:00:00 2001 From: Merlijn Date: Mon, 6 Feb 2023 15:22:48 -0500 Subject: [PATCH 4/5] Add more details for exceptions to beta --- src/Foxy/FoxyClient/FoxyClient.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Foxy/FoxyClient/FoxyClient.php b/src/Foxy/FoxyClient/FoxyClient.php index faf45a9..20ef81d 100644 --- a/src/Foxy/FoxyClient/FoxyClient.php +++ b/src/Foxy/FoxyClient/FoxyClient.php @@ -255,10 +255,10 @@ private function go($method, $uri, $post, $is_retry = false) return $this->processRequest($method, $uri, $post, $guzzle_args, $is_retry); //Catch Errors - http error } catch (\GuzzleHttp\Exception\RequestException $e) { - return array("error_description" => $e->getMessage()); + return $this->handleException($e); //Catch Errors - not JSON } catch (\GuzzleHttp\Exception\ParseException $e) { - return array("error_description" => $e->getMessage()); + return $this->handleException($e); } } } @@ -355,6 +355,24 @@ public function getLinks() return $links; } + private function handleException(\Exception $e) + { + $error = array( + "error_description" => $e->getMessage() + ); + + if ($e->hasResponse()) { + $response = $e->getResponse(); + $error = array_merge($error, array( + "error_code" => $response->getStatusCode(), + "response" => (string)$response, + "error_contents" => (string) $response->getBody()->getContents() + )); + } + + return $error; + } + //Return any errors that exist in the response data. public function getErrors($data) { From c20ef15edb65f0d23248fb9a5b033dd00d49f8db Mon Sep 17 00:00:00 2001 From: Nic Horstmeier Date: Thu, 18 May 2023 09:28:10 -0500 Subject: [PATCH 5/5] BUGFIX GuzzleHttp\Psr7\Response cannot be converted to a string --- src/Foxy/FoxyClient/FoxyClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Foxy/FoxyClient/FoxyClient.php b/src/Foxy/FoxyClient/FoxyClient.php index 20ef81d..e79bdac 100644 --- a/src/Foxy/FoxyClient/FoxyClient.php +++ b/src/Foxy/FoxyClient/FoxyClient.php @@ -365,7 +365,7 @@ private function handleException(\Exception $e) $response = $e->getResponse(); $error = array_merge($error, array( "error_code" => $response->getStatusCode(), - "response" => (string)$response, + "response" => (string)$response->getReasonPhrase(), "error_contents" => (string) $response->getBody()->getContents() )); }