bclibraries/libkey-client

来自 Third Iron 的 LibKey API 的 PHP 客户端

1.0.0 2024-05-13 20:36 UTC

This package is auto-updated.

Last update: 2024-09-13 21:20:52 UTC


README

LibKeyClient 是一个 PHP 库,用于查询来自 Third Iron 的 LibKey 文章 DOI 查询 API

安装

使用包管理器 composer 安装 LibKeyClient。

composer require bclibraries/libkey-client:^0.1

LibKeyClient 目前是 0.* 版本,所以任何小版本更新都会带来巨大变化。

用法

use BCLib\LibKeyClient\LibKeyClient;

require_once __DIR__ . '/vendor/autoload.php';

// LibKey API identifiers.
$libkey_apikey = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$libkey_id = 'xxx';
$doi = '10.1371/journal.pone.0193984';

$libkey = LibKeyClient::build($libkey_id, $libkey_apikey);

// Send request.
$http_response = $libkey->request($doi);

// Parse
if ($libkey_response = $libkey->parse($http_response)) {
    echo "Fulltext for {$libkey_response->getTitle()} is at {$libkey_response->getFullTextFile()}\n";
} else {
    echo "Could not find LibKey entry for '$doi'\n";
}

// Fulltext for Differential resilience of Amazonian otters along the Rio Negro in the aftermath of the 20th century
// international fur trade is at https://libkey.io/libraries/431/articles/195287219/full-text-file?utm_source=api_536

HTTPClient

LibKey 客户端使用 Symfony HTTPClient 组件来处理 HTTP 请求。选择 Symfony 客户端而不是 PSR-18 兼容实现,是因为原始用例需要并发请求,而 PSR-18 不支持并发请求。

运行测试

PHPUnit 用于测试。您可能需要启用套接字扩展。

./vendor/bin/phpunit 

贡献

欢迎提交拉取请求。对于主要更改,请先提出问题以讨论您想要进行哪些更改。

请确保根据需要更新测试。

许可证

MIT