bclibraries/primo-client

Ex Libris Primo REST API 的客户端

v1.0.1 2024-08-20 19:57 UTC

README

PHP 中访问 Primo 简要搜索 RESTful API 的客户端。

安装

使用 composer 安装 Primo-Client。

composer require bclibraries/primo-client:^0.3

Primo Client 目前为 0.* 版本,因此任何小版本更新都可能带来重大变化。

用法

创建一个配置哈希并传递给 PrimoClient::build() 以实例化客户端。

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

$config = [
    'apikey' => 'l7xx38c6a1a3043974262e81a81fb7475ba9',
    'gateway' => 'https://api-na.hosted.exlibrisgroup.com',
    'vid' => 'my_vid',
    'tab' => 'the_tab',
    'scope' => 'mylib'
];
$primo = \BCLib\PrimoClient\PrimoClient::build(
                                                $config['gateway'],
                                                $config['apikey'], 
                                                $config['tab'],
                                                $config['vid'],
                                                $config['scope']
                                               );
$response = $primo->search('otters');

将字符串传递给 search() 将执行简单的关键字搜索。对于更复杂的搜索,请传递一个 SearchRequest 对象

$request = $primo->getSearchRequest();

$contains_manchurian_candidate = new \BCLib\PrimoClient\Query('any','contains','manchurian candidate');
$contains_demme = new \BCLib\PrimoClient\Query('creator','contains','demme');

$is_video = new \BCLib\PrimoClient\QueryFacet('facet_rtype','exact','video');

$request->addQuery($contains_manchurian_candidate)
    ->addQuery($contains_demme, 'NOT')
    ->include($is_video)
    ->sort('date')
    ->limit(5);

$response = $primo->search($request);

可以直接访问 SearchResponse 的 JSON 结构

echo "{$response->json->info->total} total results\n";
foreach ($response->json->docs as $doc) {
    echo "{$doc->pnx->display->title[0]}\n";
}

或通过便捷参数

echo "{$response->total} total results\n";
foreach ($response->docs as $doc) {
    echo "{$doc->title}\n";
}

运行测试

PHPUnit 用于测试。要运行

vendor/bin/phpunit test

贡献

  1. 将其分叉(https://github.com/yourname/yourproject/fork
  2. 创建您的功能分支(git checkout -b feature/fooBar)
  3. 提交您的更改(git commit -am '添加一些 fooBar')
  4. 推送到分支(git push origin feature/fooBar)
  5. 创建新的 Pull Request

请确保适当更新测试。

许可

MIT