From 4a3e9ba3f17924878d3bfbadaeb74c1461ab7635 Mon Sep 17 00:00:00 2001 From: Colin Hall Date: Fri, 31 Jul 2020 09:35:28 +0100 Subject: [PATCH 1/2] Update composer.json Update for guzzle 7 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 939f729..a00a4c6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^7.2.5", "nesbot/carbon": "^1.26.3 || ^2.0", - "guzzlehttp/guzzle": "~6.0|~5.0|~4.0", + "guzzlehttp/guzzle": "~7.0|~6.0|~5.0|~4.0", "firebase/php-jwt": "^5.0", "illuminate/support": "^7.0", "macsidigital/laravel-oauth2-client": "^1.0" @@ -25,7 +25,7 @@ "require-dev": { "orchestra/testbench": "^5.0", "phpunit/phpunit": "^8.5" - }, + }, "autoload": { "psr-4": { "MacsiDigital\\API\\": "src" @@ -50,7 +50,7 @@ "MacsiDigital\\API\\Providers\\APIServiceProvider" ], "aliases": { - + } } } From 84d2cc3db25c2149d5cf696ab0d2d57e9b41d447 Mon Sep 17 00:00:00 2001 From: Colin Hall Date: Sat, 1 Aug 2020 17:39:52 +0100 Subject: [PATCH 2/2] Bug fixes Changes due to guzzle not allowing query string in all calls that are not get --- src/Support/Builder.php | 12 +++--------- src/Support/ResultSet.php | 10 ++++++---- src/Traits/InteractsWithAPI.php | 7 ++++++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Support/Builder.php b/src/Support/Builder.php index cfcd43b..6dc211a 100644 --- a/src/Support/Builder.php +++ b/src/Support/Builder.php @@ -273,7 +273,7 @@ public function all() } - public function get() + public function get($type = 'get') { if($this->resource->beforeQuery($this) === false){ return; @@ -281,18 +281,12 @@ public function get() return $this->handleResponse($this->sendRequest('get', [ $this->retreiveEndPoint('get'), $this->addPagination($this->combineQueries()) - ]), 'get'); + ]), $type); } public function getOne() { - if($this->resource->beforeQuery($this) === false){ - return; - } - return $this->handleResponse($this->sendRequest('get', [ - $this->retreiveEndPoint('get'), - $this->addPagination($this->combineQueries()) - ]), 'individual'); + return $this->get('individual'); } public function post($attributes, $type="individual") diff --git a/src/Support/ResultSet.php b/src/Support/ResultSet.php index 736ac7e..df08ed0 100644 --- a/src/Support/ResultSet.php +++ b/src/Support/ResultSet.php @@ -116,10 +116,12 @@ protected function populate($array) $this->incrementTotalDownloads(count($array[$this->resource->getApiMultipleDataField()])); return $this; } else{ - foreach($array[$this->resource->getApiMultipleDataField()] as $object){ - $this->items->push($this->resource->newFromBuilder($this->resource->passOnAttributes($object))); - $this->incrementTotalDownloads(); - } + if(isset($array[$this->resource->getApiMultipleDataField()])){ + foreach($array[$this->resource->getApiMultipleDataField()] as $object){ + $this->items->push($this->resource->newFromBuilder($this->resource->passOnAttributes($object))); + $this->incrementTotalDownloads(); + } + } } } diff --git a/src/Traits/InteractsWithAPI.php b/src/Traits/InteractsWithAPI.php index f997fd0..3c87692 100644 --- a/src/Traits/InteractsWithAPI.php +++ b/src/Traits/InteractsWithAPI.php @@ -387,7 +387,7 @@ protected function performUpdate(Builder $query) } $resource = (new $this->updateResource)->fill($this, 'update'); - + if($resource->getAttributes() != []){ $validator = $resource->validate(); @@ -613,6 +613,11 @@ public function fresh() return; } + if(method_exists($this, 'find')) + { + return $this->find($this->getKey()); + } + return $this->newQuery()->find($this->getKey()); }