-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (64 loc) · 1.64 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
61
62
63
64
65
66
67
68
69
70
71
72
73
var util = require('util');
var request = require('request');
var SteamID = require('steamid');
// Main API object
var SteamRepAPI = {
_API_URL: 'http://steamrep.com/id2rep.php',
_PROFILE_URL: 'http://steamrep.com/api/beta4/reputation/%s',
// default timeout value
timeout: 10000
};
/**
* Static method which checks user's "SCAMMER" status.
* @param {string} steamID User's SteamID64 as string.
* @param {function} callback Callback function.
*/
SteamRepAPI.isScammer = function(steamID, callback) {
var steamID32 = new SteamID(steamID);
var options = {
url: this._API_URL,
method: 'GET',
timeout: this.timeout,
qs: {
steamID32: steamID32.getSteam2RenderedID()
}
};
request(options, function(error, response, body) {
if(!error && response.statusCode === 200) {
if(body.toLowerCase().indexOf('scammer') > -1) {
callback(null, true);
} else {
callback(null, false);
}
} else {
callback(error, null);
}
});
};
/**
* Returns users's extended SteamRep profile.
* @param {string} steamID User's SteamID64 as string.
* @param {function} callback Callback function.
*/
SteamRepAPI.getProfile = function(steamID, callback) {
var finalUrl = util.format(this._PROFILE_URL, steamID);
var options = {
url: finalUrl,
method: 'GET',
timeout: this.timeout,
json: true,
qs: {
json: 1,
extended: 1
}
};
request(options, function(error, response, body) {
if(!error && response.statusCode === 200) {
callback(null, body);
} else {
callback(error, null);
}
});
};
// Export API object
module.exports = SteamRepAPI;