-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (53 loc) · 1.63 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
var request = require('request');
exports.getprice = (appid, itemname, currency) => {
return new Promise((resolve, reject) => {
if (typeof currency !== 'number') {
currency = 1;
}
request({
uri: '/market/priceoverview',
baseUrl: 'http://steamcommunity.com/',
json: true,
qs: {
currency: currency,
appid: appid,
market_hash_name: itemname
}
}, (err, res) => {
if(err) reject(err);
if(res.body.success === false) reject("Request wasn't successful. Try checking your variables. Message: " + JSON.stringify(body));
resolve(res.body);
});
})
}
exports.getprices = (appid, itemnames, currency) => {
return new Promise((resolve, reject) => {
if (typeof currency !== 'number') {
currency = 1;
}
if(typeof itemnames != 'object'){
if (typeof itemnames == 'string') {
itemnames = [itemnames];
}
}
var tmpres = [];
itemnames.forEach(function(itemname) {
request({
uri: '/market/priceoverview',
baseUrl: 'http://steamcommunity.com/',
json: true,
qs: {
currency: currency,
appid: appid,
market_hash_name: itemname
}
}, (err, res, body) => {
if(err) reject(err);
tmpres.push(body);
if(tmpres.length == itemnames.length){
resolve(tmpres);
}
});
});
});
}