forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessApi.js
48 lines (48 loc) · 1.67 KB
/
processApi.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
var utility = require('./utility');
var async = require('async');
var logger = utility.logger;
var getData = utility.getData;
var operations = require('./operations');
var insertPlayer = operations.insertPlayer;
var insertMatch = operations.insertMatch;
var insertMatchProgress = operations.insertMatchProgress;
module.exports = function processApi(job, cb) {
var payload = job.data.payload;
job.progress(0, 100, "Getting basic match data from Steam API...");
getData(job.data.url, function(err, body) {
if (err) {
//couldn't get data from api, non-retryable
return cb(JSON.stringify(err));
}
else if (body.response) {
logger.info("summaries response");
async.mapSeries(body.response.players, insertPlayer, function(err) {
return cb(err, body.response.players);
});
}
else if (payload.match_id) {
logger.info("details response");
var match = body.result;
//join payload with match
for (var prop in payload) {
match[prop] = (prop in match) ? match[prop] : payload[prop];
}
job.progress(0, 100, "Received basic match data.");
//we want to try to parse this match
match.parse_status = 0;
if (match.request) {
insertMatchProgress(match, job, function(err) {
cb(err);
});
}
else {
insertMatch(match, function(err) {
cb(err);
});
}
}
else {
return cb("unknown response");
}
});
};