forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon-product-api-tests.ts
84 lines (65 loc) · 1.79 KB
/
amazon-product-api-tests.ts
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
/// <reference types="node"/>
import amazon = require('amazon-product-api');
var client = amazon.createClient({
awsId: process.env.AWS_ACCESS_KEY_ID,
awsSecret: process.env.AWS_SECRET,
awsTag: process.env.AWS_ASSOCIATE_TAG
});
// Item Search
var searchQuery = {
director: 'Quentin Tarantino',
actor: 'Samuel L. Jackson',
searchIndex: 'DVD',
audienceRating: 'R',
responseGroup: 'ItemAttributes,Offers,Images'
};
client.itemSearch(searchQuery).then((results) => {
console.log(getResultCount(results) + " search results");
}).catch(function(err){
console.log(err);
});
client.itemSearch(searchQuery, (err, results) => {
if(err) {
console.log(err);
return;
}
console.log(getResultCount(results) + " search results");
});
// Item Lookup
var lookupQuery = {
itemId: 'B00008OE6I',
idType: 'ASIN',
responseGroup: 'OfferFull',
Condition: 'All'
};
client.itemLookup(lookupQuery).then((results) => {
console.log(getResultCount(results) + " lookup results");
}).catch(function(err){
console.log(err);
});
client.itemLookup(lookupQuery, (err, results) => {
if(err) {
console.log(err);
return;
}
console.log(getResultCount(results) + " lookup results");
});
// Browse Node Lookup
var nodeLookupQuery = {
browseNodeId: '2625373011'
};
client.browseNodeLookup(nodeLookupQuery).then((results) => {
console.log(getResultCount(results) + " node lookup results");
}).catch(function(err){
console.log(err);
});
client.browseNodeLookup(nodeLookupQuery, (err, results) => {
if(err) {
console.log(err);
return;
}
console.log(getResultCount(results) + " node lookup results");
});
function getResultCount(results: Object[]) {
return results != undefined ? results.length : 0;
}