bookboon / api
Wrapper for Bookboon API
Installs: 99 303
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 6
Forks: 2
Open Issues: 2
Requires
- php: >=7.3
- ext-curl: *
- ext-json: *
- league/oauth2-client: ~2.3
- psr/log: ^1.1
- psr/simple-cache: ^1.0
Requires (Dev)
- phpunit/phpunit: ~9.0
- vimeo/psalm: ^4.7
- dev-master
- v4.18.2
- v4.18.1
- v4.18
- v4.17.3
- v4.17.2
- v4.17.1
- v4.17
- v4.16
- v4.15
- v4.14
- v4.13.1
- v4.13
- v4.12
- v4.11.3
- v4.11.2
- v4.11.1
- v4.11
- v4.10.2
- v4.10.1
- v4.10
- v4.9.1
- v4.9
- v4.8.3
- v4.8.2
- v4.8.1
- v4.8
- v4.7
- v4.6.1
- v4.6
- v4.5.3
- v4.5.2
- v4.5.1
- v4.5
- v4.4.1
- v4.4
- v4.3
- v4.2
- v4.1
- v4.0
- 3.x-dev
- v3.14.1
- v3.14
- v3.12
- v3.11
- v3.10
- v3.9
- v3.8.1
- v3.8
- v3.7.1
- v3.7
- v3.6.1
- v3.6
- v3.5
- v3.4
- v3.3
- v3.2
- v3.1
- v3.0
- 2.x-dev
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3
- v2.2.1
- v2.2
- v2.1.1
- v2.1
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- 1.x-dev
- v1.4.1
- v1.4
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1
- dev-hotfix/filters-mistake
- dev-feature/gitlab-actions
- dev-hotfix/seedParamForSingleFrontpage
- dev-hotfix/seedParamForFrontpage
- dev-feature/hash-identifiable
- dev-hotfix/addClassroomAsType
- dev-feature/addChaptersAndTimeTags
- dev-hotfix/error-code
- dev-feature/rec-versioning
- dev-feature/classroom
- dev-hotfix/lang-name
- dev-feature/php8
- dev-feature/psalm
- dev-hotfix/client-options
- dev-hotfix/sentry-pass-through
- dev-hotfix/booksLimit
- dev-hotfix/add-email-to-provider
- dev-feature/preserve-zipkin-headers
- dev-hotfix/errors
- dev-hotfix/professional-book-type
- dev-hotfix/v1-ns
- dev-hotfix/thumbnailresolver
- dev-hotfix/author-thumb
- dev-hotfix/journey-thumb
- dev-hotfix/fix-static
- dev-hotfix/header-class
- dev-hotfix/case-insentive-take-2
- dev-hotfix/headers-case-insensitive
- dev-feature/new-entities
- dev-hotfix/fix-last
- dev-feature/subscription
- dev-feature/getAllAuthors
- dev-hotfix/curl-errors
- dev-feature/logger
- dev-hotfix/thumbnail-raw
- dev-feature/bookTypes
- dev-hotfix/book-type
- dev-hotfix/prevent-incorrect-use
This package is auto-updated.
Last update: 2024-12-05 16:57:01 UTC
README
The PHP class is a wrapper for the Bookboon.com API. Because this is just a wrapper class you should familiarize yourself with the REST api before using it.
##Usage
To use the Bookboon AIP you are required to have an application id and secret ($API_ID
and $API_SECRET
below), see the API page for details. Install via composer:
composer require bookboon/api
To use it without composer, use with any PSR-0 compatible autoloader or require every file manually.
The simplest way to get a book is to use the getBook method:
$bookboon = new Bookboon($API_ID, $API_SECRET, array(/*optional named array to set request headers*/));
$book = $bookboon->getBook("BOOK_GUID");
That will return a Book object with public getters for every property. There are plenty more simple get functions:
$category = $bookboon->getCategory("CATEGORY_GUID"); // return Category object
$reviews = $bookboon->getReviews("BOOK_GUID"); // return array of Review
$search = $bookboon->getSearch("query text"); // return array of Book
$recommendations = $bookboon->getRecommendations(array("BOOK_ID_1", "BOOK_ID_2"); // return array of Book
$questions = $bookboon->getQuestions(); // return array of Question
Finally you can download a book usually the following, you need to send a unique user identifier handle
for every unique user (for instance a user id, email):
$url = $bookboon->getBookDownloadUrl("BOOK_GUID", array("handle" => "user@email"));
// Send the $url in a redirect header to the user
Important: Do NOT store this value as it will change constantly.
Use api raw
You can also use the api
method to get database from the API. To pass variables to the API send an array with the api
function:
/* The bacon-loving student */
$vars = array('post' => array( 'answer[0]' => '6230e12c-68d8-45d5-8f02-1d3997713150',
'answer[1]' => '5aca0fe1-0d93-41b1-8691-aa242a526f17'
)
);
$bookboon->api('/questions', $vars);
Note: To make the php class more versatile you need to tell it whether to pass variables using POST or GET methods. The
api
function will only accept keys named 'post' and 'get' and parse their respective arrays into the correct query strings.
##Result
Results from the api
method is json decoded arrays of data directly from the API, if you use any of the other methods (getbooks
, getCategories
etc.) an appropiate object will be returned.
##Exceptions
The wrapper will throw a few different exceptions. If API responds with an unhandled HTTP status such as if a variabls are missing (403), the posted data is malformed (400) or an unknown API error (500). You may wish to catch these errors, like so:
$bookboon = new Bookboon($API_ID, $API_SECRET);
try {
print_r($bookboon->api('/recommendations', array(
'get' => array(
'books' => $book_id
)));
}
catch (NotFoundException $e) {
// handle exception here
}
Right now we throw the following exceptions:
ApiSyntaxException
- Usually missing or malformed parameters
AuthenticationException
- Bad credentials
GeneralApiException
- When some unknown goes wrong, please report this to us
NotFoundException
- API returns not found status (404)
##Cache
The wrapper class provides a cache interface to be used to speed up GET queries. At the moment only memcached is implemented. To set the cache provider use the setCache
method:
$bookboon->setCache(new \Bookboon\Api\Memcached($server, $port, $timeToLive));
To implement your own provider cache software, make sure your interface imlements \Bookboon\Api\Cache
. It only has three methods: save
, get
and delete
, so it should be easy enough to do.