UNPKG

riot-api-stats

Version:

Riot API Stats service

37 lines (28 loc) 2.17 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _axios = require('axios');var _axios2 = _interopRequireDefault(_axios); var _promise = require('./promise');var _promise2 = _interopRequireDefault(_promise);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new _promise2.default(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return _promise2.default.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};} const http = require('http'); const https = require('https'); const agentOptions = { keepAlive: true, keepAliveMsecs: 5000, maxFreeSockets: 10, maxSockets: 10000, maxCachedSessions: 10000 }; const instance = _axios2.default.create({ httpAgent: new http.Agent(agentOptions), httpsAgent: new https.Agent(agentOptions) });exports.default = { getFromMatchlist: (() => {var _ref = _asyncToGenerator(function* (matchlist, region = 'euw') { const matchRequests = matchlist.map(function ({ matchId }) {return _promise2.default.resolve(instance.get( `https://${region}.api.riotgames.com/api/lol/${region.toUpperCase()}/v2.2/match/${matchId}?api_key=${process.env.RIOT_API_KEY}`) // .then((data) => { console.log(`[${process.pid}] Match ${data.data.matchId}`); return data; }) );}); // Take only those matches that returned 200 http status code const matches = yield _promise2.default. all(matchRequests.map(function (p) {return p.reflect();})). then(function (inspections) { return inspections.filter(function (p) {return p.isFulfilled();}).map(function (p) {return p.value();}); }). then(function (matchResponses) {return matchResponses.map(function ({ data }) {return data;});}); return matches; });return function getFromMatchlist(_x) {return _ref.apply(this, arguments);};})() };