You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
class LeagueAPI
|
|
{
|
|
constructor()
|
|
{
|
|
this.key = process.env.lolAPIKey || 'RGAPI-fc17a511-f587-495b-ac01-80716870d46b';
|
|
}
|
|
|
|
async verifyUserName(nick, tag)
|
|
{
|
|
var options = {
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers:
|
|
{
|
|
"Origin": "https://developer.riotgames.com",
|
|
"X-Riot-Token": this.key
|
|
}
|
|
}
|
|
var res = await fetch(`https://europe.api.riotgames.com/riot/account/v1/accounts/by-riot-id/${nick}/${tag}`, options)
|
|
.then(handleRes)
|
|
.then(handleData)
|
|
.catch(handleErrors)
|
|
|
|
function handleRes(response)
|
|
{
|
|
return response.text()
|
|
}
|
|
function handleErrors(error)
|
|
{
|
|
return error;
|
|
}
|
|
function handleData(data)
|
|
{
|
|
data = JSON.parse(data);
|
|
return {
|
|
name:data.gameName,
|
|
puuid:data.puuid
|
|
}
|
|
}
|
|
return res.name?res:null;
|
|
}
|
|
}module.exports.LeagueAPI = LeagueAPI |