-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathriotapi.js
219 lines (170 loc) · 4.88 KB
/
riotapi.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
const https = require('https');
var api_key = "RGAPI-b421ee20-69b1-40dd-b009-7d4d0e5fc0a2";
var gamesPerUpdate = 10;
/*
VIEW
0 requests
VIEW (if doesnt exists in db)
2 requests (profile, leagues)
UPDATE
2 requests (profile, leagues)
1 request (list of 10 matchIds)
10 requests (match-data)
= 13
*/
/*
RATE LIMITS
20 requests every 1 seconds(s)
100 requests every 2 minutes(s)
Note that rate limits are enforced per routing value (e.g., na1, euw1, americas).
*/
var rateLimitsPerSecond = 20;
var rateLimitPerTwoMinutes = 100;
var requests = 0;
var lastUpdate = 0;
// TODO (not mandatory atm)
module.exports = {
getSummonerByName: function(name){
//console.log(name);
return RiotAPI_getSummonerByName(name);
},
getListOfMatchIds: function(puuid){
return RiotAPI_getListOfMatchIds(puuid);
},
getMatchDetails: function(matchId){
return RiotAPI_getMatchDetails(matchId);
},
getLeagueEntriesInAllQueues: function(id){
return RiotAPI_getLeagueEntriesInAllQueues(id);
},
getRequestsCount: function(){
return requests;
}
}
async function RiotAPI_getSummonerByName(nameVar) {
return new Promise ((resolve, reject) => {
var url = encodeURI('/lol/summoner/v4/summoners/by-name/'+nameVar);
requests++;
const options = {
hostname: 'eun1.api.riotgames.com',
port: 443,
path: url,
method: 'GET',
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9,pl;q=0.86",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
'Origin': 'https://developer.riotgames.com',
'Content-Type': 'application/json',
'X-Riot-Token': api_key
}
};
let req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
resolve(JSON.parse(d));
});
});
req.on('error', error => {
console.error(error);
reject(error);
});
req.end();
});
};
async function RiotAPI_getLeagueEntriesInAllQueues(id) {
return new Promise ((resolve, reject) => {
var url = encodeURI('/lol/league/v4/entries/by-summoner/'+id);
requests++;
const options = {
hostname: 'eun1.api.riotgames.com',
port: 443,
path: url,
method: 'GET',
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9,pl;q=0.86",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
'Origin': 'https://developer.riotgames.com',
'Content-Type': 'application/json',
'X-Riot-Token': api_key
}
};
let req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
resolve(JSON.parse(d));
});
});
req.on('error', error => {
console.error(error);
reject(error);
});
req.end();
});
};
async function RiotAPI_getListOfMatchIds(puuid) {
return new Promise ((resolve, reject) => {
var url = encodeURI('/lol/match/v5/matches/by-puuid/'+puuid+'/ids?start=0&count='+gamesPerUpdate);
requests++;
const options = {
hostname: 'europe.api.riotgames.com',
port: 443,
path: url,
method: 'GET',
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9,pl;q=0.86",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
'Origin': 'https://developer.riotgames.com',
'Content-Type': 'application/json',
'X-Riot-Token': api_key
}
};
let req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
resolve(JSON.parse(d));
});
});
req.on('error', error => {
console.error(error);
reject(error);
});
req.end();
});
};
async function RiotAPI_getMatchDetails(matchId) {
return new Promise ((resolve, reject) => {
var url = encodeURI('/lol/match/v5/matches/' + matchId);
requests++;
const options = {
hostname: 'europe.api.riotgames.com',
port: 443,
path: url,
method: 'GET',
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9,pl;q=0.86",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
'Origin': 'https://developer.riotgames.com',
'Content-Type': 'application/json',
'X-Riot-Token': api_key
}
};
var req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`);
var d = "";
res.on('data', function(chunk) {
d += chunk;
}).on('end', function() {
resolve(d);
});
});
req.on('error', error => {
console.error(error);
reject(error);
});
req.end();
});
};