Make part of the api oo and create oo skeleton

This commit is contained in:
Tim
2021-04-16 01:23:55 +02:00
parent 8f88a863d1
commit 91d9a5a61f
9 changed files with 487 additions and 4 deletions

View File

@ -4,6 +4,7 @@
namespace Ardent\PicnicApi;
use Ardent\PicnicApi\Objects\ApiListTransformer;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
@ -24,12 +25,24 @@ class PicnicClient
public function getCart()
{
return $this->get('cart');
return ApiListTransformer::getObject($this->get('cart'));
}
/**
* Returns all past and current deliveries of the user.
*
* @param bool $summary Return a summary (less data).
* @param array $filters An array with the statusses of the deliveries. For example; ['COMPLETED'] will only get completed deliveries. Possible options include CURRENT, COMPLETED and CANCELLED.
*/
public function getDeliveries(bool $summary = false, array $filters = []): array
{
$summary = $summary ? '/summary' : '';
return $this->post('deliveries' . $summary, $filters);
}
public function search(string $term)
{
return $this->get(sprintf('search?search_term=%s', urlencode($term)));
return ApiListTransformer::getObjects($this->get(sprintf('search?search_term=%s', urlencode($term))));
}
private function post(string $url, array $data): array