-
Notifications
You must be signed in to change notification settings - Fork 0
/
battlelog.js
66 lines (60 loc) · 2.27 KB
/
battlelog.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
var config = require('./config').Configuration;
var weapon = require('./object/weapon');
var soldier = require('./object/soldier');
var locallog = require('./locallog');
var request = require('request');
var templateName;
module.exports = {
getSoldier: function (callback) {
request.get(
config.baseUri + '/soldier/' + config.userName + '/stats/' + config.userId + '/ps3/', {
headers: {
'X-AjaxNavigation': '1'
}
},
function (err, res) {
if (res != null) {
var body = JSON.parse(res.body);
if (body.template != null) {
var templateRegExp = /profile.(.*)stats/gi;
templateName = templateRegExp.exec(body.template)[1];
callback();
}
}
}
)
},
getWeaponStats: function (callback) {
var weaponStats = [];
request.post(
config.baseUri + templateName + 'WeaponsPopulateStats/' + config.userId + '/4/stats/',
function (err, res) {
if (res != null) {
var body = JSON.parse(res.body);
body.data.mainWeaponStats.forEach(function (element) {
var w = weapon.getWeapon(element);
weaponStats.push(w);
}, this);
//locallog.saveObject(JSON.stringify(weaponStats), config.localWeaponFile);
callback(weaponStats);
} else {
console.log(err);
}
}
);
},
getSoldierStats: function (callback) {
request.post(
config.baseUri + templateName + 'overviewpopulate/' + config.userId + '/4/',
function (err, res) {
if (res != null) {
var body = JSON.parse(res.body);
//locallog.saveObject(JSON.stringify(body), config.localSoldierFile);
callback(soldier.getSoldier(body.data.overviewStats));
} else {
console.log(err);
}
}
)
}
}