diff --git a/src/Entity/Book.php b/src/Entity/Book.php index 3eec000..d01bfe9 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -128,6 +128,40 @@ public static function getAll( return $bResponse; } + /** + * Get many books by filter + * + * @param Bookboon $bookboon + * @param array $bookTypes + * @param array $filters + * @return BookboonResponse + * @throws \Bookboon\Api\Exception\UsageException + **/ + public static function getByFilters( + Bookboon $bookboon, + array $bookTypes = [self::_OWN_TYPE], + array $filters + ) : BookboonResponse { + $variables = [ + 'bookType' => join(',', $bookTypes), + ]; + + $variables = array_merge($variables, $filters); + + $bResponse = $bookboon->rawRequest( + '/v1/books', + $variables, + ClientInterface::HTTP_GET, + true, + Book::class + ); + + $bResponse->setEntityStore( + new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()), Book::class) + ); + + return $bResponse; + } /** * @param array $objectArray diff --git a/src/Entity/Chapter.php b/src/Entity/Chapter.php new file mode 100644 index 0000000..329488d --- /dev/null +++ b/src/Entity/Chapter.php @@ -0,0 +1,84 @@ + + * @throws BadUUIDException + * @throws \Bookboon\Api\Exception\EntityDataException + * @throws \Bookboon\Api\Exception\UsageException + */ + public static function getByBookId(Bookboon $bookboon, string $bookId) : BookboonResponse + { + if (Entity::isValidUUID($bookId) === false) { + throw new BadUUIDException(); + } + + $bResponse = $bookboon->rawRequest( + "/v1/books/$bookId/chapters", + [], + ClientInterface::HTTP_GET, + true, + Chapter::class + ); + + $bResponse->setEntityStore( + new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()), Chapter::class) + ); + + return $bResponse; + } + + protected function isValid(array $array) : bool + { + return isset($array['_id'], $array['duration'], $array['position'], $array['title']); + } + + + /** + * @return string UUID of entity + */ + public function getId() : string + { + return $this->safeGet('_id'); + } + + /** + * Return position of the chapter. + * + * @return int position + */ + public function getPosition() : int + { + return $this->safeGet('position'); + } + + /** + * Return duration of the chapter. + * + * @return int duration + */ + public function getDuration() : int + { + return $this->safeGet('duration'); + } + + /** + * Return title of the chapter + * + * @return string title + */ + public function getTitle() + { + return $this->safeGet('title'); + } +} diff --git a/src/Entity/TimeTag.php b/src/Entity/TimeTag.php new file mode 100644 index 0000000..6e750ee --- /dev/null +++ b/src/Entity/TimeTag.php @@ -0,0 +1,74 @@ + + * @throws BadUUIDException + * @throws \Bookboon\Api\Exception\EntityDataException + * @throws \Bookboon\Api\Exception\UsageException + */ + public static function getByBookId(Bookboon $bookboon, string $bookId) : BookboonResponse + { + if (Entity::isValidUUID($bookId) === false) { + throw new BadUUIDException(); + } + + $bResponse = $bookboon->rawRequest( + "/v1/books/$bookId/timetags", + [], + ClientInterface::HTTP_GET, + true, + TimeTag::class + ); + + $bResponse->setEntityStore( + new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()), TimeTag::class) + ); + + return $bResponse; + } + + protected function isValid(array $array) : bool + { + return isset($array['_id'], $array['offset'], $array['name']); + } + + + /** + * @return string UUID of entity + */ + public function getId() : string + { + return $this->safeGet('_id'); + } + + /** + * Return offset of the timetag. + * + * @return int offset + */ + public function getOffset() : int + { + return $this->safeGet('offset'); + } + + /** + * Return name of the chapter + * + * @return string name + */ + public function getName() + { + return $this->safeGet('name'); + } +}