forked from Gaming-City/node-tf2-prices
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (48 loc) · 1.52 KB
/
index.js
File metadata and controls
62 lines (48 loc) · 1.52 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
'use strict';
const request = require('request');
module.exports = Prices;
require('util').inherits(Prices, require('events').EventEmitter);
function Prices(options) {
options = options || {};
this.apiKey = options.apiKey;
this.retry = options.retry || true;
this.retryTime = options.retryTime || 2 * 1000;
this.getPricesTime = options.pollTime || 30 * 1000;
this.getCurrenciesTime = options.currenciesTime || 10 * 60 * 1000;
this.prices = [];
this.currencies = {};
this.request = request;
}
Prices.prototype.init = function(callback) {
var self = this;
self.getCurrencies(function(err, currencies) {
if (err) {
callback(err);
return;
}
self.getPrices(function(err, prices) {
if (err) {
callback(err);
return;
}
callback(null);
self.startChecker();
});
});
};
Prices.prototype.setPrices = function(prices) {
this.prices = prices;
};
Prices.prototype.startChecker = function() {
this._priceChecker = setInterval(Prices.prototype.getPrices.bind(this), this.getPricesTime);
this._currenciesChecker = setInterval(Prices.prototype.getCurrencies.bind(this), this.getCurrenciesTime);
};
Prices.prototype.stopChecker = function() {
clearInterval(this._priceChecker);
clearInterval(this._currenciesChecker);
};
require('./lib/http.js');
require('./lib/webapi.js');
require('./lib/requests.js');
require('./lib/methods.js');
require('./lib/prices.js');