forked from Nicklason/node-bptf-listings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (52 loc) · 1.64 KB
/
index.js
File metadata and controls
68 lines (52 loc) · 1.64 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
'use strict';
var request = require('request');
var items = require('tf2-items');
module.exports = Listings;
require('util').inherits(Listings, require('events').EventEmitter);
function Listings(options) {
options = options || {};
this.token = options.token;
this.steamid64 = options.steamid64;
this.retry = options.retry || true;
this.retryTime = options.retryTime || 2 * 1000;
this.waitTime = options.waitTime || 1 * 1000;
this.cap = -1;
this.listings = [];
this.promotes = -1;
this.actions = {
remove: [],
create: []
};
this.request = request;
this.items = options.items || new items({ apiKey: options.key });
this.ready = false;
}
Listings.prototype.init = function(callback) {
if (!this.steamid64 || this.steamid64.length != 17) {
callback(new Error("Either missing, or the given steamid64 is not valid"));
return;
}
var self = this;
self.items.init(function(err) {
if (err) {
callback(err);
return;
}
self.getListings(function (err) {
if (err) {
callback(err);
return;
}
self.sendHeartbeat();
self._heartbeatTimer = setInterval(Listings.prototype.sendHeartbeat.bind(self), 90 * 1000);
self.updateInventory();
self._inventoryTimer = setInterval(Listings.prototype.updateInventory.bind(self), 2 * 60 * 1000);
self.ready = true;
callback(null);
});
});
};
require('./lib/http.js');
require('./lib/webapi.js');
require('./lib/requests.js');
require('./lib/methods.js');