lol-api-js
Version:
Integration package LoL Riot API and your typescript/javascript
209 lines • 10.5 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = __importDefault(require("axios"));
var _1 = __importDefault(require("."));
var league_1 = __importDefault(require("./league"));
var match_1 = __importDefault(require("./match"));
var Summoner = /** @class */ (function (_super) {
__extends(Summoner, _super);
function Summoner(api_key, path, jsonObj, leagueArr, champMastObj, matchIds) {
var _this = _super.call(this, api_key, path) || this;
/**
* Returns the path to the icon location`
*
* @returns A @var string that represents a path to an `.png`
*
* @remarks
* This method is part of lol-api-js package and Summoner class
*
* @example
* summoner = new Summoner();
* summoner.get(summonerName);
* summoner.getProfileIcon();
*/
_this.getProfileIcon = function () {
var iconUrl = _this.dataPath + "/11.19.1/img/profileicon/";
return iconUrl + _this.profileIconId + ".png";
};
/**
* Returns a Match object with match details for a given matchId.
*
* @remarks
* This method is part of lol-api-js package from the Match class
*
* @param matchId - matchId that can be acessed through:
*
* ```
* summoner = new Summoner();
* summoner.get(summonerName);
* arrayOfMatchIds = summoner.getMatchIds();
* ```
*
* @example
* match = new Match();
* match.getMatch(matchId);
*/
_this.getMatch = function (matchId) { return __awaiter(_this, void 0, void 0, function () {
var url, resp, data, participants, metadata, _a, info;
var _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
url = this.buildUrl(matchUrl, matchId, {});
return [4 /*yield*/, axios_1.default.get(url)];
case 1:
resp = _c.sent();
data = resp.data;
participants = this.getInvolvedSummoners(data.metadata.participants);
_a = [__assign({}, data.metadata)];
_b = {};
return [4 /*yield*/, participants];
case 2:
metadata = __assign.apply(void 0, _a.concat([(_b.participants = _c.sent(), _b)]));
info = data.info;
return [2 /*return*/, new match_1.default(this.key, this.dataPath, metadata, info)];
}
});
}); };
/**
* Returns an Array of Summoners object with summoners details.
*
* @remarks
* This method is part of lol-api-js package from the Match class
*
* @async
* @param participants
* array of strings (Participant interface)
*
* @returns
* Returns an array of Summoners object.
*
* @private
* This is a private method, it cannot be called outside of its class
*
*/
_this.getInvolvedSummoners = function (participants) { return __awaiter(_this, void 0, void 0, function () {
var summonerUrls, summoners;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
summonerUrls = participants.map(function (puuid) {
return _this.buildUrl(summonerFromPuuid, puuid, {});
});
summoners = summonerUrls.map(function (url) { return __awaiter(_this, void 0, void 0, function () {
var resp, data, leagueData, champMastData, matchIds, _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, axios_1.default.get(url)];
case 1:
resp = _c.sent();
data = resp.data;
leagueData = this.getLeagues(data.id);
champMastData = this.getChampionMastery(data.id);
matchIds = this.getMatchIds(data.puuid, {});
_a = Summoner.bind;
_b = [void 0, this.key,
this.dataPath,
data];
return [4 /*yield*/, leagueData];
case 2:
_b = _b.concat([_c.sent()]);
return [4 /*yield*/, champMastData];
case 3:
_b = _b.concat([_c.sent()]);
return [4 /*yield*/, matchIds];
case 4: return [2 /*return*/, new (_a.apply(Summoner, _b.concat([_c.sent()])))()];
}
});
}); });
return [4 /*yield*/, Promise.all(summoners)];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// console.log("called");
_this.id = jsonObj.id;
_this.accountId = jsonObj.accountId;
_this.profileIconId = jsonObj.profileIconId;
_this.revisionDate = jsonObj.revisionDate;
_this.name = jsonObj.name;
_this.puuid = jsonObj.puuid;
_this.summonerLevel = jsonObj.summonerLevel;
_this.championMasteryArray = champMastObj;
_this.rankedSolo = new league_1.default(leagueArr[0]);
_this.rankedFlex = new league_1.default(leagueArr[1]);
_this.matchIds = matchIds;
return _this;
}
return Summoner;
}(_1.default));
exports.default = Summoner;
var matchUrl = "https://americas.api.riotgames.com/lol/match/v5/matches/";
var summonerFromPuuid = "https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-puuid/";
//# sourceMappingURL=summoner.js.map
;