Examples for presentation.
This commit is contained in:
30
sources/Example/VeryGood/ApiClient.php
Normal file
30
sources/Example/VeryGood/ApiClient.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Example\VeryGood;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class ApiClient
|
||||
{
|
||||
|
||||
private Client $client;
|
||||
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Product[]
|
||||
*/
|
||||
public function getProducts(string $filter): array {
|
||||
$response = $this->client->request('GET', 'api_endpoint/products', [
|
||||
'query' => ['filter'=>$filter]
|
||||
]);
|
||||
|
||||
$json = $response->getBody()->getContents();
|
||||
$data = json_decode($json, true);
|
||||
|
||||
return array_map( fn($element)=> (new Product())->setData($element), $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user