UNPKG

zhonya

Version:

A simple and typed League of Legends API wrapper for Node.js

45 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SummonerService = void 0; const axios_1 = require("axios"); const ZhonyaError_1 = require("../../errors/ZhonyaError"); const utils_1 = require("../../utils"); class SummonerService { constructor(config) { this.config = config; const client = axios_1.default.create({ baseURL: `https://${config.platformRouting}.api.riotgames.com`, headers: { "X-Riot-Token": config.riotApiKey, }, }); this.httpClient = client; } async getSummonerProfileIconUrl(iconId) { const lastVersion = await (0, utils_1.getLastVersion)(); const requestUrl = `http://ddragon.leagueoflegends.com/cdn/${lastVersion}/img/profileicon/${iconId}.png`; return requestUrl; } async getByPuuid(puuid) { try { const response = await this.httpClient.get(`/lol/summoner/v4/summoners/by-puuid/${puuid}`); const responseData = response.data; const profileIconUrl = await this.getSummonerProfileIconUrl(responseData.profileIconId); const summonerData = { id: responseData.id, accountId: responseData.accountId, puuid: responseData.puuid, profileIconId: responseData.profileIconId, revisionDate: new Date(responseData.revisionDate), summonerLevel: responseData.summonerLevel, profileIconUrl: profileIconUrl, }; return summonerData; } catch (error) { throw new ZhonyaError_1.ZhonyaError("Erro ao buscar invocador", error); } } } exports.SummonerService = SummonerService; //# sourceMappingURL=summoner.service.js.map