Skip to content

Commit

Permalink
Merge pull request #53 from bookboon/hotfix/v1-ns
Browse files Browse the repository at this point in the history
Hotfix/v1 ns
  • Loading branch information
lkm committed Apr 28, 2020
2 parents 528c66f + 22bbba5 commit 3066c35
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- stage: "Tests"
name: "Unit Tests"
script: vendor/bin/phpunit -c . --coverage-clover build/logs/clover.xml
- script: vendor/bin/phpstan analyse src/ --level 6 --no-progress
- script: vendor/bin/phpstan analyse src/ --level 5 --no-progress
name: "Static Analyser"

before_script:
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- '#Unsafe usage of new static().#'
5 changes: 3 additions & 2 deletions src/Client/BasicAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class BasicAuthClient implements ClientInterface
* @param Headers $headers
* @param CacheInterface|null $cache
* @param string|null $apiUri
* @param LoggerInterface|null $logger
* @throws UsageException
*/
public function __construct(
Expand All @@ -48,8 +49,8 @@ public function __construct(
Headers $headers,
CacheInterface $cache = null,
$apiUri = null,
LoggerInterface $logger = null)
{
LoggerInterface $logger = null
) {
if (empty($apiId) || empty($apiSecret)) {
throw new UsageException("Key and secret are required");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/BookboonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function serialize()
*/
public function unserialize($serialized)
{
$data = unserialize($serialized, ['']);
$data = unserialize($serialized, ['allowed_classes' => [BookboonResponse::class]]);
$this->body = $data['body'];
$this->status = $data['status'];
$this->headers = $data['headers'];
Expand Down
2 changes: 1 addition & 1 deletion src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ClientInterface
const API_HOST = 'bookboon.com';
const API_PATH = '/api';

const VERSION = 'Bookboon-PHP/3.2';
const VERSION = 'Bookboon-PHP/3.3';

/**
* Prepares the call to the api and if enabled tries cache provider first for GET calls.
Expand Down
5 changes: 2 additions & 3 deletions src/Client/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function handleErrorResponse(string $body, array $headers, int $status
case 400:
case 405:
$returnArray = json_decode($body, true);
throw new ApiSyntaxException($returnArray['message']);
throw new ApiSyntaxException($returnArray['message'] ?? '');
case 401:
case 403:
$returnArray = json_decode($body, true);
Expand All @@ -42,7 +42,6 @@ protected function handleErrorResponse(string $body, array $headers, int $status
case 410:
case 404:
throw new ApiNotFoundException($url);
break;
default:
$returnArray = json_decode($body, true);
throw new ApiGeneralException($this->generalExceptionMessage($returnArray ?? [], $headers));
Expand Down Expand Up @@ -86,4 +85,4 @@ protected function getResponseHeader(array $headers, string $name) : string
{
return $headers[$name] ?? '';
}
}
}
8 changes: 4 additions & 4 deletions src/Entity/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public static function get(Bookboon $bookboon, string $authorId) : BookboonRespo
throw new BadUUIDException();
}

$bResponse = $bookboon->rawRequest("/authors/$authorId");
$bResponse = $bookboon->rawRequest("/v1/authors/$authorId");

$bResponse->setEntityStore(
new EntityStore(
[
new static($bResponse->getReturnArray())
new self($bResponse->getReturnArray())
]
)
);
Expand All @@ -43,7 +43,7 @@ public static function get(Bookboon $bookboon, string $authorId) : BookboonRespo
*/
public static function getAll(Bookboon $bookboon)
{
$bResponse = $bookboon->rawRequest("/authors");
$bResponse = $bookboon->rawRequest('/v1/authors');

$bResponse->setEntityStore(
new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()))
Expand All @@ -63,7 +63,7 @@ public static function getAll(Bookboon $bookboon)
*/
public static function getByBookId(Bookboon $bookboon, string $bookId) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/books/$bookId/authors");
$bResponse = $bookboon->rawRequest("/v1/books/$bookId/authors");

$bResponse->setEntityStore(
new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down
12 changes: 6 additions & 6 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class Book extends Entity
*/
public static function get(Bookboon $bookboon, string $bookId, bool $extendedMetadata = false) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/books/$bookId", ['extendedMetadata' => $extendedMetadata ? 'true' : 'false']);
$bResponse = $bookboon->rawRequest("/v1/books/$bookId", ['extendedMetadata' => $extendedMetadata ? 'true' : 'false']);

$bResponse->setEntityStore(
new EntityStore(
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function getMultiple(
'extendedMetadata' => $extendedMetadata ? 'true' : 'false'
];

$bResponse = $bookboon->rawRequest("/books", $variables);
$bResponse = $bookboon->rawRequest('/v1/books', $variables);

$bResponse->setEntityStore(
new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down Expand Up @@ -99,7 +99,7 @@ public static function getAll(
'extendedMetadata' => $extendedMetadata ? 'true' : 'false'
];

$bResponse = $bookboon->rawRequest("/books", $variables);
$bResponse = $bookboon->rawRequest('/v1/books', $variables);

$bResponse->setEntityStore(
new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down Expand Up @@ -157,7 +157,7 @@ public static function getDownloadUrl(
) : string {
$variables['format'] = $format;

$bResponse = $bookboon->rawRequest("/books/$bookId/download", $variables, ClientInterface::HTTP_POST);
$bResponse = $bookboon->rawRequest("/v1/books/$bookId/download", $variables, ClientInterface::HTTP_POST);

return $bResponse->getReturnArray()['url'];
}
Expand All @@ -181,7 +181,7 @@ public static function search(
int $offset = 0,
array $bookTypes = ['pdf']
) : BookboonResponse {
$bResponse = $bookboon->rawRequest('/search', ['q' => $query, 'limit' => $limit, 'offset' => $offset, 'bookType' => join(',', $bookTypes)]);
$bResponse = $bookboon->rawRequest('/v1/search', ['q' => $query, 'limit' => $limit, 'offset' => $offset, 'bookType' => join(',', $bookTypes)]);

$bResponse->setEntityStore(
new EntityStore(Book::getEntitiesFromArray($bResponse->getReturnArray()))
Expand All @@ -206,7 +206,7 @@ public static function recommendations(
int $limit = 5,
array $bookTypes = ['pdf']
) : BookboonResponse {
$bResponse = $bookboon->rawRequest('/recommendations', ['limit' => $limit, 'books' => $bookIds, 'bookType' => join(',', $bookTypes)]);
$bResponse = $bookboon->rawRequest('/v1/recommendations', ['limit' => $limit, 'books' => $bookIds, 'bookType' => join(',', $bookTypes)]);

$bResponse->setEntityStore(
new EntityStore(Book::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down
13 changes: 5 additions & 8 deletions src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class Category extends Entity
{
const TEXTBOOKS = 'd1fabb36-4eff-4760-a80d-a15700efa9ae';
const BUSINESS = '82403e77-ccbf-4e10-875c-a15700ef8a56';

/**
* Get Category.
*
Expand All @@ -24,12 +21,12 @@ class Category extends Entity
*/
public static function get(Bookboon $bookboon, string $categoryId, array $bookTypes = ['pdf']) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/categories/$categoryId", ['bookType' => join(',', $bookTypes)]);
$bResponse = $bookboon->rawRequest("/v1/categories/$categoryId", ['bookType' => join(',', $bookTypes)]);

$bResponse->setEntityStore(
new EntityStore(
[
new static($bResponse->getReturnArray())
new self($bResponse->getReturnArray())
]
)
);
Expand All @@ -51,7 +48,7 @@ public static function getTree(
array $blacklistedCategoryIds = [],
int $depth = 2
) : BookboonResponse {
$bResponse = $bookboon->rawRequest('/categories', ['depth' => $depth]);
$bResponse = $bookboon->rawRequest('/v1/categories');

$categories = $bResponse->getReturnArray();

Expand All @@ -60,7 +57,7 @@ public static function getTree(
}

$bResponse->setEntityStore(
new EntityStore(Category::getEntitiesFromArray($categories))
new EntityStore(self::getEntitiesFromArray($categories))
);

return $bResponse;
Expand Down Expand Up @@ -100,7 +97,7 @@ private static function recursiveBlacklist(array &$categories, array $blackliste
*/
public static function getDownloadUrl(Bookboon $bookboon, string $categoryId, array $variables) : string
{
$bResponse = $bookboon->rawRequest("/categories/$categoryId/download", $variables, ClientInterface::HTTP_POST);
$bResponse = $bookboon->rawRequest("/v1/categories/$categoryId/download", $variables, ClientInterface::HTTP_POST);

return $bResponse->getReturnArray()['url'];
}
Expand Down
14 changes: 7 additions & 7 deletions src/Entity/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public static function get(Bookboon $bookboon, string $examId) : BookboonRespons
throw new BadUUIDException();
}

$bResponse = $bookboon->rawRequest("/exams/$examId");
$bResponse = $bookboon->rawRequest("/v1/exams/$examId");

$bResponse->setEntityStore(
new EntityStore(
[
new static($bResponse->getReturnArray())
new self($bResponse->getReturnArray())
]
)
);
Expand All @@ -46,7 +46,7 @@ public static function get(Bookboon $bookboon, string $examId) : BookboonRespons
*/
public static function getByBookId(Bookboon $bookboon, string $bookId) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/books/$bookId/exams");
$bResponse = $bookboon->rawRequest("/v1/books/$bookId/exams");

$bResponse->setEntityStore(
new EntityStore(Exam::getEntitiesFromArray($bResponse->getReturnArray()))
Expand All @@ -64,7 +64,7 @@ public static function getByBookId(Bookboon $bookboon, string $bookId) : Bookboo
*/
public static function getAll(Bookboon $bookboon) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/exams");
$bResponse = $bookboon->rawRequest("/v1/exams");

$bResponse->setEntityStore(
new EntityStore(static::getEntitiesFromArray($bResponse->getReturnArray()))
Expand All @@ -75,12 +75,12 @@ public static function getAll(Bookboon $bookboon) : BookboonResponse

public static function start(Bookboon $bookboon, $examId)
{
return $bookboon->rawRequest("/exams/$examId", [], ClientInterface::HTTP_POST)->getReturnArray();
return $bookboon->rawRequest("/v1/exams/$examId", [], ClientInterface::HTTP_POST)->getReturnArray();
}

public static function finish(Bookboon $bookboon, $examId, $postVars)
{
return $bookboon->rawRequest("/exams/$examId/submit", $postVars, ClientInterface::HTTP_POST)->getReturnArray();
return $bookboon->rawRequest("/v1/exams/$examId/submit", $postVars, ClientInterface::HTTP_POST)->getReturnArray();
}

/**
Expand Down Expand Up @@ -141,4 +141,4 @@ public function getQuestions()
{
return ExamQuestion::getEntitiesFromArray($this->safeGet('questions'));
}
}
}
10 changes: 4 additions & 6 deletions src/Entity/Frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Frontpage extends Entity
*/
public static function get(Bookboon $bookboon, array $bookTypes = ['pdf']) : BookboonResponse
{
$bResponse = $bookboon->rawRequest('/frontpage', ['bookType' => implode(',', $bookTypes)]);
$bResponse = $bookboon->rawRequest('/v1/frontpage', ['bookType' => implode(',', $bookTypes)]);

$bResponse->setEntityStore(
new EntityStore(Frontpage::getEntitiesFromArray($bResponse->getReturnArray()))
new EntityStore(self::getEntitiesFromArray($bResponse->getReturnArray()))
);

return $bResponse;
Expand All @@ -46,14 +46,12 @@ public static function get(Bookboon $bookboon, array $bookTypes = ['pdf']) : Boo
*/
public static function getBySlug(Bookboon $bookboon, string $slug, array $bookTypes = ['pdf']) : BookboonResponse
{

/** @var Frontpage[] $frontpageArray */
$bResponse = $bookboon->rawRequest("/frontpage/$slug", ['bookType' => join(',', $bookTypes)]);
$bResponse = $bookboon->rawRequest("/v1/frontpage/$slug", ['bookType' => join(',', $bookTypes)]);

$bResponse->setEntityStore(
new EntityStore(
[
new static($bResponse->getReturnArray())
new self($bResponse->getReturnArray())
]
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/Journey.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Journey extends Entity
*/
public static function get(Bookboon $bookboon, string $journeyId) : BookboonResponse
{
$bResponse = $bookboon->rawRequest("/journeys/$journeyId");
$bResponse = $bookboon->rawRequest("/v1/journeys/$journeyId");

$journeyEntity = new static($bResponse->getReturnArray());
$journeyEntity = new self($bResponse->getReturnArray());

if (count($journeyEntity->getBookIds()) > 0) {
$books = Book::getMultiple($bookboon, $journeyEntity->getBookIds(), false);
Expand Down Expand Up @@ -49,7 +49,7 @@ public static function get(Bookboon $bookboon, string $journeyId) : BookboonResp
*/
public static function getAll(Bookboon $bookboon, array $bookTypes = ['pdf']) : BookboonResponse
{
$bResponse = $bookboon->rawRequest('/journeys');
$bResponse = $bookboon->rawRequest('/v1/journeys');

$bResponse->setEntityStore(
new EntityStore(Journey::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Language extends Entity
*/
public static function get(Bookboon $bookboon, array $bookTypes = ['pdf']) : BookboonResponse
{
$bResponse = $bookboon->rawRequest('/languages');
$bResponse = $bookboon->rawRequest('/v1/languages');

$bResponse->setEntityStore(
new EntityStore(Language::getEntitiesFromArray($bResponse->getReturnArray()))
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function get(
array $answerIds = [],
string $rootSegmentId = ''
) : BookboonResponse {
$url = $rootSegmentId == '' ? '/questions' : '/questions/' . $rootSegmentId;
$url = $rootSegmentId == '' ? '/v1/questions' : '/v1/questions/' . $rootSegmentId;
$bResponse = $bookboon->rawRequest($url, ['answer' => $answerIds]);

$bResponse->setEntityStore(
Expand All @@ -46,7 +46,7 @@ public static function send(
array $variables = [],
string $rootSegmentId = ''
) : BookboonResponse {
$url = $rootSegmentId == '' ? '/questions' : '/questions/' . $rootSegmentId;
$url = $rootSegmentId == '' ? '/v1/questions' : '/v1/questions/' . $rootSegmentId;
$bResponse = $bookboon->rawRequest($url, $variables, ClientInterface::HTTP_POST);
return $bResponse;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Entity/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public static function getByBookId(Bookboon $bookboon, string $bookId) : Bookboo
throw new BadUUIDException();
}

$bResponse = $bookboon->rawRequest("/books/$bookId/review");
$bResponse = $bookboon->rawRequest("/v1/books/$bookId/reviews");

$bResponse->setEntityStore(
new EntityStore(Review::getEntitiesFromArray($bResponse->getReturnArray()))
new EntityStore(self::getEntitiesFromArray($bResponse->getReturnArray()))
);

return $bResponse;
}

/**
* @param array $review
* @return static
* @return Review
* @throws \Bookboon\Api\Exception\EntityDataException
*/
public static function create(array $review = []) : Review
{
return new static($review);
return new self($review);
}


Expand All @@ -57,7 +57,7 @@ public static function create(array $review = []) : Review
public function submit(Bookboon $bookboon, string $bookId) : void
{
if (Entity::isValidUUID($bookId)) {
$bookboon->rawRequest("/books/$bookId/review", $this->getData(), ClientInterface::HTTP_POST);
$bookboon->rawRequest("/v1/books/$bookId/reviews", $this->getData(), ClientInterface::HTTP_POST);
}
}

Expand Down
Loading

0 comments on commit 3066c35

Please sign in to comment.