Skip to content

takisrs/biblionet-api-wrapper

Repository files navigation

A wrapper library for biblionet's API

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.


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.

Visibility Function
public __construct(string $username, string $password, array $log=array(), integer $requestTimeout=10, integer $resultsPerPage=50) : void
ApiFetcher constructor
public fetch(string $fetchType=1, string/int/array $param1=null, string $param2=null) : \takisrs\Biblionet\ApiFetcher
Fetch books from biblionet's api. You may call with method to fetch data for a specific book, or provide a month to fetch books published in that month. You may also provide two months to fetch books published in that period.
public fill(array $types=array()) : \takisrs\Biblionet\ApiFetcher
Fill with extra data the already fetched items. You may use this method to fetch extra data from biblionet's api for the books that you have fetch with the fetch() method. This method, depending the params, makes extra api requests to the api to fetch the requested data, so it may be slow. Use this method if you want to fetch book's subjects, contributors or companies.
public filter(\string $field, mixed $value, \string $operator='==') : \takisrs\Biblionet\ApiFetcher
Filter the already fetched items. Use this method to narrow down the number of books that have already been fetched depending on specific filters. You may, for example, use this method to keep only the hardcopy books from the fetched items.
public getItems() : Book[] an array of Book objects
Returns the fetched items. Use this method to get all the data that have been fetch from biblionet's api.

Class: \takisrs\Biblionet\Helper

A helper class that provides some static functions.

Visibility Function
public static compare(mixed $var1, mixed $var2, \string $operator) : bool The result of the comparison
Makes a comparison between two variables
public static getPercentage(integer/\int $current, integer/\int $total) : float the percentage
Calculates and return a percentage of completion
public static isCli() : bool
Checks if the script has been called through cli
public static isJson(\string $str) : bool
Checks if a string is json

Class: \takisrs\Biblionet\Logger

A helper class to output logs.

Visibility Function
public __construct(array $show=array()) : void
Constructor.
public disable() : void
Disables the logging
public enable() : void
Enables the logging
public log(\string $type, \string $entity, \string $title, \string $text='', \float $percentage=null) : void
Logs an entry.

Class: \takisrs\Biblionet\Models\Category

The model class of Category

Visibility Function
public __construct(int $id, string $name) : void
category constructor
public getId() : int
get the id of the category
public getName() : string
get the name of the category

Class: \takisrs\Biblionet\Models\Book

The model class of Book

Visibility Function
public __construct(mixed $data) : void
public getAgeFrom() : int
Get the value of ageFrom
public getAgeTo() : int
Get the value of ageTo
public getAlternativeTitle() : string
Get the value of alternativeTitle
public getAvailability() : string
Get the value of availability
public getCategory() : \takisrs\Biblionet\Models\Category
Get the value of category
public getComments() : string
Get the value of comments
public getCompanies() : \takisrs\Biblionet\Models\Company[]
Get the array of Company objs
public getContributors() : \takisrs\Biblionet\Models\Contributor[]
Get the array of Contributor objs
public getCover() : string
Get the value of cover
public getCurrentPublishDate() : mixed
Get the value of currentPublishDate
public getDimensions() : string
Get the value of dimensions
public getEditionNo() : string
Get the value of editionNo
public getFirstPublishDate() : mixed
Get the value of firstPublishDate
public getFuturePublishDate() : mixed
Get the value of futurePublishDate
public getId() : int
Get the value of id
public getImage() : string
Get the value of image
public getIsbn() : string
Get the value of isbn
public getIsbn2() : string
Get the value of isbn2
public getIsbn3() : string
Get the value of isbn3
public getLanguage() : \takisrs\Biblionet\Models\Language
Get the value of language
public getLastUpdated() : \Datetime
Get the value of lastUpdated
public getMultiVolumeTitle() : string
Get the value of multiVolumeTitle
public getOriginalLanguage() : \takisrs\Biblionet\Models\Language
Get the value of originalLanguage
public getOriginalTitle() : string
Get the value of originalTitle
public getPageNo() : int
Get the value of pageNo
public getPlace() : \takisrs\Biblionet\Models\Place
Get the value of place
public getPrice() : float
Get the value of price (euros)
public getPublisher() : \takisrs\Biblionet\Models\Company
Get the value of publisher
public getSeries() : string
Get the value of series
public getSeriesNo() : string
Get mapped to SeriesNo
public getSpecifications() : string
Get the value of specifications
public getSubSeries() : string
Get mapped to SubSeries
public getSubSeriesNo() : string
Get mapped to SubSeriesNo
public getSubjects() : \takisrs\Biblionet\Models\Subject[]
Get the array of Subject objs
public getSubtitle() : string
Get the value of subtitle
public getSummary() : string
Get the value of summary
public getTitle() : string
Get the value of title
public getTranslatedLanguage() : \takisrs\Biblionet\Models\Language
Get the value of translatedLanguage
public getType() : string
Get the value of type
public getVat() : float
Get the value of vat (percentage)
public getVolumeCount() : string
Get the value of volumeCount
public getVolumeNo() : string
Get the value of volumeNo
public getWebAddress() : string
Get the value of webAddress
public getWeight() : int
Get the value of weight (grams)
public getWriter() : \takisrs\Biblionet\Models\Contributor
Get the value of writer
public setCompanies(array $data) : void
Init Book's companies
public setContributors(array $data) : void
Init Book's contributors
public setSubjects(array $data) : void
Init Book's subjects

Class: \takisrs\Biblionet\Models\Company

The model class of Company (ex. publisher)

Visibility Function
public __construct(int $id, string $name, int $typeId=1, string $typeName='Εκδότης', int $order) : void
Company constructor
public getId() : int
Get the id of the category
public getName() : string
Get the name of the category
public getOrder() : int
Get the order of the category
public getTypeId() : int
Get the type id of the category
public getTypeName() : string
Get the type name of the category

Class: \takisrs\Biblionet\Models\Contributor

The model class of Contributor (ex. writer)

Visibility Function
public __construct(int $id, string $name, int $typeId=1, string $typeName='Συγγραφέας', int $order) : void
Contributor constructor
public getId() : int
Get the id of the contributor
public getName() : string
Get the name of the contributor
public getOrder() : int
Get the order of the contributor
public getTypeId() : int
Get the type id of the contributor
public getTypeName() : string
Get the type name of the contributor

Class: \takisrs\Biblionet\Models\Subject

The model class of Subject

Visibility Function
public __construct(int $id, string $name, string $ddc, int $order) : void
Subject constructor
public getDdc() : string
Get the DDC of subject
public getId() : int
Get the id of subject
public getName() : string
Get the name of subject
public getOrder() : int
Get the order of subject

Class: \takisrs\Biblionet\Models\Place

The model class of Place

Visibility Function
public __construct(int $id, string $name) : void
Place constructor
public getId() : int
Get the id of the place
public getName() : string
Get the name of the place

Class: \takisrs\Biblionet\Models\Language

The model class of Language

Visibility Function
public __construct(int $id, string $name) : void
The language constructor
public getId() : int
Get the id of the language
public getName() : string
Get the name of the language

About

A wrapper library for biblionet's API, written in PHP

Resources

License

Stars

Watchers

Forks