-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
103 lines (93 loc) · 1.79 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const request = require('request-promise-native');
const moment = require('moment');
class AgentStats {
constructor(api_key) {
this.apiKey = api_key;
this.apiBase = 'https://api.agent-stats.com/';
}
getGroups() {
return request.get({
uri: `${this.apiBase}groups`,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getPending(group_id) {
return request.get({
uri: `${this.apiBase}groups/${group_id}/pending`,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getGroupProgress(group_id, type) {
let uri = `${this.apiBase}groups/${group_id}`;
if (type){
uri = `${uri}/${type}`;
}
return request.get({
uri: uri,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getShares() {
return request.get({
uri: `${this.apiBase}share`,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getShare(username, startdate) {
let uri = `${this.apiBase}share/${username}`;
if (startdate && startdate instanceof Date) {
uri = `${uri}/${moment(startdate).format('YYYY-MM-DD')}`;
}
return request.get({
uri: uri,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getMedals() {
return request.get({
uri: `${this.apiBase}medals`,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
getProgress(startdate) {
let uri = `${this.apiBase}progress`;
if (startdate && startdate instanceof Date) {
uri = `${uri}/${moment(startdate).format('YYYY-MM-DD')}`;
}
return request.get({
uri: uri,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
requestGroupRefresh(group_id) {
return request.post({
uri: `${this.apiBase}groups/${group_id}/refresh`,
headers: {
'AS-Key': this.apiKey
},
json: true
});
}
}
module.exports = AgentStats;