-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduced Chapter and TimeTag entities
- Loading branch information
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Bookboon\Api\Entity; | ||
|
||
use Bookboon\Api\Bookboon; | ||
use Bookboon\Api\Client\BookboonResponse; | ||
use Bookboon\Api\Client\ClientInterface; | ||
use Bookboon\Api\Exception\BadUUIDException; | ||
|
||
class Chapter extends Entity | ||
{ | ||
/** | ||
* @param Bookboon $bookboon | ||
* @param string $authorId | ||
* @return BookboonResponse<Chapter> | ||
* @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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Bookboon\Api\Entity; | ||
|
||
use Bookboon\Api\Bookboon; | ||
use Bookboon\Api\Client\BookboonResponse; | ||
use Bookboon\Api\Client\ClientInterface; | ||
use Bookboon\Api\Exception\BadUUIDException; | ||
|
||
class TimeTag extends Entity | ||
{ | ||
/** | ||
* @param Bookboon $bookboon | ||
* @param string $authorId | ||
* @return BookboonResponse<TimeTag> | ||
* @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'); | ||
} | ||
} |