takisrs / biblionet-api-wrapper
A wrapper library for biblionet's api
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
README
A wrapper library for biblionet's API, written in PHP, to help you fetch books' data easily.
Read more about biblionet and their api
Installation
composer require takisrs/biblionet-api-wrapper
How to use
Fetch a book by id and display some info
use takisrs\Biblionet\ApiFetcher; // Initialize the fetcher class $fetcher = new ApiFetcher("testuser", "testpsw"); // Fetch a book $fetchedItems = $fetcher->fetch(ApiFetcher::FETCH_BY_ID, 252822)->getItems(); // Get the Book object $fetchedBook = reset($fetchedItems); // Output some info with the help of getters if ($fetchedBook){ echo $fetchedBook->getTitle() . " => " . $fetchedBook->getLanguage()->getName().PHP_EOL; }
Fetch current month's hardcopy books with their contributors and display some info
use takisrs\Biblionet\ApiFetcher; $fetcher = new ApiFetcher("testuser", "testpsw"); // Fetch current month's books $fetcher->fetch(ApiFetcher::FETCH_BY_MONTH, date("Y-m")); // Keep only the hardcopy books $fetcher->filter('type', 'Βιβλίο', '=='); // Fill the rest with extra data (contributors) $fetcher->fill([ApiFetcher::FILL_CONTRIBUTORS]); // Get an array of books $fetchedItems = $fetcher->getItems(); // Display some info foreach ($fetchedItems as $item) { echo "**** " . $item->getTitle() . " ****" . PHP_EOL; echo "Publication Date: " . $item->getFirstPublishDate()->format("d/m/y") . PHP_EOL; echo "Weight: " . $item->getWeight() . ' g' . PHP_EOL; echo "Price: " . $item->getPrice() . ' €' . PHP_EOL; $contributors = $item->getContributors(); foreach ($contributors as $contributor) { echo $contributor->getTypeName() . ": " . $contributor->getName() . PHP_EOL; } echo PHP_EOL; }
Examples on how to use the fetch method
$fetcher->fetch(ApiFetcher::FETCH_BY_ID, 252986); // specific book $fetcher->fetch(ApiFetcher::FETCH_BY_ID, [253064, 252986, 252976]); // specific books $fetcher->fetch(ApiFetcher::FETCH_BY_MONTH); // current month's books $fetcher->fetch(ApiFetcher::FETCH_BY_MONTH, "2020-10"); // specific month's books $fetcher->fetch(ApiFetcher::FETCH_BY_MONTH, "2020-10", "2021-01"); // specific period's books
You may also combine all the above. ex:
// January's book of the last 3 years $fetcher->fetch(ApiFetcher::FETCH_BY_MONTH, "2019-01")->fetch(ApiFetcher::FETCH_BY_MONTH, "2020-01")->fetch(ApiFetcher::FETCH_BY_MONTH, "2021-01");
Examples on how to use the filter method
$fetcher->filter('type', 'e-book', '=='); // Keep only the ebooks $fetcher->filter('place.name', 'Αθήνα', '=='); // Keep only those published in Athens $fetcher->filter('cover', 'Μαλακό εξώφυλλο', '=='); // Keep only those with a soft cover $fetcher->filter('availability', 'Κυκλοφορεί', '=='); // Keep only the available ones $fetcher->filter('id', 253064, '>='); // Keep the books with an id >= 253064
You may also combine all the above.
More Examples
You may check for more examples in the examples folder on this repository.
Documentation
You may read the full documentation here or check the docs bellow.
- \takisrs\Biblionet\ApiFetcher
- \takisrs\Biblionet\Helper
- \takisrs\Biblionet\Logger
- \takisrs\Biblionet\Models\Category
- \takisrs\Biblionet\Models\Book
- \takisrs\Biblionet\Models\Company
- \takisrs\Biblionet\Models\Contributor
- \takisrs\Biblionet\Models\Subject
- \takisrs\Biblionet\Models\Place
- \takisrs\Biblionet\Models\Language
Class: \takisrs\Biblionet\ApiFetcher
A wrapper class for biblionet's api. This library will help you fetch books' data from biblionet database. It provides some helpful methods that simplify the communication with their api.
Class: \takisrs\Biblionet\Helper
A helper class that provides some static functions.
Class: \takisrs\Biblionet\Logger
A helper class to output logs.
Class: \takisrs\Biblionet\Models\Category
The model class of Category
Class: \takisrs\Biblionet\Models\Book
The model class of Book
Class: \takisrs\Biblionet\Models\Company
The model class of Company (ex. publisher)
Class: \takisrs\Biblionet\Models\Contributor
The model class of Contributor (ex. writer)
Class: \takisrs\Biblionet\Models\Subject
The model class of Subject
Class: \takisrs\Biblionet\Models\Place
The model class of Place
Class: \takisrs\Biblionet\Models\Language
The model class of Language