kindred-api
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -67,3 +67,3 @@ (function (global, factory) { | ||
value: function addRequest() { | ||
this.madeRequests.push(new Date().getTime() + (this.seconds * 1000 + this.seconds * 1000 / 75)); | ||
this.madeRequests.push(new Date().getTime() + this.seconds * 1000); | ||
} | ||
@@ -323,88 +323,104 @@ }, { | ||
var proxy = staticReq ? 'global' : region; | ||
var reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery); | ||
return new Promise(function (resolve, reject) { | ||
var proxy = staticReq ? 'global' : region; | ||
var reqUrl = _this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery); | ||
if (!cb) { | ||
console.log(chalk.red('error: No callback passed in for the method call regarding `' + chalk.yellow(reqUrl) + '`')); | ||
return; | ||
} | ||
if (_this.limits) { | ||
var self = _this; | ||
if (this.limits) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
self.limits[region][0].addRequest(); | ||
self.limits[region][1].addRequest(); | ||
} | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
self.limits[region][0].addRequest(); | ||
self.limits[region][1].addRequest(); | ||
} | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
if (response && body) { | ||
var statusMessage = void 0; | ||
var statusCode = response.statusCode; | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
if (response && body) { | ||
var statusMessage = void 0; | ||
var statusCode = response.statusCode; | ||
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode)); | ||
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode)); | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl); | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}); | ||
console.log(); | ||
} | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl); | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}); | ||
console.log(); | ||
} | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!'); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
if (callback) { | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!'); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
if (statusCode === 429) { | ||
if (self.debug) console.log('!!! resending request !!!'); | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 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 callback(statusMessage + ' : ' + chalk.yellow(reqUrl));else return callback(error, JSON.parse(body)); | ||
} else { | ||
console.log('callback not defined'); | ||
if (error) { | ||
return reject('err:', error); | ||
} else { | ||
return resolve(JSON.parse(body)); | ||
} | ||
} | ||
} else { | ||
console.log(error, reqUrl); | ||
} | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
})(cb); | ||
} else { | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
if (response) { | ||
var statusMessage = void 0; | ||
var statusCode = response.statusCode; | ||
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl));else return callback(error, JSON.parse(body)); | ||
} else { | ||
console.log(error, reqUrl); | ||
} | ||
}); | ||
} else { | ||
setTimeout(function () { | ||
sendRequest.bind(self)(callback); | ||
}, 1000); | ||
} | ||
})(cb); | ||
} else { | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
if (response) { | ||
var statusMessage = void 0; | ||
var statusCode = response.statusCode; | ||
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode)); | ||
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode)); | ||
if (_this.debug) { | ||
console.log(response && statusMessage, reqUrl); | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}); | ||
} | ||
if (_this.debug) { | ||
console.log(response && statusMessage, reqUrl); | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}); | ||
if (cb) { | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl));else return cb(error, JSON.parse(body)); | ||
} else { | ||
if (error) { | ||
return reject('err:', error); | ||
} else { | ||
return resolve(JSON.parse(body)); | ||
} | ||
} | ||
} else { | ||
console.log(error, reqUrl); | ||
} | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl));else return cb(error, JSON.parse(body)); | ||
} else { | ||
console.log(error, reqUrl); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -411,0 +427,0 @@ }, { |
@@ -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"},d={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"},g={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,i=r.defaultRegion,s=void 0===i?m.NORTH_AMERICA:i,a=r.debug,l=void 0!==a&&a,d=r.limits;o(this,e),this.key=t;var g=void 0,h=!0,y=!1,c=void 0;try{for(var v,f=Object.keys(m)[Symbol.iterator]();!(h=(v=f.next()).done);h=!0){var I=v.value;m[I]===s&&(g=!0)}}catch(e){y=!0,c=e}finally{try{!h&&f.return&&f.return()}finally{if(y)throw c}}if(this.defaultRegion=g?s:void 0,this.defaultRegion||(console.log(""+n.red("Initialization of Kindred failed: "+n.yellow(s)+" is an invalid region.")),console.log(""+n.red("Try importing "+n.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead.")),process.exit(1)),this.debug=l,d){(Array.isArray(d)&&2!==d.length||!p.int(d[0])||2!==d[0].length||!p.int(d[1])||2!==d[1].length)&&"dev"!==d&&"prod"!==d&&(console.log(n.red("Initialization of Kindred failed: Invalid "+n.yellow("limits")+". Valid examples: "+n.yellow("[[10, 10], [500, 600]]"))+"."),console.log(n.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+n.red("and Kindred will set the limits appropriately.")),process.exit(1)),this.limits={},"dev"===d&&(d=[[10,10],[500,600]]),"prod"===d&&(d=[[3e3,10],[18e4,600]]);var R=!0,_=!1,q=void 0;try{for(var U,D=Object.keys(m)[Symbol.iterator]();!(R=(U=D.next()).done);R=!0){var b=U.value;this.limits[m[b]]=[new u(d[0][0],d[0][1]),new u(d[1][0],d[1][1])]}}catch(e){_=!0,q=e}finally{try{!R&&D.return&&D.return()}finally{if(_)throw q}}}}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,d=void 0!==m&&m,g=e.staticReq,h=void 0!==g&&g,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v,I=h?"global":a,R=this._makeUrl(o,I,h,l,d,y);if(!r)return void console.log(n.red("error: No callback passed in for the method call regarding `"+n.yellow(R)+"`"));if(this.limits){var _=this;!function e(r){_.canMakeRequest(a)?(h||(_.limits[a][0].addRequest(),_.limits[a][1].addRequest()),t({url:R,qs:f},function(t,i,o){if(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,R),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(R)):r(t,JSON.parse(o))}console.log(t,R)})):setTimeout(function(){e.bind(_)(r)},1e3)}(r)}else t({url:R,qs:f},function(e,t,o){if(t){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,R),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(R)):r(e,JSON.parse(o))}console.log(e,R)})}},{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"+g.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"+g.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"+g.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"+g.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"+g.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"+g.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"+g.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"+g.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"+g.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[d[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,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[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,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[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,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[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,g=arguments[1],h=l[d[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},g):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,t){return r?g(r):e._currentGameRequest({endUrl:""+t[e._sanitizeName(m)].id,platformId:h,region:i},g)}):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,d=r.names,g=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(d)?this.getSummoners({names:d,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[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 d&&"string"!=typeof g?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:d||g,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(d||g)].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,d=r.names,g=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(d)?this.getSummoners({names:d,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[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 d&&"string"!=typeof g?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:d||g,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(d||g)].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,d=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:t,options:m},d):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?d(r):e._matchListRequest({endUrl:""+n[e._sanitizeName(u)].id,region:t,options:m},d)}):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,d=r.names,g=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(d)?this.getSummoners({names:d,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[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 d&&"string"!=typeof g?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:d||g,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(d||g)].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,d=r.names,g=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(d)?this.getSummoners({names:d,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[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 d&&"string"!=typeof g?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:d||g,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(d||g)].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,d=r.names,g=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(d)?this._summonerRequest({endUrl:"by-name/"+d.map(function(r){return e._sanitizeName(r)}).join(","),region:t},h):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?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(d||g),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}(),I={Kindred:f,REGIONS:m};e.exports=I}); | ||
!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 n={exports:{}};r(n,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=n.exports}}(this,function(e,r,n,t,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 n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(r,n,t){return n&&e(r.prototype,n),t&&e(r,t),r}}(),u=function(){function e(n,t){o(this,e),this.allowedRequests=n,this.seconds=t,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)}},{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"},d={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"},g={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 n=r.key,i=r.defaultRegion,s=void 0===i?m.NORTH_AMERICA:i,a=r.debug,l=void 0!==a&&a,d=r.limits;o(this,e),this.key=n;var g=void 0,h=!0,y=!1,c=void 0;try{for(var v,f=Object.keys(m)[Symbol.iterator]();!(h=(v=f.next()).done);h=!0){var I=v.value;m[I]===s&&(g=!0)}}catch(e){y=!0,c=e}finally{try{!h&&f.return&&f.return()}finally{if(y)throw c}}if(this.defaultRegion=g?s:void 0,this.defaultRegion||(console.log(""+t.red("Initialization of Kindred failed: "+t.yellow(s)+" is an invalid region.")),console.log(""+t.red("Try importing "+t.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead.")),process.exit(1)),this.debug=l,d){(Array.isArray(d)&&2!==d.length||!p.int(d[0])||2!==d[0].length||!p.int(d[1])||2!==d[1].length)&&"dev"!==d&&"prod"!==d&&(console.log(t.red("Initialization of Kindred failed: Invalid "+t.yellow("limits")+". Valid examples: "+t.yellow("[[10, 10], [500, 600]]"))+"."),console.log(t.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+t.red("and Kindred will set the limits appropriately.")),process.exit(1)),this.limits={},"dev"===d&&(d=[[10,10],[500,600]]),"prod"===d&&(d=[[3e3,10],[18e4,600]]);var R=!0,_=!1,q=void 0;try{for(var U,D=Object.keys(m)[Symbol.iterator]();!(R=(U=D.next()).done);R=!0){var b=U.value;this.limits[m[b]]=[new u(d[0][0],d[0][1]),new u(d[1][0],d[1][1])]}}catch(e){_=!0,q=e}finally{try{!R&&D.return&&D.return()}finally{if(_)throw q}}}}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 "+t.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,n,t,i,o){var s=n?"":r+"/";return"https://"+r+".api.riotgames.com/"+(t||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,d=void 0!==m&&m,g=e.staticReq,h=void 0!==g&&g,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v;return new Promise(function(e,s){var u=h?"global":a,m=i._makeUrl(o,u,h,l,d,y);if(i.limits){var g=i;!function r(i){g.canMakeRequest(a)?(h||(g.limits[a][0].addRequest(),g.limits[a][1].addRequest()),n({url:m,qs:f},function(n,o,a){if(o&&a){var u=void 0,l=o.statusCode;return l>=200&&l<300?u=t.green(l):l>=400&&l<500?u=t.red(l+" "+c(l)):l>=500&&(u=t.bold.red(l+" "+c(l))),g.debug&&(console.log(u,m),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()),i?(l>=500&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(g)(i)},1e3)),429===l&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(g)(i)},1e3*o.headers["retry-after"]+50)),l>=400?i(u+" : "+t.yellow(m)):i(n,JSON.parse(a))):(console.log("callback not defined"),n?s("err:",n):e(JSON.parse(a)))}console.log(n,m)})):setTimeout(function(){r.bind(g)(i)},1e3)}(r)}else n({url:m,qs:f},function(n,o,a){if(o){var u=void 0,l=o.statusCode;return l>=200&&l<300?u=t.green(l):l>=400&&l<500?u=t.red(l+" "+c(l)):l>=500&&(u=t.bold.red(l+" "+c(l))),i.debug&&(console.log(o&&u,m),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"]})),r?l>=400?r(u+" : "+t.yellow(m)):r(n,JSON.parse(a)):n?s("err:",n):e(JSON.parse(a))}console.log(n,m)})})}},{key:"_observerRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+n,observerMode:!0,region:t},r)}},{key:"_championRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.CHAMPION+"/"+n,region:t,options:i},r)}},{key:"_championMasteryRequest",value:function(e,r){var n=e.endUrl,t=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+n,options:t,championMastery:!0},r)}},{key:"_currentGameRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+n,region:t},r)}},{key:"_staticRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=void 0===t?this.defaultRegion:t,o=e.options;return this._baseRequest({endUrl:"static-data/"+i+"/v"+g.STATIC_DATA+"/"+n,staticReq:!0,region:i,options:o},r)}},{key:"_statusRequest",value:function(e,r){var n=e.endUrl,t=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+g.STATUS+"/"+n,status:!0,options:t},r)}},{key:"_gameRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"v"+g.GAME+"/game/"+n,region:t},r)}},{key:"_leagueRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.LEAGUE+"/league/"+n,region:t,options:i},r)}},{key:"_matchRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.MATCH+"/match/"+n,region:t,options:i},r)}},{key:"_matchListRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.MATCH_LIST+"/matchlist/by-summoner/"+n,region:t,options:i},r)}},{key:"_runesMasteriesRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._summonerRequest({endUrl:n,region:t},r)}},{key:"_statsRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.STATS+"/stats/by-summoner/"+n,region:t,options:i},r)}},{key:"_summonerRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"v"+g.SUMMONER+"/summoner/"+n,region:t},r)}},{key:"_logError",value:function(e,r){console.log(t.bold.yellow(e),t.red("request"),t.bold.red("FAILED")+t.red("; "+r))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,r){var n=e.region,t=e.options;return this._championRequest({endUrl:"champion",region:n,options:t},r=n||t?r:arguments[0])}},{key:"getChamp",value:function(e,r){var n=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region:n},r):this._logError(this.getChamp.name,"required params "+t.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,n=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[d[n]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:n,options:s},a)}return this._logError(this.getChampMastery.name,"required params "+t.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]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/champions",region:i},h)})}return this._logError(this.getChampMasteries.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/score",region:i},h)})}return this._logError(this.getTotalChampMasteryScore.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getTopChamps",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/topchampions",region:i},h)})}return this._logError(this.getTopChamps.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=arguments[1],h=l[d[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},g):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,n){return r?g(r):e._currentGameRequest({endUrl:""+n[e._sanitizeName(m)].id,platformId:h,region:i},g)}):this._logError(this.getCurrentGame.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._observerRequest({endUrl:"featured",region:r},n=r?n:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=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:n},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?l(r):e._gameRequest({endUrl:"by-summoner/"+t[e._sanitizeName(u)].id+"/recent",region:n},l)}):this._logError(this.getRecentGames.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:n},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[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:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getLeagues.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+t[e._sanitizeName(d||g)].id,region:n},h)})}},{key:"getLeagueEntries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[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:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?void this._logError(this.getLeagueEntries.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+t[e._sanitizeName(d||g)].id+"/entry",region:n},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=void 0===n?{type:"RANKED_SOLO_5x5"}:n,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:r,options:t},i=r?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=void 0===n?{type:"RANKED_SOLO_5x5"}:n,i=arguments[1];return this._leagueRequest({endUrl:"master",region:r,options:t},i=r?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"champion",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"champion/"+(n||i),region:r,options:o},s):this._logError(this.getChampion.name,"required params "+t.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,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"item",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"item/"+(n||i),region:r,options:o},s):this._logError(this.getItem.name,"required params "+t.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,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"language-strings",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._staticRequest({endUrl:"languages",region:r},n=r?n:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"map",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"mastery",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"mastery/"+(n||i),region:r,options:o},s):this._logError(this.getMastery.name,"required params "+t.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,n=arguments[1];return this._staticRequest({endUrl:"realm",region:r},n=r?n:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"rune",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"rune/"+(n||i),region:r,options:o},s):this._logError(this.getRune.name,"required params "+t.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,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(n||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(n||i||o),region:r,options:s},a):this._logError(this.getSummonerSpell.name,"required params "+t.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,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"versions",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._statusRequest({endUrl:"shard",region:r},n=r?n:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._statusRequest({endUrl:"shards",region:r},n=r?n:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(n||i)?this._matchRequest({endUrl:""+(n||i),region:r,options:s},a):this._logError(this.getMatch.name,"required params "+t.yellow("`id/matchID` (int)")+" not passed in")}},{key:"getMatchList",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=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,d=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:n,options:m},d):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?d(r):e._matchListRequest({endUrl:""+t[e._sanitizeName(u)].id,region:n,options:m},d)}):this._logError(this.getMatchList.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[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:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getRunes.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._runesMasteriesRequest({endUrl:t[e._sanitizeName(d||g)].id+"/runes",region:n},h)})}},{key:"getMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[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:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getMasteries.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._runesMasteriesRequest({endUrl:t[e._sanitizeName(d||g)].id+"/masteries",region:n},h)})}},{key:"getRankedStats",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=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:n,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?m(r):e._statsRequest({endUrl:t[e._sanitizeName(u)].id+"/ranked",region:n,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=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:n,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?m(r):e._statsRequest({endUrl:t[e._sanitizeName(u)].id+"/summary",region:n,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getSummoners",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:n},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:n},h):p.string(d)?this._summonerRequest({endUrl:"by-name/"+d.map(function(r){return e._sanitizeName(r)}).join(","),region:n},h):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?void this._logError(this.getSummoners.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(d||g),region:n},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(n||i||o)?this.getSummoners({region:r,ids:[n||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:r,names:[a]},u):this._logError(this.getSummoner.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getSummonerNames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(n||o||a)?this._summonerRequest({endUrl:(n||o||a).join(",")+"/name",region:r},l):Number.isInteger(n||i||o||s||a||u)?this._summonerRequest({endUrl:(n||i||o||s||a||u)+"/name",region:r},l):void this._logError(this.getSummonerNames.name,"required params "+t.yellow("required params `ids/summonerIDs/playerIDs` ([int]/int)")+" or "+t.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,n=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(n))return this.getSummonerNames({region:r,id:n||i||o},s);this._logError(this.getSummonerName.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}(),I={Kindred:f,REGIONS:m};e.exports=I}); |
{ | ||
"name": "kindred-api", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"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", |
@@ -19,3 +19,3 @@ # Kindred | ||
Hopefully there aren't *too* many bugs! I'm a noob after all. | ||
Hopefully there aren't *too* many bugs! ***I'm a noob after all, so use this library at your own risk.*** I'm currently working on adding caching and fully support promises (it might be a bit buggy atm). | ||
@@ -313,3 +313,9 @@ ## Philosophy | ||
k.getSummoner({ summonerID: 354959 }, rprint) | ||
k.getSummoner({ summonerID: 354959 }) | ||
.then(json => console.log(json)) | ||
.catch(err => console.log(err)) | ||
k.getSummoners({ summonerIDs: [354959, 21542029] }, rprint) | ||
k.getMatch({ id: 2459973154 }, rprint) | ||
@@ -360,2 +366,6 @@ k.getMatch({ matchID: 2459973154 }, rprint) | ||
k.getRunes({ id: 354959 }) | ||
.then(json => console.log(json)) | ||
.catch(err => console.error(err)) | ||
/* | ||
@@ -387,2 +397,4 @@ But what if you want to quickly get the rune pages given | ||
/* Currently promises are bugged for these type of chained requests. */ | ||
/* | ||
@@ -389,0 +401,0 @@ Functions will have an options parameter that you can pass in query |
@@ -95,98 +95,111 @@ const request = require('request') | ||
_baseRequest({ endUrl, region = this.defaultRegion, status = false, observerMode = false, staticReq = false, championMastery = false, options = {} }, cb) { | ||
const proxy = staticReq ? 'global' : region | ||
const reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery) | ||
return new Promise((resolve, reject) => { | ||
const proxy = staticReq ? 'global' : region | ||
const reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery) | ||
if (!cb) { | ||
console.log( | ||
chalk.red( | ||
`error: No callback passed in for the method call regarding \`${chalk.yellow(reqUrl)}\`` | ||
) | ||
) | ||
return | ||
} | ||
if (this.limits) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
self.limits[region][0].addRequest() | ||
self.limits[region][1].addRequest() | ||
} | ||
if (this.limits) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
if (self.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
self.limits[region][0].addRequest() | ||
self.limits[region][1].addRequest() | ||
} | ||
// return new Promise((resolve, reject) => { | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
if (response && body) { | ||
let statusMessage | ||
const { statusCode } = response | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
if (response && body) { | ||
let statusMessage | ||
const { statusCode } = response | ||
if (statusCode >= 200 && statusCode < 300) | ||
statusMessage = chalk.green(statusCode) | ||
else if (statusCode >= 400 && statusCode < 500) | ||
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
else if (statusCode >= 500) | ||
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
if (statusCode >= 200 && statusCode < 300) | ||
statusMessage = chalk.green(statusCode) | ||
else if (statusCode >= 400 && statusCode < 500) | ||
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
else if (statusCode >= 500) | ||
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl) | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}) | ||
console.log() | ||
} | ||
if (callback) { | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
if (self.debug) { | ||
console.log(statusMessage, reqUrl) | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}) | ||
console.log() | ||
} | ||
if (statusCode === 429) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { | ||
sendRequest.bind(self)(callback) | ||
}, (response.headers['retry-after'] * 1000) + 50) | ||
} | ||
if (statusCode >= 500) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return callback(error, JSON.parse(body)) | ||
} else { | ||
console.log('callback not defined') | ||
if (error) { | ||
return reject('err:', error) | ||
} else { | ||
return resolve(JSON.parse(body)) | ||
} | ||
} | ||
} else { | ||
console.log(error, reqUrl) | ||
} | ||
}) | ||
} else { | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
})(cb) | ||
} else { | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
if (response) { | ||
let statusMessage | ||
const { statusCode } = response | ||
if (statusCode === 429) { | ||
if (self.debug) console.log('!!! resending request !!!') | ||
setTimeout(() => { | ||
sendRequest.bind(self)(callback) | ||
}, (response.headers['retry-after'] * 1000) + 50) | ||
} | ||
if (statusCode >= 200 && statusCode < 300) | ||
statusMessage = chalk.green(statusCode) | ||
else if (statusCode >= 400 && statusCode < 500) | ||
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
else if (statusCode >= 500) | ||
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return callback(error, JSON.parse(body)) | ||
if (this.debug) { | ||
console.log(response && statusMessage, reqUrl) | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}) | ||
} | ||
if (cb) { | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return cb(error, JSON.parse(body)) | ||
} else { | ||
console.log(error, reqUrl) | ||
if (error) { | ||
return reject('err:', error) | ||
} else { | ||
return resolve(JSON.parse(body)) | ||
} | ||
} | ||
}) | ||
} else { | ||
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000) | ||
} | ||
})(cb) | ||
} else { | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
if (response) { | ||
let statusMessage | ||
const { statusCode } = response | ||
if (statusCode >= 200 && statusCode < 300) | ||
statusMessage = chalk.green(statusCode) | ||
else if (statusCode >= 400 && statusCode < 500) | ||
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
else if (statusCode >= 500) | ||
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`) | ||
if (this.debug) { | ||
console.log(response && statusMessage, reqUrl) | ||
console.log({ | ||
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'], | ||
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'], | ||
'x-rate-limit-count': response.headers['x-rate-limit-count'], | ||
'retry-after': response.headers['retry-after'] | ||
}) | ||
} else { | ||
console.log(error, reqUrl) | ||
} | ||
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl)) | ||
else return cb(error, JSON.parse(body)) | ||
} else { | ||
console.log(error, reqUrl) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
@@ -193,0 +206,0 @@ |
@@ -19,3 +19,3 @@ const Deque = require('double-ended-queue') | ||
addRequest() { | ||
this.madeRequests.push((new Date()).getTime() + (this.seconds*1000 + ((this.seconds*1000) / 75))) | ||
this.madeRequests.push((new Date()).getTime() + (this.seconds*1000)) | ||
} | ||
@@ -22,0 +22,0 @@ |
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
314965
2691
460