-
Notifications
You must be signed in to change notification settings - Fork 37
/
api.js
43 lines (34 loc) · 1.08 KB
/
api.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
const fetch = require('node-fetch');
const fs = require('fs');
async function tempLog(log) {
fs.appendFile('log.txt', log + '\n', function (err) {
//console.log('LogError', log);
});
}
async function getPossibleTeams(matchDetails) {
try {
const response = await fetch(process.env.API_URL + 'get_team/', {
method: 'post',
body: JSON.stringify(matchDetails),
headers: {'Content-Type': 'application/json'}
});
var dataRaw = await response.text();
if (process.env.DEBUG === 'true') {
tempLog('--------------------------------------------------------');
tempLog(JSON.stringify(matchDetails));
tempLog('response:');
tempLog(dataRaw);
tempLog('--------------------------------------------------------');
}
const data = JSON.parse(dataRaw);
return data;
} catch(e) {
console.log('API Error', e);
}
return false;
}
async function reportLoss(username) {
fetch(process.env.API_URL + 'report_loss/' + username + "/" + process.env.ACCUSERNAME.split('@')[0]);
}
exports.getPossibleTeams = getPossibleTeams;
exports.reportLoss = reportLoss;