Skip to content

Repository files navigation

EANSearch

Java class for EAN, GTIN, UPC and ISBN lookup and validation using the EAN-Search.org API.

Requirements

  • Java (JDK)
  • Gradle (project includes a minimal wrapper shim)

Running the example

Environment

  • EAN_SEARCH_API_TOKEN - API token (required for the example)

Build

chmod +x ./gradlew
./gradlew clean build

Run example

export EAN_SEARCH_API_TOKEN="<your-token>"# Basic example: prints a barcode lookup and a short product list
./gradlew run

Notes

  • The example reads the token from the environment and will exit with code 1 if not set.
  • The Gradle wrapper in this repository is a minimal shim. If you prefer, install Gradle locally and run gradle wrapper to generate a full wrapper.

Using the EANSearch class

packagecom.relaxedcommunications.eansearch;
importjava.util.List;
publicclassExample {
publicstaticvoidmain(String[] args) {
Stringtoken = System.getenv("EAN_SEARCH_API_TOKEN");
if (token == null) {
System.err.println("Set EAN_SEARCH_API_TOKEN env var");
System.exit(1);
}
EANSearchclient = newEANSearch(token);
StringsampleEan = "5099750442227";
StringsampleIsbn = "1119578884"; // ISBN-10// 1) barcodeLookupSystem.out.println("-- barcodeLookup --");
ProductFullp = client.barcodeLookup(sampleEan, Language.English);
if (p != null) {
System.out.println(p.ean + " → " + p.name + " (category: " + p.categoryName + ", google category Id: " + p.googleCategoryId + ") issued in " + p.issuingCountry);
} else {
System.out.println("barcodeLookup: Not found");
}
// 2) isbnLookup (delegates to barcode-lookup)System.out.println("-- isbnLookup --");
ProductFullbook = client.isbnLookup("1119578884");
System.out.println(book == null ? "isbnLookup: Not found" : (sampleIsbn + " → " + book.name));
// 3) verifyChecksumSystem.out.println("-- verifyChecksum --");
booleanok = client.verifyChecksum(sampleEan);
System.out.println(sampleEan + " checksum valid: " + ok);
booleanbad = client.verifyChecksum(sampleEan + "1");
System.out.println(sampleEan + "1 checksum valid: " + bad);
// 4) productSearchSystem.out.println("-- productSearch (exact match) --");
List<Product> products = client.productSearch("Bananaboat", Language.Any, 0);
for (Productq : products) {
System.out.println(q.ean + " → " + q.name + " (" + q.categoryName + ")");
}
// 5) similarProductSearchSystem.out.println("-- similarProductSearch --");
List<Product> similar = client.similarProductSearch("apple iphone withextratokenthatnevermatchesexact", Language.English);
for (Productr : similar) {
System.out.println(r.ean + " → " + r.name);
}
// 6) categorySearch (see appendix C in the API docs for category IDs)System.out.println("-- categorySearch --");
List<Product> cat = client.categorySearch(45, "Bananaboat");
for (Productc : cat) {
System.out.println(c.ean + " → " + c.name + " (" + c.categoryName + ")");
}
// 7) barcodePrefixSearchSystem.out.println("-- barcodePrefixSearch --");
List<Product> prefix = client.barcodePrefixSearch("5099750442");
for (Productq : prefix) {
System.out.println(q.ean + " → " + q.name + " (" + q.categoryName + ")");
}
// 8) issuingCountryLookupSystem.out.println("-- issuingCountryLookup --");
Stringcountry = client.issuingCountryLookup(sampleEan);
System.out.println(sampleEan + " issuing country: " + country);
// 9) barcodeImageSystem.out.println("-- barcodeImage --");
Stringimg = client.barcodeImage(sampleEan, 300, 100);
System.out.println("HTML: <img src=\"data:image/png;base64," + img + "\""); // 10) creditsRemainingSystem.out.println("-- creditsRemaining --");
System.out.println("API credits remaining: " + client.creditsRemaining());
}
}

About

A Java class for EAN, GTIN, UPC and ISBN name lookup and validation using the API on ean-search.org

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages