Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Cache/HashTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/MemcachedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public function delete($key)
*/
public function isInitialized()
{
return $this->cache == null;
return $this->cache != null;
}
}
13 changes: 8 additions & 5 deletions src/Client/Oauth/BookboonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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';
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/AudioTalkBook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bookboon\Api\Entity;

class AudioTalkBook extends Book
{
const _OWN_TYPE = Book::TYPE_AUDIOTALK;
}
34 changes: 29 additions & 5 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Book extends Entity
const TYPE_AUDIO = 'audio';
const TYPE_PDF = 'pdf';
const TYPE_VIDEO = 'video';
const TYPE_AUDIOTALK = 'audioTalk';

const FORMAT_PDF = 'pdf';
const FORMAT_EPUB = 'epub';
Expand Down Expand Up @@ -86,7 +87,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, self::TYPE_AUDIOTALK),
true)
) {
$entities[] = self::objectTransformer($object);
}
}

return $entities;
Expand Down Expand Up @@ -117,11 +124,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();
}
Expand All @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Cache/HashTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down