Simple PHP wrapper for Zeitfracht's webservice API, written in PHP https://fundevogel.codeberg.page/php-pcbis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Martin Folkers 80b058e852
Bump version
2 days ago
data Rewrite everything 1 month ago
docs Rename PDF docs 2 days ago
src Switch into production mode 2 days ago
tests Remove caching implementation 2 days ago
.editorconfig Migrate project to 'codeberg.org' 1 month ago
.gitattributes Rewrite everything 1 month ago
.gitignore Rewrite everything 1 month ago
.woodpecker.yml Restructure project, remove SOAP client 1 month ago
LICENSE Initial commit 3 years ago
README.md Switch into production mode 2 days ago
composer.json Bump version 2 days ago
login.example.json Improving support for audiobooks 2 years ago
phpunit.xml Rewrite everything 1 month ago
pint.json Rewrite everything 1 month ago
psalm.xml Resolve psalm errors 4 weeks ago

README.md

php-pcbis

License Packagist Build

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