kindred-api
Advanced tools
Comparing version 1.0.9 to 1.1.0
@@ -257,3 +257,3 @@ (function (global, factory) { | ||
value: function _baseRequest(_ref2, cb) { | ||
var _this2 = this; | ||
var _this = this; | ||
@@ -283,9 +283,8 @@ var endUrl = _ref2.endUrl, | ||
if (this.limits) { | ||
(function sendRequest() { | ||
var _this = this; | ||
if (this.canMakeRequest(region)) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
this.limits[region][0].addRequest(); | ||
this.limits[region][1].addRequest(); | ||
self.limits[region][0].addRequest(); | ||
self.limits[region][1].addRequest(); | ||
} | ||
@@ -300,3 +299,3 @@ | ||
if (_this.debug) { | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl); | ||
@@ -312,18 +311,24 @@ console.log({ | ||
if (statusCode >= 500 && _this.limits) { | ||
if (_this.debug) console.log('!!! resending request !!!'); | ||
setTimeout(sendRequest.bind(_this), 1000); | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!'); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
if (statusCode === 429 && _this.limits) { | ||
if (_this.debug) console.log('!!! resending request !!!'); | ||
setTimeout(sendRequest.bind(_this), response.headers['retry-after'] * 1000 + 50); | ||
if (statusCode === 429) { | ||
if (self.debug) console.log('!!! resending request !!!'); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, response.headers['retry-after'] * 1000 + 50); | ||
} | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl));else return cb(error, JSON.parse(body)); | ||
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl));else return callback(error, JSON.parse(body)); | ||
}); | ||
} else { | ||
setTimeout(sendRequest.bind(this), 1000); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
}).bind(this)(reqUrl, options); | ||
})(cb); | ||
} else { | ||
@@ -337,3 +342,3 @@ request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
if (_this2.debug) { | ||
if (_this.debug) { | ||
console.log(response && statusMessage, reqUrl); | ||
@@ -561,3 +566,3 @@ console.log({ | ||
value: function getChampMasteries() { | ||
var _this3 = this; | ||
var _this2 = this; | ||
@@ -586,4 +591,4 @@ var _ref19 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this3._championMasteryRequest({ | ||
endUrl: _location + '/player/' + data[_this3._sanitizeName(name)].id + '/champions', | ||
return _this2._championMasteryRequest({ | ||
endUrl: _location + '/player/' + data[_this2._sanitizeName(name)].id + '/champions', | ||
region: region | ||
@@ -599,3 +604,3 @@ }, cb); | ||
value: function getTotalChampMasteryScore() { | ||
var _this4 = this; | ||
var _this3 = this; | ||
@@ -624,4 +629,4 @@ var _ref20 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this4._championMasteryRequest({ | ||
endUrl: _location2 + '/player/' + data[_this4._sanitizeName(name)].id + '/score', | ||
return _this3._championMasteryRequest({ | ||
endUrl: _location2 + '/player/' + data[_this3._sanitizeName(name)].id + '/score', | ||
region: region | ||
@@ -637,3 +642,3 @@ }, cb); | ||
value: function getTopChamps() { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -662,4 +667,4 @@ var _ref21 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this5._championMasteryRequest({ | ||
endUrl: _location3 + '/player/' + data[_this5._sanitizeName(name)].id + '/topchampions', | ||
return _this4._championMasteryRequest({ | ||
endUrl: _location3 + '/player/' + data[_this4._sanitizeName(name)].id + '/topchampions', | ||
region: region | ||
@@ -675,3 +680,3 @@ }, cb); | ||
value: function getCurrentGame() { | ||
var _this6 = this; | ||
var _this5 = this; | ||
@@ -698,4 +703,4 @@ var _ref22 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this6._currentGameRequest({ | ||
endUrl: '' + data[_this6._sanitizeName(name)].id, platformId: platformId, region: region | ||
return _this5._currentGameRequest({ | ||
endUrl: '' + data[_this5._sanitizeName(name)].id, platformId: platformId, region: region | ||
}, cb); | ||
@@ -723,3 +728,3 @@ }); | ||
value: function getRecentGames() { | ||
var _this7 = this; | ||
var _this6 = this; | ||
@@ -743,4 +748,4 @@ var _ref24 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this7._gameRequest({ | ||
endUrl: 'by-summoner/' + data[_this7._sanitizeName(name)].id + '/recent', region: region | ||
return _this6._gameRequest({ | ||
endUrl: 'by-summoner/' + data[_this6._sanitizeName(name)].id + '/recent', region: region | ||
}, cb); | ||
@@ -755,3 +760,3 @@ }); | ||
value: function getLeagues() { | ||
var _this8 = this; | ||
var _this7 = this; | ||
@@ -795,3 +800,3 @@ var _ref25 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
args.push(data[_this8._sanitizeName(_name)].id); | ||
args.push(data[_this7._sanitizeName(_name)].id); | ||
} | ||
@@ -813,3 +818,3 @@ } catch (err) { | ||
return _this8._leagueRequest({ endUrl: 'by-summoner/' + args.join(','), region: region }, cb); | ||
return _this7._leagueRequest({ endUrl: 'by-summoner/' + args.join(','), region: region }, cb); | ||
}); | ||
@@ -820,4 +825,4 @@ } else if (_typeof(arguments[0]) === 'object' && (typeof names === 'string' || typeof name === 'string')) { | ||
return _this8._leagueRequest({ | ||
endUrl: 'by-summoner/' + data[_this8._sanitizeName(names || name)].id, | ||
return _this7._leagueRequest({ | ||
endUrl: 'by-summoner/' + data[_this7._sanitizeName(names || name)].id, | ||
region: region | ||
@@ -833,3 +838,3 @@ }, cb); | ||
value: function getLeagueEntries() { | ||
var _this9 = this; | ||
var _this8 = this; | ||
@@ -873,3 +878,3 @@ var _ref26 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
args.push(data[_this9._sanitizeName(_name2)].id); | ||
args.push(data[_this8._sanitizeName(_name2)].id); | ||
} | ||
@@ -891,3 +896,3 @@ } catch (err) { | ||
return _this9._leagueRequest({ endUrl: 'by-summoner/' + args.join(',') + '/entry', region: region }, cb); | ||
return _this8._leagueRequest({ endUrl: 'by-summoner/' + args.join(',') + '/entry', region: region }, cb); | ||
}); | ||
@@ -897,4 +902,4 @@ } else if (_typeof(arguments[0]) === 'object' && (typeof names === 'string' || typeof name === 'string')) { | ||
if (err) return cb(err); | ||
return _this9._leagueRequest({ | ||
endUrl: 'by-summoner/' + data[_this9._sanitizeName(names || name)].id + '/entry', | ||
return _this8._leagueRequest({ | ||
endUrl: 'by-summoner/' + data[_this8._sanitizeName(names || name)].id + '/entry', | ||
region: region | ||
@@ -1176,3 +1181,3 @@ }, cb); | ||
value: function getMatchList() { | ||
var _this10 = this; | ||
var _this9 = this; | ||
@@ -1198,4 +1203,4 @@ var _ref47 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this10._matchListRequest({ | ||
endUrl: '' + data[_this10._sanitizeName(name)].id, | ||
return _this9._matchListRequest({ | ||
endUrl: '' + data[_this9._sanitizeName(name)].id, | ||
region: region, options: options | ||
@@ -1211,3 +1216,3 @@ }, cb); | ||
value: function getRunes() { | ||
var _this11 = this; | ||
var _this10 = this; | ||
@@ -1251,3 +1256,3 @@ var _ref48 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
args.push(data[_this11._sanitizeName(_name3)].id); | ||
args.push(data[_this10._sanitizeName(_name3)].id); | ||
} | ||
@@ -1269,3 +1274,3 @@ } catch (err) { | ||
return _this11._runesMasteriesRequest({ | ||
return _this10._runesMasteriesRequest({ | ||
endUrl: args.join(',') + '/runes', | ||
@@ -1278,4 +1283,4 @@ region: region | ||
if (err) return cb(err); | ||
return _this11._runesMasteriesRequest({ | ||
endUrl: data[_this11._sanitizeName(names || name)].id + '/runes', | ||
return _this10._runesMasteriesRequest({ | ||
endUrl: data[_this10._sanitizeName(names || name)].id + '/runes', | ||
region: region | ||
@@ -1291,3 +1296,3 @@ }, cb); | ||
value: function getMasteries() { | ||
var _this12 = this; | ||
var _this11 = this; | ||
@@ -1331,3 +1336,3 @@ var _ref49 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
args.push(data[_this12._sanitizeName(_name4)].id); | ||
args.push(data[_this11._sanitizeName(_name4)].id); | ||
} | ||
@@ -1349,3 +1354,3 @@ } catch (err) { | ||
return _this12._runesMasteriesRequest({ | ||
return _this11._runesMasteriesRequest({ | ||
endUrl: args.join(',') + '/masteries', | ||
@@ -1358,4 +1363,4 @@ region: region | ||
if (err) return cb(err); | ||
return _this12._runesMasteriesRequest({ | ||
endUrl: data[_this12._sanitizeName(names || name)].id + '/masteries', | ||
return _this11._runesMasteriesRequest({ | ||
endUrl: data[_this11._sanitizeName(names || name)].id + '/masteries', | ||
region: region | ||
@@ -1371,3 +1376,3 @@ }, cb); | ||
value: function getRankedStats() { | ||
var _this13 = this; | ||
var _this12 = this; | ||
@@ -1392,4 +1397,4 @@ var _ref50 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this13._statsRequest({ | ||
endUrl: data[_this13._sanitizeName(name)].id + '/ranked', | ||
return _this12._statsRequest({ | ||
endUrl: data[_this12._sanitizeName(name)].id + '/ranked', | ||
region: region, options: options | ||
@@ -1405,3 +1410,3 @@ }, cb); | ||
value: function getStatsSummary() { | ||
var _this14 = this; | ||
var _this13 = this; | ||
@@ -1426,4 +1431,4 @@ var _ref51 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
if (err) return cb(err); | ||
return _this14._statsRequest({ | ||
endUrl: data[_this14._sanitizeName(name)].id + '/summary', | ||
return _this13._statsRequest({ | ||
endUrl: data[_this13._sanitizeName(name)].id + '/summary', | ||
region: region, options: options | ||
@@ -1439,3 +1444,3 @@ }, cb); | ||
value: function getSummoners() { | ||
var _this15 = this; | ||
var _this14 = this; | ||
@@ -1468,3 +1473,3 @@ var _ref52 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
endUrl: 'by-name/' + names.map(function (name) { | ||
return _this15._sanitizeName(name); | ||
return _this14._sanitizeName(name); | ||
}).join(','), | ||
@@ -1471,0 +1476,0 @@ region: region |
@@ -1,1 +0,1 @@ | ||
!function(e,r){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp"],r);else if("undefined"!=typeof exports)r(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"));else{var t={exports:{}};r(t,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=t.exports}}(this,function(e,r,t,n,i){"use strict";function o(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),u=function(){function e(t,n){o(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new r}return a(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=1e3*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+(1e3*this.seconds+1e3*this.seconds/75))}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length<this.allowedRequests}}]),e}(),l={BRAZIL:"BR1",EUROPE:"EUN1",EUROPE_WEST:"EUW1",KOREA:"KR",LATIN_AMERICA_NORTH:"LA1",LATIN_AMERICA_SOUTH:"LA2",NORTH_AMERICA:"NA1",OCEANIA:"OC1",RUSSIA:"RU",TURKEY:"TR1",JAPAN:"JP1"},m={BRAZIL:"br",EUROPE:"eune",EUROPE_WEST:"euw",KOREA:"kr",LATIN_AMERICA_NORTH:"lan",LATIN_AMERICA_SOUTH:"las",NORTH_AMERICA:"na",OCEANIA:"oce",RUSSIA:"ru",TURKEY:"tr",JAPAN:"jp"},g={br:"BRAZIL",eune:"EUROPE",euw:"EUROPE_WEST",kr:"KOREA",lan:"LATIN_AMERICA_NORTH",las:"LATIN_AMERICA_SOUTH",na:"NORTH_AMERICA",oce:"OCEANIA",ru:"RUSSIA",tr:"TURKEY",jp:"JAPAN"},d={CHAMPION:1.2,CURRENT_GAME:1,FEATURED_GAMES:1,GAME:1.3,LEAGUE:2.5,STATIC_DATA:1.2,STATUS:1,MATCH:2.2,MATCH_LIST:2.2,RUNES_MASTERIES:1.4,STATS:1.3,SUMMONER:1.4},h={int:function(e){return e.every(function(e){return Number.isInteger(e)})},string:function(e){return e.every(function(e){return"string"==typeof e})}},p={int:function(e){return e&&Array.isArray(e)&&h.int(e)&&e.length>0},string:function(e){return e&&Array.isArray(e)&&h.string(e)&&e.length>0}},y={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},c=function(e){var r=y[e];if(r)return r},v=i("^[0-9\\p{L} _\\.]+$"),f=function(){function e(r){var t=r.key,n=r.defaultRegion,i=void 0===n?m.NORTH_AMERICA:n,s=r.debug,a=void 0!==s&&s,l=r.limits;if(o(this,e),this.key=t,this.defaultRegion=i,this.debug=a,l){this.limits={};var g=!0,d=!1,h=void 0;try{for(var p,y=Object.keys(m)[Symbol.iterator]();!(g=(p=y.next()).done);g=!0){var c=p.value;this.limits[m[c]]=[new u(l[0][0],l[0][1]),new u(l[1][0],l[1][1])]}}catch(e){d=!0,h=e}finally{try{!g&&y.return&&y.return()}finally{if(d)throw h}}}}return a(e,[{key:"canMakeRequest",value:function(e){return!(!this.limits[e][0].requestAvailable()||!this.limits[e][1].requestAvailable())}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+n.yellow(e)+" is not valid. Request failed."),process.exit(1)}},{key:"_validName",value:function(e){return v.test(e)}},{key:"_makeUrl",value:function(e,r,t,n,i,o){var s=t?"":r+"/";return"https://"+r+".api.riotgames.com/"+(n||i||o?"":"api/lol/"+s)+encodeURI(e)+"?api_key="+this.key}},{key:"_baseRequest",value:function(e,r){var i=this,o=e.endUrl,s=e.region,a=void 0===s?this.defaultRegion:s,u=e.status,l=void 0!==u&&u,m=e.observerMode,g=void 0!==m&&m,d=e.staticReq,h=void 0!==d&&d,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v,R=h?"global":a,I=this._makeUrl(o,R,h,l,g,y);if(!r)return void console.log(n.red("error: No callback passed in for the method call regarding `"+n.yellow(I)+"`"));this.limits?function e(){var i=this;this.canMakeRequest(a)?(h||(this.limits[a][0].addRequest(),this.limits[a][1].addRequest()),t({url:I,qs:f},function(t,o,s){var a=void 0,u=o.statusCode;return u>=200&&u<300?a=n.green(u):u>=400&&u<500?a=n.red(u+" "+c(u)):u>=500&&(a=n.bold.red(u+" "+c(u))),i.debug&&(console.log(a,I),console.log({"x-app-rate-limit-count":o.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":o.headers["x-method-rate-limit-count"],"x-rate-limit-count":o.headers["x-rate-limit-count"],"retry-after":o.headers["retry-after"]}),console.log()),u>=500&&i.limits&&(i.debug&&console.log("!!! resending request !!!"),setTimeout(e.bind(i),1e3)),429===u&&i.limits&&(i.debug&&console.log("!!! resending request !!!"),setTimeout(e.bind(i),1e3*o.headers["retry-after"]+50)),u>=400?r(a+" : "+n.yellow(I)):r(t,JSON.parse(s))})):setTimeout(e.bind(this),1e3)}.bind(this)(I,f):t({url:I,qs:f},function(e,t,o){var s=void 0,a=t.statusCode;return a>=200&&a<300?s=n.green(a):a>=400&&a<500?s=n.red(a+" "+c(a)):a>=500&&(s=n.bold.red(a+" "+c(a))),i.debug&&(console.log(t&&s,I),console.log({"x-app-rate-limit-count":t.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":t.headers["x-method-rate-limit-count"],"x-rate-limit-count":t.headers["x-rate-limit-count"],"retry-after":t.headers["retry-after"]})),a>=400?r(s+" : "+n.yellow(I)):r(e,JSON.parse(o))})}},{key:"_observerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+t,observerMode:!0,region:n},r)}},{key:"_championRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.CHAMPION+"/"+t,region:n,options:i},r)}},{key:"_championMasteryRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+t,options:n,championMastery:!0},r)}},{key:"_currentGameRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+t,region:n},r)}},{key:"_staticRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=void 0===n?this.defaultRegion:n,o=e.options;return this._baseRequest({endUrl:"static-data/"+i+"/v"+d.STATIC_DATA+"/"+t,staticReq:!0,region:i,options:o},r)}},{key:"_statusRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+d.STATUS+"/"+t,status:!0,options:n},r)}},{key:"_gameRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.GAME+"/game/"+t,region:n},r)}},{key:"_leagueRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.LEAGUE+"/league/"+t,region:n,options:i},r)}},{key:"_matchRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH+"/match/"+t,region:n,options:i},r)}},{key:"_matchListRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH_LIST+"/matchlist/by-summoner/"+t,region:n,options:i},r)}},{key:"_runesMasteriesRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._summonerRequest({endUrl:t,region:n},r)}},{key:"_statsRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.STATS+"/stats/by-summoner/"+t,region:n,options:i},r)}},{key:"_summonerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.SUMMONER+"/summoner/"+t,region:n},r)}},{key:"_logError",value:function(e,r){console.log(n.bold.yellow(e),n.red("request"),n.bold.red("FAILED")+n.red("; "+r))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,r){var t=e.region,n=e.options;return this._championRequest({endUrl:"champion",region:t,options:n},r=t||n?r:arguments[0])}},{key:"getChamp",value:function(e,r){var t=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region:t},r):this._logError(this.getChamp.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=void 0===r?this.defaultRegion:r,i=e.playerID,o=e.championID,s=e.options,a=arguments[1];if(Number.isInteger(i)&&Number.isInteger(o)){var u=l[g[t]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:t,options:s},a)}return this._logError(this.getChampMastery.name,"required params "+n.yellow("`playerID` (int) AND `championID` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/champions",region:i},h)})}return this._logError(this.getChampMasteries.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/score",region:i},h)})}return this._logError(this.getTotalChampMasteryScore.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTopChamps",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/topchampions",region:i},h)})}return this._logError(this.getTopChamps.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=arguments[1],h=l[g[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},d):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,t){return r?d(r):e._currentGameRequest({endUrl:""+t[e._sanitizeName(m)].id,platformId:h,region:i},d)}):this._logError(this.getCurrentGame.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._observerRequest({endUrl:"featured",region:r},t=r?t:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=arguments[1];return Number.isInteger(i||o||a)?this._gameRequest({endUrl:"by-summoner/"+(i||o||a)+"/recent",region:t},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?l(r):e._gameRequest({endUrl:"by-summoner/"+n[e._sanitizeName(u)].id+"/recent",region:t},l)}):this._logError(this.getRecentGames.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(","),region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getLeagues.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id,region:t},h)})}},{key:"getLeagueEntries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(",")+"/entry",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getLeagueEntries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id+"/entry",region:t},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:r,options:n},i=r?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"master",region:r,options:n},i=r?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"champion",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"champion/"+(t||i),region:r,options:o},s):this._logError(this.getChampion.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"item",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"item/"+(t||i),region:r,options:o},s):this._logError(this.getItem.name,"required params "+n.yellow("`id/itemID` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"language-strings",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"languages",region:r},t=r?t:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"map",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"mastery",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"mastery/"+(t||i),region:r,options:o},s):this._logError(this.getMastery.name,"required params "+n.yellow("`id/masteryID` (int)")+" not passed in")}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"realm",region:r},t=r?t:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"rune",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"rune/"+(t||i),region:r,options:o},s):this._logError(this.getRune.name,"required params "+n.yellow("`id/runeID` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(t||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(t||i||o),region:r,options:s},a):this._logError(this.getSummonerSpell.name,"required params "+n.yellow("`id/spellID/summonerSpellID` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"versions",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shard",region:r},t=r?t:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shards",region:r},t=r?t:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(t||i)?this._matchRequest({endUrl:""+(t||i),region:r,options:s},a):this._logError(this.getMatch.name,"required params "+n.yellow("`id/matchID` (int)")+" not passed in")}},{key:"getMatchList",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=void 0===l?{rankedQueues:"RANKED_SOLO_5x5"}:l,g=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:t,options:m},g):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?g(r):e._matchListRequest({endUrl:""+n[e._sanitizeName(u)].id,region:t,options:m},g)}):this._logError(this.getMatchList.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/runes",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getRunes.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/runes",region:t},h)})}},{key:"getMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/masteries",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getMasteries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/masteries",region:t},h)})}},{key:"getRankedStats",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/ranked",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/ranked",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/summary",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/summary",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummoners",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:t},h):p.string(g)?this._summonerRequest({endUrl:"by-name/"+g.map(function(r){return e._sanitizeName(r)}).join(","),region:t},h):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getSummoners.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(g||d),region:t},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(t||i||o)?this.getSummoners({region:r,ids:[t||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:r,names:[a]},u):this._logError(this.getSummoner.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummonerNames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(t||o||a)?this._summonerRequest({endUrl:(t||o||a).join(",")+"/name",region:r},l):Number.isInteger(t||i||o||s||a||u)?this._summonerRequest({endUrl:(t||i||o||s||a||u)+"/name",region:r},l):void this._logError(this.getSummonerNames.name,"required params "+n.yellow("required params `ids/summonerIDs/playerIDs` ([int]/int)")+" or "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}},{key:"getSummonerName",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(t))return this.getSummonerNames({region:r,id:t||i||o},s);this._logError(this.getSummonerName.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}(),R={Kindred:f,REGIONS:m};e.exports=R}); | ||
!function(e,r){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp"],r);else if("undefined"!=typeof exports)r(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"));else{var t={exports:{}};r(t,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=t.exports}}(this,function(e,r,t,n,i){"use strict";function o(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),u=function(){function e(t,n){o(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new r}return a(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=1e3*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+(1e3*this.seconds+1e3*this.seconds/75))}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length<this.allowedRequests}}]),e}(),l={BRAZIL:"BR1",EUROPE:"EUN1",EUROPE_WEST:"EUW1",KOREA:"KR",LATIN_AMERICA_NORTH:"LA1",LATIN_AMERICA_SOUTH:"LA2",NORTH_AMERICA:"NA1",OCEANIA:"OC1",RUSSIA:"RU",TURKEY:"TR1",JAPAN:"JP1"},m={BRAZIL:"br",EUROPE:"eune",EUROPE_WEST:"euw",KOREA:"kr",LATIN_AMERICA_NORTH:"lan",LATIN_AMERICA_SOUTH:"las",NORTH_AMERICA:"na",OCEANIA:"oce",RUSSIA:"ru",TURKEY:"tr",JAPAN:"jp"},g={br:"BRAZIL",eune:"EUROPE",euw:"EUROPE_WEST",kr:"KOREA",lan:"LATIN_AMERICA_NORTH",las:"LATIN_AMERICA_SOUTH",na:"NORTH_AMERICA",oce:"OCEANIA",ru:"RUSSIA",tr:"TURKEY",jp:"JAPAN"},d={CHAMPION:1.2,CURRENT_GAME:1,FEATURED_GAMES:1,GAME:1.3,LEAGUE:2.5,STATIC_DATA:1.2,STATUS:1,MATCH:2.2,MATCH_LIST:2.2,RUNES_MASTERIES:1.4,STATS:1.3,SUMMONER:1.4},h={int:function(e){return e.every(function(e){return Number.isInteger(e)})},string:function(e){return e.every(function(e){return"string"==typeof e})}},p={int:function(e){return e&&Array.isArray(e)&&h.int(e)&&e.length>0},string:function(e){return e&&Array.isArray(e)&&h.string(e)&&e.length>0}},y={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},c=function(e){var r=y[e];if(r)return r},v=i("^[0-9\\p{L} _\\.]+$"),f=function(){function e(r){var t=r.key,n=r.defaultRegion,i=void 0===n?m.NORTH_AMERICA:n,s=r.debug,a=void 0!==s&&s,l=r.limits;if(o(this,e),this.key=t,this.defaultRegion=i,this.debug=a,l){this.limits={};var g=!0,d=!1,h=void 0;try{for(var p,y=Object.keys(m)[Symbol.iterator]();!(g=(p=y.next()).done);g=!0){var c=p.value;this.limits[m[c]]=[new u(l[0][0],l[0][1]),new u(l[1][0],l[1][1])]}}catch(e){d=!0,h=e}finally{try{!g&&y.return&&y.return()}finally{if(d)throw h}}}}return a(e,[{key:"canMakeRequest",value:function(e){return!(!this.limits[e][0].requestAvailable()||!this.limits[e][1].requestAvailable())}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+n.yellow(e)+" is not valid. Request failed."),process.exit(1)}},{key:"_validName",value:function(e){return v.test(e)}},{key:"_makeUrl",value:function(e,r,t,n,i,o){var s=t?"":r+"/";return"https://"+r+".api.riotgames.com/"+(n||i||o?"":"api/lol/"+s)+encodeURI(e)+"?api_key="+this.key}},{key:"_baseRequest",value:function(e,r){var i=this,o=e.endUrl,s=e.region,a=void 0===s?this.defaultRegion:s,u=e.status,l=void 0!==u&&u,m=e.observerMode,g=void 0!==m&&m,d=e.staticReq,h=void 0!==d&&d,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v,R=h?"global":a,I=this._makeUrl(o,R,h,l,g,y);if(!r)return void console.log(n.red("error: No callback passed in for the method call regarding `"+n.yellow(I)+"`"));if(this.limits){var _=this;!function e(r){_.canMakeRequest(a)?(h||(_.limits[a][0].addRequest(),_.limits[a][1].addRequest()),t({url:I,qs:f},function(t,i,o){var s=void 0,a=i.statusCode;return a>=200&&a<300?s=n.green(a):a>=400&&a<500?s=n.red(a+" "+c(a)):a>=500&&(s=n.bold.red(a+" "+c(a))),_.debug&&(console.log(s,I),console.log({"x-app-rate-limit-count":i.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":i.headers["x-method-rate-limit-count"],"x-rate-limit-count":i.headers["x-rate-limit-count"],"retry-after":i.headers["retry-after"]}),console.log()),a>=500&&(_.debug&&console.log("!!! resending request !!!"),setTimeout(function(){e.bind(_)(r)},1e3)),429===a&&(_.debug&&console.log("!!! resending request !!!"),setTimeout(function(){e.bind(_)(r)},1e3*i.headers["retry-after"]+50)),a>=400?r(s+" : "+n.yellow(I)):r(t,JSON.parse(o))})):setTimeout(function(){e.bind(_)(r)},1e3)}(r)}else t({url:I,qs:f},function(e,t,o){var s=void 0,a=t.statusCode;return a>=200&&a<300?s=n.green(a):a>=400&&a<500?s=n.red(a+" "+c(a)):a>=500&&(s=n.bold.red(a+" "+c(a))),i.debug&&(console.log(t&&s,I),console.log({"x-app-rate-limit-count":t.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":t.headers["x-method-rate-limit-count"],"x-rate-limit-count":t.headers["x-rate-limit-count"],"retry-after":t.headers["retry-after"]})),a>=400?r(s+" : "+n.yellow(I)):r(e,JSON.parse(o))})}},{key:"_observerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+t,observerMode:!0,region:n},r)}},{key:"_championRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.CHAMPION+"/"+t,region:n,options:i},r)}},{key:"_championMasteryRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+t,options:n,championMastery:!0},r)}},{key:"_currentGameRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+t,region:n},r)}},{key:"_staticRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=void 0===n?this.defaultRegion:n,o=e.options;return this._baseRequest({endUrl:"static-data/"+i+"/v"+d.STATIC_DATA+"/"+t,staticReq:!0,region:i,options:o},r)}},{key:"_statusRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+d.STATUS+"/"+t,status:!0,options:n},r)}},{key:"_gameRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.GAME+"/game/"+t,region:n},r)}},{key:"_leagueRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.LEAGUE+"/league/"+t,region:n,options:i},r)}},{key:"_matchRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH+"/match/"+t,region:n,options:i},r)}},{key:"_matchListRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH_LIST+"/matchlist/by-summoner/"+t,region:n,options:i},r)}},{key:"_runesMasteriesRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._summonerRequest({endUrl:t,region:n},r)}},{key:"_statsRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.STATS+"/stats/by-summoner/"+t,region:n,options:i},r)}},{key:"_summonerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.SUMMONER+"/summoner/"+t,region:n},r)}},{key:"_logError",value:function(e,r){console.log(n.bold.yellow(e),n.red("request"),n.bold.red("FAILED")+n.red("; "+r))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,r){var t=e.region,n=e.options;return this._championRequest({endUrl:"champion",region:t,options:n},r=t||n?r:arguments[0])}},{key:"getChamp",value:function(e,r){var t=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region:t},r):this._logError(this.getChamp.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=void 0===r?this.defaultRegion:r,i=e.playerID,o=e.championID,s=e.options,a=arguments[1];if(Number.isInteger(i)&&Number.isInteger(o)){var u=l[g[t]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:t,options:s},a)}return this._logError(this.getChampMastery.name,"required params "+n.yellow("`playerID` (int) AND `championID` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/champions",region:i},h)})}return this._logError(this.getChampMasteries.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/score",region:i},h)})}return this._logError(this.getTotalChampMasteryScore.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTopChamps",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/topchampions",region:i},h)})}return this._logError(this.getTopChamps.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=arguments[1],h=l[g[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},d):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,t){return r?d(r):e._currentGameRequest({endUrl:""+t[e._sanitizeName(m)].id,platformId:h,region:i},d)}):this._logError(this.getCurrentGame.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._observerRequest({endUrl:"featured",region:r},t=r?t:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=arguments[1];return Number.isInteger(i||o||a)?this._gameRequest({endUrl:"by-summoner/"+(i||o||a)+"/recent",region:t},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?l(r):e._gameRequest({endUrl:"by-summoner/"+n[e._sanitizeName(u)].id+"/recent",region:t},l)}):this._logError(this.getRecentGames.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(","),region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getLeagues.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id,region:t},h)})}},{key:"getLeagueEntries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(",")+"/entry",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getLeagueEntries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id+"/entry",region:t},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:r,options:n},i=r?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"master",region:r,options:n},i=r?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"champion",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"champion/"+(t||i),region:r,options:o},s):this._logError(this.getChampion.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"item",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"item/"+(t||i),region:r,options:o},s):this._logError(this.getItem.name,"required params "+n.yellow("`id/itemID` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"language-strings",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"languages",region:r},t=r?t:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"map",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"mastery",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"mastery/"+(t||i),region:r,options:o},s):this._logError(this.getMastery.name,"required params "+n.yellow("`id/masteryID` (int)")+" not passed in")}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"realm",region:r},t=r?t:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"rune",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"rune/"+(t||i),region:r,options:o},s):this._logError(this.getRune.name,"required params "+n.yellow("`id/runeID` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(t||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(t||i||o),region:r,options:s},a):this._logError(this.getSummonerSpell.name,"required params "+n.yellow("`id/spellID/summonerSpellID` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"versions",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shard",region:r},t=r?t:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shards",region:r},t=r?t:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(t||i)?this._matchRequest({endUrl:""+(t||i),region:r,options:s},a):this._logError(this.getMatch.name,"required params "+n.yellow("`id/matchID` (int)")+" not passed in")}},{key:"getMatchList",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=void 0===l?{rankedQueues:"RANKED_SOLO_5x5"}:l,g=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:t,options:m},g):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?g(r):e._matchListRequest({endUrl:""+n[e._sanitizeName(u)].id,region:t,options:m},g)}):this._logError(this.getMatchList.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/runes",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getRunes.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/runes",region:t},h)})}},{key:"getMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/masteries",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getMasteries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/masteries",region:t},h)})}},{key:"getRankedStats",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/ranked",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/ranked",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/summary",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/summary",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummoners",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:t},h):p.string(g)?this._summonerRequest({endUrl:"by-name/"+g.map(function(r){return e._sanitizeName(r)}).join(","),region:t},h):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getSummoners.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(g||d),region:t},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(t||i||o)?this.getSummoners({region:r,ids:[t||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:r,names:[a]},u):this._logError(this.getSummoner.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummonerNames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(t||o||a)?this._summonerRequest({endUrl:(t||o||a).join(",")+"/name",region:r},l):Number.isInteger(t||i||o||s||a||u)?this._summonerRequest({endUrl:(t||i||o||s||a||u)+"/name",region:r},l):void this._logError(this.getSummonerNames.name,"required params "+n.yellow("required params `ids/summonerIDs/playerIDs` ([int]/int)")+" or "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}},{key:"getSummonerName",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(t))return this.getSummonerNames({region:r,id:t||i||o},s);this._logError(this.getSummonerName.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}(),R={Kindred:f,REGIONS:m};e.exports=R}); |
{ | ||
"name": "kindred-api", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "Kindred is a thin Node.js wrapper on top of Riot Games API for League of Legends", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -80,7 +80,8 @@ const request = require('request') | ||
if (this.limits) { | ||
(function sendRequest() { | ||
if (this.canMakeRequest(region)) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
this.limits[region][0].addRequest() | ||
this.limits[region][1].addRequest() | ||
self.limits[region][0].addRequest() | ||
self.limits[region][1].addRequest() | ||
} | ||
@@ -99,3 +100,3 @@ | ||
if (this.debug) { | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl) | ||
@@ -111,19 +112,21 @@ console.log({ | ||
if (statusCode >= 500 && this.limits) { | ||
if (this.debug) console.log('!!! resending request !!!') | ||
setTimeout(sendRequest.bind(this), 1000) | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
if (statusCode === 429 && this.limits) { | ||
if (this.debug) console.log('!!! resending request !!!') | ||
setTimeout(sendRequest.bind(this), (response.headers['retry-after'] * 1000) + 50) | ||
if (statusCode === 429) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { | ||
sendRequest.bind(self)(callback) | ||
}, (response.headers['retry-after'] * 1000) + 50) | ||
} | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return cb(error, JSON.parse(body)) | ||
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return callback(error, JSON.parse(body)) | ||
}) | ||
} else { | ||
setTimeout(sendRequest.bind(this), 1000) | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
}).bind(this)(reqUrl, options) | ||
})(cb) | ||
} else { | ||
@@ -130,0 +133,0 @@ request({ url: reqUrl, qs: options }, (error, response, body) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
307807
2589