-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
104 lines (90 loc) · 2.94 KB
/
example.cpp
File metadata and controls
104 lines (90 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cstdlib>
#include "eansearch.hpp"
using namespace std;
int main() {
auto token = getenv("EAN_SEARCH_API_TOKEN");
if (token == nullptr) {
cout << "Please check your API token" << endl;
return 1;
}
auto * api = new EANSearch(token);
cout << "*** BarcodeLookup()" << endl;
string ean = "5099750442227";
ProductFull * p = api->BarcodeLookup(ean);
if (p) {
cout << ean << " is " << p->name
<< " in category " << p->categoryId << " [" << p->categoryName << "]"
<< " Google category " << p->googleCategoryId << " issued in " << p->issuingCountry
<< endl;
delete p;
} else {
cout << ean << " not found" << endl;
}
cout << "*** IsbnLookup()" << endl;
string isbn = "1119578884";
auto * b = api->IsbnLookup(isbn);
if (p) {
cout << isbn << " is book title " << b->name << endl;
delete b;
} else {
cout << isbn << " not found" << endl;
}
cout << "*** VerifyChecksum()" << endl;
cout << ean << " is " << (api->VerifyChecksum(ean) ? "" : "not ") << "valid" << endl;
ean = "5099750442228"; // invalid
cout << ean << " is " << (api->VerifyChecksum(ean) ? "" : "not ") << "valid" << endl;
cout << "*** ProductSearch() Bananaboat" << endl;
auto * pl = api->ProductSearch("Bananaboat");
if (pl) {
for (auto p : *pl) {
cout << p->ean << " is " << p->name
<< " in category " << p->categoryId << " [" << p->categoryName << "]"
<< " issued in " << p->issuingCountry
<< endl;
}
DeleteProductList(pl);
}
cout << "*** SimilarProductSearch() iPhone Max whatever" << endl;
pl = api->SimilarProductSearch("iPhone Max whatever", 1);
if (pl) {
for (auto p : *pl) {
cout << p->ean << " is " << p->name
<< " in category " << p->categoryId << " [" << p->categoryName << "]"
<< " issued in " << p->issuingCountry
<< endl;
}
DeleteProductList(pl);
}
cout << "*** CategorySearch() Bananaboat in Music" << endl;
pl = api->CategorySearch(45, "Bananaboat");
if (pl) {
for (auto p : *pl) {
cout << p->ean << " is " << p->name
<< " in category " << p->categoryId << " [" << p->categoryName << "]"
<< " issued in " << p->issuingCountry
<< endl;
}
DeleteProductList(pl);
}
cout << "*** BarcodePrefixSearch() 4007249146" << endl;
pl = api->BarcodePrefixSearch("4007249146", 1);
if (pl) {
for (auto p : *pl) {
cout << p->ean << " is " << p->name
<< " in category " << p->categoryId << " [" << p->categoryName << "]"
<< " issued in " << p->issuingCountry
<< endl;
}
DeleteProductList(pl);
}
cout << "*** IssuingCountryLookup()" << endl;
ean = "5099750442227";
cout << ean << " was issued in " << api->IssuingCountryLookup(ean) << endl;
cout << "*** BarcodeImage() base64 encoded" << endl;
ean = "5099750442227";
cout << ean << " image: <img src=\"data:image/png;base64," << api->BarcodeImage(ean, 102, 50) << "\">" << endl;
cout << "*** CreditsRemaining()" << endl;
cout << api->CreditsRemaining() << " credits remaining" << endl;
return 0;
}