From f435ff9333039b8bc50104b1c9355b3e7ed8e1e8 Mon Sep 17 00:00:00 2001 From: rbo Date: Fri, 10 Aug 2018 15:22:13 +0100 Subject: [PATCH 1/5] New oauth links --- src/Client/Oauth/BookboonProvider.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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'; } /** From ad5f3893e1988684147a0d1e2c7694ff39c06cd7 Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Fri, 25 Jan 2019 11:37:20 +0000 Subject: [PATCH 2/5] Fix memcached and hashtrait bugs Signed-off-by: Lasse Mammen --- src/Cache/HashTrait.php | 8 ++------ src/Cache/MemcachedCache.php | 2 +- tests/Cache/HashTraitTest.php | 11 +++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) 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/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'); From d3553295e46b67f44bc327e884a624063162719c Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 31 Jan 2019 14:07:05 +0000 Subject: [PATCH 3/5] Prevent unknown book types throwing exceptions for missing class Signed-off-by: Lasse Mammen --- src/Entity/Book.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Entity/Book.php b/src/Entity/Book.php index 6c1fa40..dbd3ed3 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -86,7 +86,13 @@ public static function getEntitiesFromArray(array $array) { $entities = array(); foreach ($array as $object) { - $entities[] = self::objectTransformer($object); + if (in_array( + $object['_type'], + array(self::TYPE_PDF, self::TYPE_AUDIO, self::TYPE_VIDEO), + true) + ) { + $entities[] = self::objectTransformer($object); + } } return $entities; From 29306d9f74eb200fb85d802e218be078dd4778a0 Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 21 Feb 2019 10:09:15 +0000 Subject: [PATCH 4/5] Restrict search and categories to pdf books only by default Signed-off-by: Lasse Mammen --- src/Entity/Book.php | 25 +++++++++++++++++++++---- src/Entity/Category.php | 8 +++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Entity/Book.php b/src/Entity/Book.php index dbd3ed3..fe16455 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -123,11 +123,21 @@ public static function getDownloadUrl(Bookboon $bookboon, $bookId, array $variab * @param $query string to search for * @param int $limit results to return per page * @param int $offset offset of results + * @param string $bookType * @return Book[] */ - public static function search(Bookboon $bookboon, $query, $limit = 10, $offset = 0) + public static function search(Bookboon $bookboon, $query, $limit = 10, $offset = 0, $bookType = self::TYPE_PDF) { - $search = $bookboon->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(); } @@ -144,9 +154,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))); } /** From ff6cc6abae44e501c1de819e9b89be4ba8632ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justas=20Stanevi=C4=8Dius?= Date: Tue, 10 Sep 2019 10:49:38 +0300 Subject: [PATCH 5/5] adding expert talks to old platform --- src/Entity/AudioTalkBook.php | 8 ++++++++ src/Entity/Book.php | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/Entity/AudioTalkBook.php 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 @@ +