|
2 days ago | |
---|---|---|
data | 1 month ago | |
docs | 2 days ago | |
src | 2 days ago | |
tests | 2 days ago | |
.editorconfig | 1 month ago | |
.gitattributes | 1 month ago | |
.gitignore | 1 month ago | |
.woodpecker.yml | 1 month ago | |
LICENSE | 3 years ago | |
README.md | 2 days ago | |
composer.json | 2 days ago | |
login.example.json | 2 years ago | |
phpunit.xml | 1 month ago | |
pint.json | 1 month ago | |
psalm.xml | 4 weeks ago |
README.md
php-pcbis
What
This small library may be used to gather information about books by utilizing the JSON API powering pcbis.de, developed by Zeitfracht, a german wholesale book distributor. The official API documentation can be found here.
Why
It powers our book recommendations & downloads cover images from the German National Library.
How
It's available for Composer:
composer require fundevogel/php-pcbis
Basic workflow
Getting started is pretty straight-forward:
<?php
require_once('vendor/autoload.php');
use Fundevogel\Pcbis\Pcbis;
# Create object, passing credentials as first parameter (for caching, see below)
$object = new Pcbis([/* ... */]);
try {
# After loading a book, you might want to ..
$book = $object->load('978-3-522-20255-8');
# (1) .. export its bibliographic data
$data = $book->export();
# (2) .. access specific information
echo $book->title();
# (3) .. download its cover
if ($book->downloadCover()) {
echo 'Cover downloaded!';
}
# (4) .. query its OLA status
if ($book->isAvailable()) {
# ...
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage(), "\n";
}
Note: While using this library during development, please consider using the API testing endpoint like so:
# Initialize API wrapper
$api = new Webservice($credentials);
# Use 'testing' URL
$api->url = 'https://wstest.pcbis.de/ws30';
If you want to load several EANs/ISBNs, use loadAll(array $identifiers)
which returns a Products
object.
Note: Starting with v3, ISBN validation is no longer enabled by default. If you want formatted (= hyphenated) ISBNs when calling isbn()
(if available), php-pcbis
takes care of this for you if nicebooks/isbn
is installed.
Caching
By default, php-pcbis
doesn't implement any caching mechanism. If you want to store data - and you probably should - this could be achieved something like this:
require_once('vendor/autoload.php');
use Fundevogel\Pcbis\Pcbis;
$obj = new Pcbis([/* ... */]);
$ean = 'identifier';
if ($myCache->has($ean)) {
$data = $myCache->get($ean);
$product = $obj->load($data);
}
else {
$product = $obj->load($ean);
$myCache->set($ean, $product->data);
}
Credits
Most of the helper functions were taken from Kirby's excellent toolkit
package by Bastian Allgeier (who's just awesome, btw).
Happy coding!
©️ Fundevogel Kinder- und Jugendbuchhandlung