bclibraries / libkey-client
PHP client for LibKey API from Third Iron
Requires
- php: >=8.2
- ext-json: *
- nyholm/psr7: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- symfony/http-client: ^5.1
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32.0
- mockery/mockery: ^1.3
- php-http/mock-client: ^1.3
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-03-13 22:24:14 UTC
README
LibKeyClient is a PHP library for querying the LibKey Article DOI lookup API from Third Iron.
Installation
Use the package manager composer to install LibKeyClient.
composer require bclibraries/libkey-client:^0.1
LibKeyClient is currently a 0.* release, so things will change drastically with any minor release.
Usage
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
The HTTPClient
LibKey client uses the Symfony HTTPClient component to handle HTTP requests. The Symfony client was chosen instead of a PSR-18—compliant implementation because the original use case required concurrent requests, which PSR-18 does not support.
Running tests
PHPUnit is used for testing. You may need to enable the sockets extension.
./vendor/bin/phpunit
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.