定制 renanbr/crossref-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renanbr/crossref-client

Composer 安装命令:

composer require renanbr/crossref-client

包简介

Client for CrossRef REST API

README 文档

README

This is a library for the Crossref REST API written in PHP.

Crossref Metadata APIs logo PHP logo

Tests codecov Static Analysis Coding Standards

Table of contents

Introduction

This is NOT an official library! The intent of this library is to provide an easy way to make requests to the CrossRef's REST API. You SHOULD read this documentation in conjunction with the official documentation.

Highlighted features:

Library's summary:

class RenanBr\CrossRefClient
{
    // Returns JSON decoded as array
    public function request($path, array $parameters = []);

    // Returns boolean
    public function exists($path);

    public function setUserAgent($userAgent);
    public function setCache(Psr\SimpleCache\CacheInterface $cache);
    public function setVersion($version);
}

Installing

composer require renanbr/crossref-client ^1

Usage

Singletons

Singletons are single results. Retrieving metadata for a specific identifier (e.g. DOI, ISSN, funder_identifier) typically returns in a singleton result.

See: https://github.com/CrossRef/rest-api-doc#singletons

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();
$work = $client->request('works/10.1037/0003-066X.59.1.29');
print_r($work);

The above example will output:

Array
(
    [status] => ok
    [message-type] => work
    [message-version] => 1.0.0
    [message] => Array
        (
            ...

            [DOI] => 10.1037/0003-066x.59.1.29
            [type] => journal-article

            ...

            [title] => Array
                (
                    [0] => How the Mind Hurts and Heals the Body.
                )

            ...
        )
)

Determine existence of a singleton

(...) [You can] determine "existence" of a singleton. The advantage of this technique is that it is very fast because it does not return any metadata (...)

See: https://github.com/CrossRef/rest-api-doc#headers-only

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();
$exists = $client->exists('members/98');
var_dump($exists);

The above example will output:

bool(true)

Lists

Lists results can contain multiple entries. Searching or filtering typically returns a list result.

A list has two parts: Summary; and Items. Normally, an API list result will return both.

See: https://github.com/CrossRef/rest-api-doc#lists

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();

$parameters = [
    'query' => 'global state',
    'filter' => [
        'has-orcid' => true,
    ],
];
$result = $client->request('works', $parameters);

foreach ($result['message']['items'] as $work) {
    // ...
}

Configuration

Caching results

Cache data so you don't request the same data over and over again.

See: https://github.com/CrossRef/rest-api-doc#etiquette

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();
$client->setCache(new voku\cache\CachePsr16());

// ...

The above example uses voku/simple-cache as cache implementation, but you can use any PSR-16 implementation because setCache() accept Psr\SimpleCache\CacheInterface as argument.

Identifying your script

As of September 18th 2017 any API queries that use HTTPS and have appropriate contact information will be directed to a special pool of API machines that are reserved for polite users.

See: https://github.com/CrossRef/rest-api-doc#good-manners--more-reliable-service

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();
$client->setUserAgent('GroovyBib/1.1 (https://example.org/GroovyBib/; mailto:GroovyBib@example.org)');

// ...

The above example makes all subsequent requests attach the contact information given.

Tying to a specific major version

If you need to tie your implementation to a specific major version of the API, you can do so by using version-specific routes. The default route redirects to the most recent version of the API.

See: https://github.com/CrossRef/rest-api-doc#how-to-manage-api-versions

require __DIR__ . '/vendor/autoload.php';
$client = new RenanBr\CrossRefClient();
$client->setVersion('v55');

// ...

The above example tie all subsequent requests to the API version v55.

Rate limits

By default, this library conforms to the rate limit imposed by the API for the current execution.

If you want to keep this behavior across multiple executions, you must configure the cache, as mentioned above.

Handling errors

As this library uses guzzlehttp/guzzle internally. Please refer to the Guzzle Exceptions documentation to see how to handle exceptions properly.

renanbr/crossref-client 适用场景与选型建议

renanbr/crossref-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38.15k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rest」 「api」 「client」 「API-Client」 「crossref」 「crossref-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 renanbr/crossref-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 renanbr/crossref-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 renanbr/crossref-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 38.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-22