First working version of client
This commit is contained in:
50
src/PicnicClient.php
Normal file
50
src/PicnicClient.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Ardent\PicnicApi;
|
||||
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class PicnicClient
|
||||
{
|
||||
private Client $client;
|
||||
|
||||
public function __construct(string $username, string $password)
|
||||
{
|
||||
$cb = new ClientBuilder($username, $password);
|
||||
$this->client = $cb->getClient();
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->get('user');
|
||||
}
|
||||
|
||||
public function getCart()
|
||||
{
|
||||
return $this->get('cart');
|
||||
}
|
||||
|
||||
public function search(string $term)
|
||||
{
|
||||
return $this->get(sprintf('search?search_term=%s', urlencode($term)));
|
||||
}
|
||||
|
||||
private function post(string $url, array $data): array
|
||||
{
|
||||
$data = $this->client->post($url, [
|
||||
RequestOptions::JSON => $data,
|
||||
]);
|
||||
|
||||
return json_decode($data->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
private function get(string $url): array
|
||||
{
|
||||
$data = $this->client->get($url);
|
||||
|
||||
return json_decode($data->getBody()->getContents(), true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user