From e178d1c8b4be8a88639741ddb30d0ce6c3713cf7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 22 Jun 2023 10:59:10 +0300 Subject: [PATCH] Update the ApiFetcher to have option to get a field or get the JSON. --- app/DotsAPI/Fetcher/v2/ApiFetcher.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/DotsAPI/Fetcher/v2/ApiFetcher.php b/app/DotsAPI/Fetcher/v2/ApiFetcher.php index c025725..9491a46 100644 --- a/app/DotsAPI/Fetcher/v2/ApiFetcher.php +++ b/app/DotsAPI/Fetcher/v2/ApiFetcher.php @@ -6,7 +6,7 @@ use GuzzleHttp\Client; class ApiFetcher { - public function get($endpoint) { + public function get($endpoint, $field = 'items') { $client = new Client(); $baseUrl = config('dotsapi.base_url'); @@ -31,8 +31,10 @@ class ApiFetcher ); $data = json_decode($response->getBody()->getContents(), true); - $items = $data['items']; - return $items; + if($field == '') + return $data; + + return $data[$field]; } }