diff --git a/src/Cache/HashTrait.php b/src/Cache/HashTrait.php index aa6f4a6..79a8d05 100644 --- a/src/Cache/HashTrait.php +++ b/src/Cache/HashTrait.php @@ -21,7 +21,7 @@ public function hash($url, $id, array $headers) $headerString = ""; foreach ($headers as $key => $value) { if ($key != Headers::HEADER_XFF) { - $headerString = $key.$value; + $headerString .= $key.$value; } } @@ -39,11 +39,7 @@ public function hash($url, $id, array $headers) */ public function isCachable($url, $httpMethod) { - if ($httpMethod === Client::HTTP_GET && $this->isInitialized()) { - return true; - } - - return false; + return $httpMethod === Client::HTTP_GET && $this->isInitialized(); } /** diff --git a/src/Cache/MemcachedCache.php b/src/Cache/MemcachedCache.php index 06fcb15..a1b7954 100644 --- a/src/Cache/MemcachedCache.php +++ b/src/Cache/MemcachedCache.php @@ -88,6 +88,6 @@ public function delete($key) */ public function isInitialized() { - return $this->cache == null; + return $this->cache != null; } } diff --git a/src/Client/Oauth/BookboonProvider.php b/src/Client/Oauth/BookboonProvider.php index 37ed87a..c2d44af 100644 --- a/src/Client/Oauth/BookboonProvider.php +++ b/src/Client/Oauth/BookboonProvider.php @@ -17,8 +17,11 @@ class BookboonProvider extends AbstractProvider { use BearerAuthorizationTrait; - const AUTHORIZE = '/authorize'; - const ACCESS_TOKEN = '/access_token'; + + const AUTHORIZE = '/login/authorize'; + const ACCESS_TOKEN = '/login/access_token'; + const PROTOCOL = 'https'; + const HOST = 'bookboon.com'; /** * @var string @@ -80,7 +83,7 @@ protected function getConfigurableOptions() */ public function getBaseAuthorizationUrl() { - return Client::API_PROTOCOL . '://' . Client::API_URL . self::AUTHORIZE; + return self::PROTOCOL . '://' . self::HOST . self::AUTHORIZE; } /** @@ -93,7 +96,7 @@ public function getBaseAuthorizationUrl() */ public function getBaseAccessTokenUrl(array $params) { - return Client::API_PROTOCOL . '://' . Client::API_URL . self::ACCESS_TOKEN; + return self::PROTOCOL . '://' . self::HOST . self::ACCESS_TOKEN; } /** @@ -104,7 +107,7 @@ public function getBaseAccessTokenUrl(array $params) */ public function getResourceOwnerDetailsUrl(AccessToken $token) { - return Client::API_PROTOCOL . '://' . Client::API_URL . '/_application'; + return self::HOST . '://' . self::HOST . '/login/userinfo'; } /** diff --git a/src/Entity/AudioTalkBook.php b/src/Entity/AudioTalkBook.php new file mode 100644 index 0000000..f3b561e --- /dev/null +++ b/src/Entity/AudioTalkBook.php @@ -0,0 +1,8 @@ +rawRequest('/search', array('q' => $query, 'limit' => $limit, 'offset' => $offset)); + $search = $bookboon->rawRequest( + '/search', + array( + 'q' => $query, + 'limit' => $limit, + 'offset' => $offset, + 'bookType' => $bookType + ) + ); + if (count($search) === 0) { return array(); } @@ -138,9 +155,16 @@ public static function search(Bookboon $bookboon, $query, $limit = 10, $offset = * @param int $limit * @return Book[] */ - public static function recommendations(Bookboon $bookboon, array $bookIds = array(), $limit = 5, $bookType = 'pdf') + public static function recommendations(Bookboon $bookboon, array $bookIds = array(), $limit = 5, $bookType = self::TYPE_PDF) { - $recommendations = $bookboon->rawRequest('/recommendations', array('limit' => $limit, 'book' => $bookIds, 'bookType' => $bookType)); + $recommendations = $bookboon->rawRequest( + '/recommendations', + array( + 'limit' => $limit, + 'book' => $bookIds, + 'bookType' => $bookType + ) + ); return Book::getEntitiesFromArray($recommendations); } diff --git a/src/Entity/Category.php b/src/Entity/Category.php index 8a2d4f4..8371ccf 100644 --- a/src/Entity/Category.php +++ b/src/Entity/Category.php @@ -16,11 +16,13 @@ class Category extends Entity * * @param Bookboon $bookboon * @param string $categoryId - * @return Category|bool + * @param string $bookType + * @return Category + * @throws \Bookboon\Api\Exception\EntityDataException */ - public static function get(Bookboon $bookboon, $categoryId) + public static function get(Bookboon $bookboon, $categoryId, $bookType = Book::TYPE_PDF) { - return new static($bookboon->rawRequest("/categories/$categoryId")); + return new static($bookboon->rawRequest("/categories/$categoryId", array('bookType' => $bookType))); } /** diff --git a/tests/Cache/HashTraitTest.php b/tests/Cache/HashTraitTest.php index a12bc20..39a9413 100644 --- a/tests/Cache/HashTraitTest.php +++ b/tests/Cache/HashTraitTest.php @@ -40,6 +40,17 @@ public function testHashHeader() $this->assertNotEquals($hash1, $hash2); } + /** @group tttt */ + public function testHashLanguageHeader() + { + $mock = $this->getMockForTrait('\Bookboon\Api\Cache\HashTrait'); + + $hash1 = $mock->hash('/test', "WHATEVSID", array(Headers::HEADER_LANGUAGE => 'en, de', Headers::HEADER_BRANDING => 'branding-test')); + $hash2 = $mock->hash('/test', "WHATEVSID", array(Headers::HEADER_LANGUAGE => 'de, en', Headers::HEADER_BRANDING => 'branding-test')); + + $this->assertNotEquals($hash1, $hash2); + } + public function testRequestIsCacheable() { $mock = $this->getMockForTrait('\Bookboon\Api\Cache\HashTrait');