Update the ApiFetcher to have option to get a field or get the JSON.

This commit is contained in:
2023-06-22 10:59:10 +03:00
parent 6c13fe7d7d
commit e178d1c8b4
+5 -3
View File
@@ -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];
}
}