3ft9/dpla

该包已被 废弃,并且不再维护。没有建议的替代包。
关于该包最新版本(1.0.8)的许可证信息不可用。

提供访问美国数字公共图书馆API的权限。

1.0.8 2013-05-26 03:28 UTC

This package is not auto-updated.

Last update: 2024-02-12 10:50:45 UTC


README

这是一个简单的库,用于访问DPLA搜索API

2022-06-08更新:我收到了一封电子邮件,通知我API已发生破坏性更改,我无法再声明它将正常工作。由于我不再使用此代码,我将不会更新它,但我会很高兴接受pull请求。

基本用法

要开始,您只需要引入主DPLA类并创建其实例,传递您的API密钥。

require '/path/to/tfn/dpla.php';
$dpla = new \TFN\DPLA('your api key');

使用此对象,您可以创建一个搜索查询。查询对象支持链式调用,如果您愿意可以使用它。此示例运行一个简单的搜索,查找提及披萨的内容,并获取第一页的十个结果。

$res = $dpla->createSearchQuery()->forText('pizza')->withPaging(1, 10)->execute();

除了通用文本,您还可以在特定字段中进行搜索。此示例将匹配标题中包含“披萨”的任何内容。

$res = $dpla->createSearchQuery()->withTitle('pizza')->withPaging(1, 10)->execute();

有关支持的所有内容的详细信息,请参阅searchquery.php。

execute()方法将返回一个结果对象,该对象具有方便的方法来访问搜索结果的部分。

// Get the total number of documents that matched the search query.
$total_count = $res->getTotalCount();

// Get the page details that this results object represents.
$page = $res->getPageNumber();
$per_page = $res->getPerPage();

// Get an array of the documents in this results object.
$docs = $res->getDocuments();

它还提供了获取结果下一页和前一页的便利方法。

$prev_page_res = $res->getPrevPage();
$next_page_res = $res->getNextPage();

您还可以获取当前页、前一页和下一页的查询对象。

$current_query = $res->getSearchQuery();
$prev_page_query = $res->getPrevPageSearchQuery();
$next_page_query = $res->getNextPageSearchQuery();

许可证

此代码已进入公有领域,请根据您的需求使用。鼓励并欢迎署名,但不是必需的。

贡献

我们欢迎以pull请求的形式进行贡献。

我们是谁?

此代码由Stuart Dallas3ft9 Ltd开发和维护。

原始版本在很大程度上基于William Karavites的Java包装器