diff --git a/composer.json b/composer.json index f7bf7f5..8acfbe3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "require": { "php": "^8.0", "ext-json": "*", - "guzzlehttp/guzzle": "^6.0" + "guzzlehttp/guzzle": "^6.0", + "symfony/serializer": "^5.0" }, "autoload": { "psr-4": { diff --git a/src/GrocyClient.php b/src/GrocyClient.php index 153d3cf..1ab794b 100644 --- a/src/GrocyClient.php +++ b/src/GrocyClient.php @@ -15,7 +15,7 @@ class GrocyClient private function getObjects(string $object, array $query = [], $order = null, $limit = null, $offset = null) { - return $this->client->get($object, compact('order', 'limit', 'offset')); + return $this->client->get(sprintf('objects/%s', $object), compact('order', 'limit', 'offset')); } private function getObject(string $object, int $id) diff --git a/src/Objects/ApiListTransformer.php b/src/Objects/ApiListTransformer.php index debd4c2..4fdc9bd 100644 --- a/src/Objects/ApiListTransformer.php +++ b/src/Objects/ApiListTransformer.php @@ -6,19 +6,6 @@ namespace Ardent\GrocyApi\Objects; class ApiListTransformer { - private static function list(string $type): ?string - { - return match ($type) { - Category::getType() => Category::class, - SingleArticle::getType() => SingleArticle::class, - SingleArticleDetails::getType() => SingleArticleDetails::class, - Order::getType() => Order::class, - OrderLine::getType() => OrderLine::class, - OrderArticle::getType() => OrderArticle::class, - Delivery::getType() => Delivery::class, - default => null, - }; - } public static function getObjects(array $items): array { diff --git a/src/Objects/Category.php b/src/Objects/Category.php deleted file mode 100644 index c4b63f0..0000000 --- a/src/Objects/Category.php +++ /dev/null @@ -1,57 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @return SingleArticle[] - */ - public function getArticles(): array - { - return $this->items; - } -} \ No newline at end of file diff --git a/src/Objects/Delivery.php b/src/Objects/Delivery.php deleted file mode 100644 index ea540f2..0000000 --- a/src/Objects/Delivery.php +++ /dev/null @@ -1,107 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getDeliveryId(): string - { - return $this->deliveryId; - } - - /** - * @return string - */ - public function getCreationTime(): string - { - return $this->creationTime; - } - - /** - * @return array - */ - public function getSlot(): array - { - return $this->slot; - } - - /** - * @return array - */ - public function getEta2(): array - { - return $this->eta2; - } - - /** - * @return string - */ - public function getStatus(): string - { - return $this->status; - } - - /** - * @return array - */ - public function getDeliveryTime(): array - { - return $this->deliveryTime; - } - - /** - * @return Order[] - */ - public function getOrders(): array - { - return $this->orders; - } -} \ No newline at end of file diff --git a/src/Objects/Order.php b/src/Objects/Order.php deleted file mode 100644 index 5ad8951..0000000 --- a/src/Objects/Order.php +++ /dev/null @@ -1,97 +0,0 @@ -id; - } - - /** - * @return OrderLine[] - */ - public function getItems(): array - { - return $this->items; - } - - /** - * @return array - */ - public function getDeliverySlots(): array - { - return $this->deliverySlots; - } - - /** - * @return array - */ - public function getSelectedSlot(): array - { - return $this->selectedSlot; - } - - /** - * @return int - */ - public function getTotalCount(): int - { - return $this->totalCount; - } - - /** - * @return int - */ - public function getTotalPrice(): int - { - return $this->totalPrice; - } - - /** - * @return int - */ - public function getCheckoutTotalPrice(): int - { - return $this->checkoutTotalPrice; - } -} \ No newline at end of file diff --git a/src/Objects/OrderArticle.php b/src/Objects/OrderArticle.php deleted file mode 100644 index f8a425a..0000000 --- a/src/Objects/OrderArticle.php +++ /dev/null @@ -1,93 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @param string $size one of tiny/small/medium/large/extra-large - * - * @return string[] - */ - public function getImageUrls(string $size = 'medium'): array - { - return array_map(function ($id) use ($size) { - return Client::getImageUri($id, $size); - }, $this->imageIds); - } - - /** - * @return string - */ - public function getUnitQuantity(): string - { - return $this->unitQuantity; - } - - /** - * @return int - */ - public function getPrice(): int - { - return $this->price; - } - - /** - * @return int - */ - public function getMaxCount(): int - { - return $this->maxCount; - } -} \ No newline at end of file diff --git a/src/Objects/OrderLine.php b/src/Objects/OrderLine.php deleted file mode 100644 index bae75be..0000000 --- a/src/Objects/OrderLine.php +++ /dev/null @@ -1,68 +0,0 @@ -id; - } - - /** - * @return OrderArticle[] - */ - public function getItems(): array - { - return $this->items; - } - - /** - * @return int - */ - public function getDisplayPrice(): int - { - return $this->displayPrice; - } - - /** - * @return int - */ - public function getPrice(): int - { - return $this->price; - } -} \ No newline at end of file diff --git a/src/Objects/SingleArticle.php b/src/Objects/SingleArticle.php deleted file mode 100644 index f2149c8..0000000 --- a/src/Objects/SingleArticle.php +++ /dev/null @@ -1,124 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @return int - */ - public function getPrice(): float - { - return $this->price / 100.0; - } - - /** - * @return int - */ - public function getDisplayPrice(): float - { - return $this->displayPrice / 100.0; - } - - /** - * @return string - */ - public function getImageId(): string - { - return $this->imageId; - } - - public function getImageUrl(string $size = 'medium'): string - { - return Client::getImageUri($this->imageId, $size); - } - - /** - * @return int - */ - public function getMaxCount(): int - { - return $this->maxCount; - } - - /** - * @return string - */ - public function getUnitQuantity(): string - { - return $this->unitQuantity; - } - - /** - * @return string - */ - public function getUnitQuantitySub(): string - { - return $this->unitQuantitySub; - } - - /** - * @return array - */ - public function getDecorators(): array - { - return $this->decorators; - } -} \ No newline at end of file diff --git a/src/Objects/SingleArticleDetails.php b/src/Objects/SingleArticleDetails.php deleted file mode 100644 index 6162425..0000000 --- a/src/Objects/SingleArticleDetails.php +++ /dev/null @@ -1,153 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - public function getPrice(): float - { - return $this->price / 100.0; - } - - public function getDisplayPrice(): float - { - return $this->displayPrice / 100.0; - } - - public function getDeposit(): float - { - return $this->deposit / 100.0; - } - - /** - * @return string - */ - public function getImageId(): string - { - return $this->imageId; - } - - public function getImageUrl(string $size = 'medium'): string - { - return Client::getImageUri($this->imageId, $size); - } - - /** - * @return array - */ - public function getImageIds(): array - { - return $this->imageIds; - } - - /** - * @param string $size one of tiny/small/medium/large/extra-large - * - * @return string[] - */ - public function getImageUrls(string $size = 'medium'): array - { - return array_map(function ($id) use ($size) { - return Client::getImageUri($id, $size); - }, $this->imageIds); - } - - public function getMaxCount(): int - { - return $this->maxCount; - } - - public function getUnitQuantity(): string - { - return $this->unitQuantity; - } - - public function getUnitQuantitySub(): string - { - return $this->unitQuantitySub; - } - - public function getDecorators(): array - { - return $this->decorators; - } - - public function getNutritionalValues(): array - { - return $this->nutritionalValues; - } - - public function getIngredientsBlob(): string - { - return $this->ingredientsBlob; - } - - public function getAdditionalInfo(): string - { - return $this->additionalInfo; - } -} \ No newline at end of file