diff --git a/code/web/Drivers/LibKeyDriver.php b/code/web/Drivers/LibKeyDriver.php index 22a08c2aaf..aa70bf4279 100644 --- a/code/web/Drivers/LibKeyDriver.php +++ b/code/web/Drivers/LibKeyDriver.php @@ -2,7 +2,7 @@ class LibKeyDriver { - public function getLibKeyLink($doi) { + public function getLibKeyLink(string $doiUrl): string | null { require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php'; $activeLibrary = Library::getActiveLibrary(); $settings = new LibKeySetting(); @@ -11,10 +11,14 @@ public function getLibKeyLink($doi) { $settings->fetch(); } $curlWrapper = new CurlWrapper; - $response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $doi . "?access_token=" . $settings->apiKey); + $response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $this->extractDoi($doiUrl) . "?access_token=" . $settings->apiKey); if (empty($response)) { return null; } return json_decode($response, true)["data"]["bestIntegratorLink"]["bestLink"]; } + public function extractDoi(string $url): string { + $doi = str_replace(["https://doi.org/", "http://"], "", $url); + return $doi; + } } \ No newline at end of file