LibKeyClient is a PHP library for querying the LibKey Article DOI lookup API from Third Iron.
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.
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
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.
PHPUnit is used for testing. You may need to enable the sockets extension.
./vendor/bin/phpunit
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.