elife / api-client
eLife Sciences API客户端
dev-master / 1.0.x-dev
2024-05-29 06:59 UTC
Requires
- php: ^7.1
- beberlei/assert: >=2.2
- composer/package-versions-deprecated: 1.11.99.2
- crell/api-problem: ^3.6
- guzzlehttp/promises: ^1.0
- guzzlehttp/psr7: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.0
- mtdowling/jmespath.php: ^2.0
- phpspec/phpspec: ^5.1 || ^6.3 || ^7.5
- phpspec/prophecy: ^1.10
- phpunit/phpunit: ^7.5.20 || ^8.5 || ^9.6 || ^10.2
- psr/log: ^1.0
- squizlabs/php_codesniffer: ^3.10
Suggests
- guzzlehttp/guzzle: ^6.0, to use the Guzzle6HttpClient adapter
- monolog/monolog: ^1.0, to use the HttpMessageProcessor log processor
- mtdowling/jmespath.php: ^2.0, to use the Result::search() method
- psr/log: ^1.0, to use the WarningCheckingHttpClient adapter
This package is auto-updated.
Last update: 2024-08-29 07:52:36 UTC
README
这个库提供了一个PHP客户端,用于eLife Sciences API。
依赖关系
- PHP 7
您需要一个eLife\ApiClient\HttpClient
的实现;客户端为Guzzle 6提供了一个适配器。
安装
执行composer require elife/api-client
。
使用
eLife\ApiClient\ApiClient
命名空间为eLife API的每个部分提供单独的客户端。
API客户端上的每个方法都代表一个端点。
您可以向API客户端传递默认头部,以及/或每个API客户端方法。您应该提供一个声明您支持哪些版本的Accept
头部。
API客户端总是返回GuzzleHttp\Promise\PromiseInterface
的实例,该实例封装了eLife\ApiClient\Result
的实例,而eLife\ApiClient\Result
又封装了JSON响应。
eLife\ApiClient\Result
通过使用JMESPath(使用jmespath.php)提供集成,允许轻松搜索JSON响应。
基本示例
列出出现在端点第一个页面上的实验室帖子ID
use eLife\ApiClient\ApiClient\LabsClient; use eLife\ApiClient\HttpClient\Guzzle6HttpClient; use eLife\ApiClient\MediaType; use GuzzleHttp\Client as Guzzle; $guzzle = new Guzzle(['base_uri' => 'https://api.elifesciences.org/']); $httpClient = new Guzzle6HttpClient($guzzle); $labsClient = new LabsClient($httpClient); var_dump($labsClient->listPosts(['Accept' => new MediaType(LabsClient::TYPE_POST_LIST, 1)])->wait()->search('items[*].id'));
弃用警告
由于eLife API使用HTTP Warning
头部提供弃用警告,因此eLife\ApiClient\HttpClient\WarningCheckingHttpClient
将它们传递给一个PSR-7 logger。