Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed May 5, 2017
1 parent de46175 commit 1333ccf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions EANSearch.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* A PHP class for EAN and ISBN name lookup and validation using the API on ean-search.org
*
* (c) Jan Willamowius, 2017
* Relaxed Communications GmbH, 2017
* https://www.ean-search.org/ean-database-api.html
*
*/

class EANSearch {
private $accessToken;

Expand All @@ -18,14 +27,14 @@ 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");
$response = new SimpleXMLElement($xml);
return $response->product;
return $response->xpath('//product');
}

function productSearch($name, $page = 0) {
$xml = file_get_contents("https://api.ean-search.org/api?"
. "op=product-search&token=$this->accessToken&name=$name&page=$page");
$response = new SimpleXMLElement($xml);
return $response->product;
return $response->xpath('//product');
}

function barcodeImage($ean) {
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# ean-search

## Initialization
// your access token from ean-search.org
$accessToken = 'abcdef';

$eanSearch = new EANSearch($accessToken);

## Usage
$ean = '5099750442227';
$name = $eanSearch->barcodeLookup($ean);
echo "$ean is $name\n";

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

$eanList = $eanSearch->productSearch('iPod');
foreach ($eanList as $product) {
echo "$product->ean is $product->name\n";
}

$eanList = $eanSearch->barcodePrefixSearch(4007249146);
foreach ($eanList as $product) {
echo "$product->ean is $product->name\n";
}

0 comments on commit 1333ccf

Please sign in to comment.