-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
60 lines (51 loc) · 1.97 KB
/
index.js
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
var pkg = require('./package.json');
module.exports = bestbuy;
function bestbuy (_options) {
var options = setupOptions(_options);
const availabilityEndpoint = require('./lib/availability')(options);
const realTimeAvailabilityEndpoint = require('./lib/real-time-availability')(options);
const categoriesEndpoint = require('./lib/categories')(options);
const productsEndpoint = require('./lib/products')(options);
const openBoxEndpoint = require('./lib/openBox')(options);
const storesEndpoint = require('./lib/stores')(options);
if (!options.key) throw new Error('A Best Buy developer API key is required');
return {
options: options,
availability: availabilityEndpoint.availability,
availabilityAsStream: availabilityEndpoint.availabilityAsStream,
realTimeAvailability: realTimeAvailabilityEndpoint.realTimeAvailability,
openBox: openBoxEndpoint.openBox,
openBoxAsStream: openBoxEndpoint.openBoxAsStream,
categories: categoriesEndpoint.categories,
categoriesAsStream: categoriesEndpoint.categoriesAsStream,
products: productsEndpoint.products,
productsAsStream: productsEndpoint.productsAsStream,
recommendations: require('./lib/recommendations')(options),
stores: storesEndpoint.stores,
storesAsStream: storesEndpoint.storesAsStream,
warranties: require('./lib/warranties')(options),
version: require('./lib/version')(options)
};
}
function setupOptions (_opts) {
var opts = {
key: process.env.BBY_API_KEY,
url: 'https://api.bestbuy.com',
debug: false,
headers: {
'User-Agent': `bestbuy-sdk-js/${pkg.version};nodejs`
},
requestsPerSecond: 5,
maxRetries: 0,
retryInterval: 2000,
timeout: 5000
};
if (typeof _opts === 'string') {
opts.key = _opts;
} else if (typeof _opts === 'object') {
opts = Object.assign(opts, _opts);
}
opts.apiService = require('./lib/api.service')(opts);
opts.apiStreamService = require('./lib/api.stream.service')(opts);
return opts;
}