biblys / data-client-php
Biblys 数据 PHP 客户端库
Requires
- php: >=5.6.0
- biblys/isbn: ~2.0
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is auto-updated.
Last update: 2020-01-19 06:36:44 UTC
README
一个PHP库,用于从Biblys 数据获取数据或向其推送数据。
安装
使用 composer
使用 composer 安装
composer require biblys/data-client-php:~0
API
客户端
$client = new Client(array options)
初始化一个新的 Biblys 数据客户端。
选项
apiKey
: 读取数据时为可选,推送数据到服务器时必须server
: 可选,默认为http://data.biblys.fr
$client->getBook(string $isbn)
获取此 ISBN 在 Biblys 数据服务器上的书籍信息。
如果找到了与此 ISBN 相关的对象,则返回一个 Book
对象,否则返回 false。
$client->pushBook(Book $book)
将 Book
对象发送到服务器。使用 getBook()
测试是否存在具有此 ISBN 的书籍。如果存在,则使用 updateBook()
方法更新它。否则,将使用 createBook()
方法创建它。
$client->createBook(Book $book)
将尝试在服务器上创建书籍。如果已经存在具有此 ISBN 的书籍,则抛出异常。
$client->updateBook(Book $book)
服务器上尚未实现(将静默失败)。
$client->pushPublisher(Publisher $publisher)
将 Publisher
对象发送到服务器。使用 getPublisher()
测试是否存在具有此 ID 的书籍。如果存在,则使用 updatePublisher()
方法更新它。否则,将使用 createPublisher()
方法创建它。
$client->createPublisher(Publisher $publisher)
将尝试在服务器上创建书籍。如果已经存在具有此 ISBN 的书籍,则抛出异常。
$client->updatePublisher(Publisher $publisher)
服务器上尚未实现(将静默失败)。
书籍
$book = new Book()
创建一个新的 Book
对象
$book->setEan(string $isbn)
设置书籍的 ISBN。如果 `$isbn` 不是一个有效的 ISBN,则抛出异常。
$book->getEan()
获取书籍的 ISBN。
$book->setTitle(string $title)
设置书的标题
$book->getTitle()
获取书的标题
$book->setPublisher(Publisher $publisher)
将出版商资源与书籍关联
$book->getPublisher()
获取作为出版商对象的书籍出版商
$book->setAuthors(array $authors)
设置书的作者(必须是一个贡献者对象的数组)
$book->addAuthor(Author $author)
将贡献者作为作者与书籍关联
$book->getAuthors()
获取作为贡献者对象的数组的书籍作者
贡献者
可以将与书籍相关联的多个贡献者作为作者。其他角色(插图画家、翻译者等)将在以后加入。
$contributor = new Contributor()
创建一个新的 Contributor
对象
$contributor->setId(string $id)
设置贡献者的ID。
$contributor->getId()
获取贡献者的ID。
$contributor->setFirstName(string $firstName)
设置贡献者的名字
$contributor->getFirstName()
获取贡献者的名字
$contributor->setLastName(string $lastName)
设置贡献者的姓氏
$contributor->getLastName()
获取贡献者的姓氏
$contributor->setName(string $name)
设置贡献者的全名(名 + 姓)
$contributor->getName()
获取贡献者的全名(名 + 姓)
出版商
可以将出版商资源与书籍关联。
$publisher = new Publisher()
创建一个新的 Publisher
对象
$publisher->setId(string $id)
设置出版商的ID。
$publisher->getId()
获取出版商的ID。
$publisher->setName(string $name)
设置出版商的名称
$publisher->getName()
获取出版商的名称
示例
从ISBN获取书籍信息
use Biblys\Data\Client; $client = new Client(); $result = $client->getBook('9791091146134'); if (!$result) { // Result if false, no book was found for this ISBN } else { echo $result->getTitle(); }
将书籍信息推送到服务器
use Biblys\Data\Client; use Biblys\Data\Book; use Biblys\Data\Publisher; $client = new Client([ "apiKey" => "YOUR_API_KEY" // required when pushing data ]); $book = new Book(); $book->setEan('9791091146134'); $book->setTitle('Chants du cauchemar et de la nuit'); $publisher = new Publisher(); $publisher->setName('Dystopia'); $book->setPublisher($publisher); $author = new Contributor(); $author->setFirstName('Thomas'); $author->setLastName('Ligotti'); $book->addAuthor($author); try { $result = $client->push($book); } catch (Exception $e) { // Something went wrong }
测试
使用PHPUnit运行测试
执行composer install
执行composer test
变更日志
0.3.0 (2016-04-05)
- 贡献者推送,创建和获取方法
- 书籍必须至少由一位贡献者作为作者推送
0.2.1 (2016-03-25)
- 修复了通过书籍获取出版商的问题
- 创建书籍时必须要求出版商属性
0.2.0 (2016-03-24)
- 出版商推送,创建和获取方法
- 书籍必须与出版商一起推送
0.1.0 (2016-03-05)
- 首次发布
- 书籍推送,创建和获取方法