First working version of client

This commit is contained in:
Tim
2021-04-13 02:54:22 +02:00
parent 5fae7dfe9f
commit 8f88a863d1
5 changed files with 533 additions and 3 deletions

50
src/PicnicClient.php Normal file
View 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);
}
}