takisrs/biblionet-api-wrapper

biblionet的API包装库

1.0.0 2021-02-03 22:55 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:34 UTC


README

biblionet的API包装库,用PHP编写,帮助您轻松获取书籍数据。

了解更多关于biblionet及其API的信息。

安装

composer require takisrs/biblionet-api-wrapper

如何使用

通过ID获取书籍并显示一些信息

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;
}

获取当前月份的平装书籍及其贡献者并显示一些信息

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;
}

如何使用fetch方法的示例

$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

您也可以结合上述所有内容。例如

// 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");

如何使用filter方法的示例

$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

您也可以结合上述所有内容。

更多示例

您可以在本存储库的examples文件夹中查看更多示例。

文档

您可以在此处阅读完整的文档或检查下面的文档。

类:\takisrs\Biblionet\ApiFetcher

biblionet的API包装类。此库将帮助您从biblionet数据库中获取书籍数据。它提供了一些帮助方法,简化了与他们的API的通信。

类:\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

语言模型的类