Skip to content

Commit

Permalink
feat: extract doi from url
Browse files Browse the repository at this point in the history
  • Loading branch information
Chloe070196 committed Dec 2, 2024
1 parent 4a1d87a commit 08139de
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}

0 comments on commit 08139de

Please sign in to comment.