Skip to content

Commit

Permalink
add isbnLookup to lookup books by ISBN-10 or ISBN-13
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Apr 18, 2024
1 parent c243e95 commit 8ff1613
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions EANSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function barcodeSearch($ean, $lang = 1) {
return $response->product;
}

// only return the book name
function isbnLookup($isbn) {
$xml = file_get_contents("https://api.ean-search.org/api?"
. "op=barcode-lookup&token=$this->accessToken&isbn=$isbn", false, $this->ctx);
if ($xml === FALSE) {
return '';
}
$response = new SimpleXMLElement($xml);
return $response->product->name;
}

function barcodePrefixSearch($prefix, $page = 0) {
$xml = file_get_contents("https://api.ean-search.org/api?"
. "op=barcode-prefix-search&token=$this->accessToken&prefix=$prefix&page=$page", false, $this->ctx);
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ echo "$ean is $name\n";
$product = $eanSearch->barcodeSearch($ean, 1);
echo "$ean is $product->name from category $product->categoryName issued in $product->issuingCountry\n";

$isbn = '1119578884';
$title = $eanSearch->isbnLookup($isbn);
echo "$isbn is $title\n";

$ok = $eanSearch->verifyChecksum($ean);
echo "$ean is " . ($ok ? 'valid' : 'invalid') . "\n";

Expand Down

0 comments on commit 8ff1613

Please sign in to comment.