kindred-api
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -193,3 +193,28 @@ (function (global, factory) { | ||
if (limits) { | ||
this.limits = [new RateLimit(limits[0][0], limits[0][1]), new RateLimit(limits[1][0], limits[1][1])]; | ||
this.limits = {}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.keys(regions)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var region = _step.value; | ||
this.limits[regions[region]] = [new RateLimit(limits[0][0], limits[0][1]), new RateLimit(limits[1][0], limits[1][1])]; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
@@ -200,4 +225,4 @@ } | ||
key: 'canMakeRequest', | ||
value: function canMakeRequest() { | ||
if (!this.limits[0].requestAvailable() || !this.limits[1].requestAvailable()) { | ||
value: function canMakeRequest(region) { | ||
if (!this.limits[region][0].requestAvailable() || !this.limits[region][1].requestAvailable()) { | ||
return false; | ||
@@ -262,7 +287,8 @@ } | ||
if (this.canMakeRequest()) { | ||
if (this.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
this.limits[0].addRequest(); | ||
this.limits[1].addRequest(); | ||
this.limits[region][0].addRequest(); | ||
this.limits[region][1].addRequest(); | ||
} | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
@@ -748,9 +774,9 @@ var statusMessage = void 0; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _name = _step.value; | ||
for (var _iterator2 = names[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _name = _step2.value; | ||
@@ -760,12 +786,12 @@ args.push(data[_this8._sanitizeName(_name)].id); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
@@ -824,9 +850,9 @@ } | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = names[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _name2 = _step2.value; | ||
for (var _iterator3 = names[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _name2 = _step3.value; | ||
@@ -836,12 +862,12 @@ args.push(data[_this9._sanitizeName(_name2)].id); | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -1198,9 +1224,9 @@ } | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator3 = names[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _name3 = _step3.value; | ||
for (var _iterator4 = names[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var _name3 = _step4.value; | ||
@@ -1210,12 +1236,12 @@ args.push(data[_this11._sanitizeName(_name3)].id); | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -1276,9 +1302,9 @@ } | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
try { | ||
for (var _iterator4 = names[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var _name4 = _step4.value; | ||
for (var _iterator5 = names[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var _name4 = _step5.value; | ||
@@ -1288,12 +1314,12 @@ args.push(data[_this12._sanitizeName(_name4)].id); | ||
} catch (err) { | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
if (!_iteratorNormalCompletion5 && _iterator5.return) { | ||
_iterator5.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
} | ||
@@ -1300,0 +1326,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp"],t);else if("undefined"!=typeof exports)t(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"));else{var r={exports:{}};t(r,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=r.exports}}(this,function(e,t,r,n,i){"use strict";function o(e,t){if(!(e instanceof t))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,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=function(){function e(r,n){o(this,e),this.allowedRequests=r,this.seconds=n,this.madeRequests=new t}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 t=y[e];if(t)return t},v=i("^[0-9\\p{L} _\\.]+$"),f=function(){function e(t){var r=t.key,n=t.defaultRegion,i=void 0===n?m.NORTH_AMERICA:n,s=t.debug,a=void 0!==s&&s,l=t.limits;o(this,e),this.key=r,this.defaultRegion=i,this.debug=a,l&&(this.limits=[new u(l[0][0],l[0][1]),new u(l[1][0],l[1][1])])}return a(e,[{key:"canMakeRequest",value:function(){return!(!this.limits[0].requestAvailable()||!this.limits[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,t,r,n,i,o){var s=r?"":t+"/";return"https://"+t+".api.riotgames.com/"+(n||i||o?"":"api/lol/"+s)+encodeURI(e)+"?api_key="+this.key}},{key:"_baseRequest",value:function(e,t){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(!t)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()?(h||(this.limits[0].addRequest(),this.limits[1].addRequest()),r({url:I,qs:f},function(r,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?t(a+" : "+n.yellow(I)):t(r,JSON.parse(s))})):setTimeout(e.bind(this),1e3)}.bind(this)(I,f):r({url:I,qs:f},function(e,r,o){var s=void 0,a=r.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(r&&s,I),console.log({"x-app-rate-limit-count":r.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":r.headers["x-method-rate-limit-count"],"x-rate-limit-count":r.headers["x-rate-limit-count"],"retry-after":r.headers["retry-after"]})),a>=400?t(s+" : "+n.yellow(I)):t(e,JSON.parse(o))})}},{key:"_observerRequest",value:function(e,t){var r=e.endUrl,n=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+r,observerMode:!0,region:n},t)}},{key:"_championRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.CHAMPION+"/"+r,region:n,options:i},t)}},{key:"_championMasteryRequest",value:function(e,t){var r=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+r,options:n,championMastery:!0},t)}},{key:"_currentGameRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+r,region:n},t)}},{key:"_staticRequest",value:function(e,t){var r=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+"/"+r,staticReq:!0,region:i,options:o},t)}},{key:"_statusRequest",value:function(e,t){var r=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+d.STATUS+"/"+r,status:!0,options:n},t)}},{key:"_gameRequest",value:function(e,t){var r=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.GAME+"/game/"+r,region:n},t)}},{key:"_leagueRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.LEAGUE+"/league/"+r,region:n,options:i},t)}},{key:"_matchRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH+"/match/"+r,region:n,options:i},t)}},{key:"_matchListRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH_LIST+"/matchlist/by-summoner/"+r,region:n,options:i},t)}},{key:"_runesMasteriesRequest",value:function(e,t){var r=e.endUrl,n=e.region;return this._summonerRequest({endUrl:r,region:n},t)}},{key:"_statsRequest",value:function(e,t){var r=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.STATS+"/stats/by-summoner/"+r,region:n,options:i},t)}},{key:"_summonerRequest",value:function(e,t){var r=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.SUMMONER+"/summoner/"+r,region:n},t)}},{key:"_logError",value:function(e,t){console.log(n.bold.yellow(e),n.red("request"),n.bold.red("FAILED")+n.red("; "+t))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,t){var r=e.region,n=e.options;return this._championRequest({endUrl:"champion",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getChamp",value:function(e,t){var r=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region: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]:{},t=e.region,r=void 0===t?this.defaultRegion:t,i=e.playerID,o=e.championID,s=e.options,a=arguments[1];if(Number.isInteger(i)&&Number.isInteger(o)){var u=l[g[r]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:r,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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=void 0===r?this.defaultRegion:r,o=t.id,a=t.summonerID,u=t.playerID,m=t.name,d=t.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(t,r){return t?h(t):e._championMasteryRequest({endUrl:y+"/player/"+r[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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=void 0===r?this.defaultRegion:r,o=t.id,a=t.summonerID,u=t.playerID,m=t.name,d=t.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(t,r){return t?h(t):e._championMasteryRequest({endUrl:y+"/player/"+r[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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=void 0===r?this.defaultRegion:r,o=t.id,a=t.summonerID,u=t.playerID,m=t.name,d=t.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(t,r){return t?h(t):e._championMasteryRequest({endUrl:y+"/player/"+r[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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=void 0===r?this.defaultRegion:r,o=t.id,a=t.summonerID,u=t.playerID,m=t.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(t,r){return t?d(t):e._currentGameRequest({endUrl:""+r[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]:{},t=e.region,r=arguments[1];return this._observerRequest({endUrl:"featured",region:t},r=t?r:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.id,o=t.summonerID,a=t.playerID,u=t.name,l=arguments[1];return Number.isInteger(i||o||a)?this._gameRequest({endUrl:"by-summoner/"+(i||o||a)+"/recent",region:r},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:r},function(t,n){return t?l(t):e._gameRequest({endUrl:"by-summoner/"+n[e._sanitizeName(u)].id+"/recent",region:r},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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.ids,o=t.id,a=t.summonerIDs,u=t.summonerID,l=t.playerIDs,m=t.playerID,g=t.names,d=t.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:r},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:r},h):p.string(g)?this.getSummoners({names:g,region:r},function(t,n){if(t)return h(t);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:r},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:r},function(t,n){return t?h(t):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id,region:r},h)})}},{key:"getLeagueEntries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.ids,o=t.id,a=t.summonerIDs,u=t.summonerID,l=t.playerIDs,m=t.playerID,g=t.names,d=t.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:r},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:r},h):p.string(g)?this.getSummoners({names:g,region:r},function(t,n){if(t)return h(t);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:r},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:r},function(t,n){return t?h(t):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id+"/entry",region:r},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=void 0===r?{type:"RANKED_SOLO_5x5"}:r,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:t,options:n},i=t?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=void 0===r?{type:"RANKED_SOLO_5x5"}:r,i=arguments[1];return this._leagueRequest({endUrl:"master",region:t,options:n},i=t?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"champion",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(r||i)?this._staticRequest({endUrl:"champion/"+(r||i),region:t,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]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"item",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(r||i)?this._staticRequest({endUrl:"item/"+(r||i),region:t,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]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"language-strings",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=arguments[1];return this._staticRequest({endUrl:"languages",region:t},r=t?r:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"map",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"mastery",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(r||i)?this._staticRequest({endUrl:"mastery/"+(r||i),region:t,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]:{},t=e.region,r=arguments[1];return this._staticRequest({endUrl:"realm",region:t},r=t?r:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"rune",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(r||i)?this._staticRequest({endUrl:"rune/"+(r||i),region:t,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]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(r||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(r||i||o),region:t,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]:{},t=e.region,r=e.options,n=arguments[1];return this._staticRequest({endUrl:"versions",region:t,options:r},n=t||r?n:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=arguments[1];return this._statusRequest({endUrl:"shard",region:t},r=t?r:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=arguments[1];return this._statusRequest({endUrl:"shards",region:t},r=t?r:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(r||i)?this._matchRequest({endUrl:""+(r||i),region:t,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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.id,o=t.summonerID,a=t.playerID,u=t.name,l=t.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:r,options:m},g):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:r},function(t,n){return t?g(t):e._matchListRequest({endUrl:""+n[e._sanitizeName(u)].id,region:r,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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.ids,o=t.id,a=t.summonerIDs,u=t.summonerID,l=t.playerIDs,m=t.playerID,g=t.names,d=t.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:r},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:r},h):p.string(g)?this.getSummoners({names:g,region:r},function(t,n){if(t)return h(t);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:r},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:r},function(t,n){return t?h(t):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/runes",region:r},h)})}},{key:"getMasteries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.ids,o=t.id,a=t.summonerIDs,u=t.summonerID,l=t.playerIDs,m=t.playerID,g=t.names,d=t.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:r},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:r},h):p.string(g)?this.getSummoners({names:g,region:r},function(t,n){if(t)return h(t);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:r},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:r},function(t,n){return t?h(t):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/masteries",region:r},h)})}},{key:"getRankedStats",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.id,o=t.summonerID,a=t.playerID,u=t.name,l=t.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/ranked",region:r,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:r},function(t,n){return t?m(t):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/ranked",region:r,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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.id,o=t.summonerID,a=t.playerID,u=t.name,l=t.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/summary",region:r,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:r},function(t,n){return t?m(t):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/summary",region:r,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,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.region,i=t.ids,o=t.id,a=t.summonerIDs,u=t.summonerID,l=t.playerIDs,m=t.playerID,g=t.names,d=t.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:r},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:r},h):p.string(g)?this._summonerRequest({endUrl:"by-name/"+g.map(function(t){return e._sanitizeName(t)}).join(","),region:r},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:r},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,r=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(r||i||o)?this.getSummoners({region:t,ids:[r||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:t,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]:{},t=e.region,r=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(r||o||a)?this._summonerRequest({endUrl:(r||o||a).join(",")+"/name",region:t},l):Number.isInteger(r||i||o||s||a||u)?this._summonerRequest({endUrl:(r||i||o||s||a||u)+"/name",region:t},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]:{},t=e.region,r=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(r))return this.getSummonerNames({region:t,id:r||i||o},s);this._logError(this.getSummonerName.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}();e.exports=f}); | ||
!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}):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}();e.exports=f}); |
{ | ||
"name": "kindred-api", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Kindred is a thin Node.js wrapper on top of Riot Games API for League of Legends", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"scripts": { | ||
"go": "yarn lint && yarn build && yarn minify && node index.js", | ||
"go": "yarn lint && yarn build && yarn minify && node test.js", | ||
"prepare": "yarn build && yarn minify", | ||
@@ -11,0 +11,0 @@ "test": "node make test", |
# Kindred | ||
Kindred is a thin Node.js wrapper on top of [Riot Games API for League of Legends](http://www.developer.riotgames.com) | ||
Kindred is a thin Node.js wrapper (with an optional rate limiter) on top of [Riot Games API for League of Legends](http://www.developer.riotgames.com). | ||
@@ -13,9 +13,9 @@ ## Table of Contents | ||
## Philosophy | ||
My goal is to make a wrapper that is convenient and sensible. This project is heavily inspired by [psuedonym117's Python wrapper](https://github.com/pseudonym117/Riot-Watcher). I want to make the API as consistent as possible and also make a decent rate limiter. However, I also wish to provide users flexibility and a detailed errors system to make the wrapper as unobtrusive as possible. Look at the [Quick Usage Examples](#quick-usage-examples) to see what I mean. | ||
My goal is to make a wrapper that is simple, sensibile, and consistent. This project is heavily inspired by [psuedonym117's Python wrapper](https://github.com/pseudonym117/Riot-Watcher). Look at the [Quick Usage Examples](#quick-usage-examples) to see what I mean. | ||
This is my first try at making an API wrapper. I am open to any advice and help! | ||
March 28, 2017 | ||
***March 28, 2017*** | ||
**I'm pretty proud of the end result. The rate limiting isn't the best, and the method names are kinda iffy, but it works really well for my other project and when I need a quick script**. | ||
**I'm pretty proud of the end result. The rate limiting isn't the best, and the method names are kinda iffy (minor inconsistencies), but it works really well for my other project and for when I need a quick script. I'll try to improve this library over the next few weeks.** | ||
@@ -188,6 +188,6 @@ ## Installation | ||
* Get mastery pages mapped by summoner ID for a given list of summoner IDs. (REST) | ||
* getMasteries({ region, ids/summonerIDs/playerIDs ([int]/int), id (int), names ([str]/str), name (str)}, cb) | ||
* getMasteries({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int), names ([str]/str), name (str)}, cb) | ||
2. **/api/lol/{region}/v1.4/summoner/{summonerIds}/runes** | ||
* Retrieve match list by match ID. (REST) | ||
* getRunes({ region, ids/summonerIDs/playerIDs ([int]/int), id (int), names ([str]/str), name (str) }, cb) | ||
* getRunes({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int), names ([str]/str), name (str) }, cb) | ||
@@ -428,4 +428,6 @@ ### Stats | ||
There are a few inconsistencies within this program that I don't know how to address since this is my first API wrapper and I'm still quite a big newbie. | ||
There are a few inconsistencies and weird things within this libary that I don't know how to address since this is my first API wrapper and I'm still quite a big newbie. | ||
For example, the two methods getChamp() and getChampion() are actually different. | ||
getChamp() targets the champ endpoint | ||
@@ -435,3 +437,3 @@ | ||
I didn't want to attach getChampion() with 'static' in any way or form since I thought it looked kind of annoying. | ||
I didn't want to attach getChampion() with 'static' in any way or form since I thought it looked kind of annoying because then I would want to attach static to the other static methods as well (maybe that's better?). | ||
@@ -438,0 +440,0 @@ **Right now, the code is also quite messy and there is a lot of repeated code.** Function definitions are quite long because I include many aliases as well. I haven't thought of an elegant way to make a magic function that manages to work for every single endpoint request yet. |
@@ -24,11 +24,15 @@ const request = require('request') | ||
if (limits) { | ||
this.limits = [ | ||
new RateLimit(limits[0][0], limits[0][1]), | ||
new RateLimit(limits[1][0], limits[1][1]) | ||
] | ||
this.limits = {} | ||
for (const region of Object.keys(REGIONS)) { | ||
this.limits[REGIONS[region]] = [ | ||
new RateLimit(limits[0][0], limits[0][1]), | ||
new RateLimit(limits[1][0], limits[1][1]) | ||
] | ||
} | ||
} | ||
} | ||
canMakeRequest() { | ||
if (!this.limits[0].requestAvailable() || !this.limits[1].requestAvailable()) { | ||
canMakeRequest(region) { | ||
if (!this.limits[region][0].requestAvailable() || !this.limits[region][1].requestAvailable()) { | ||
return false | ||
@@ -78,7 +82,8 @@ } | ||
(function sendRequest() { | ||
if (this.canMakeRequest()) { | ||
if (this.canMakeRequest(region)) { | ||
if (!staticReq) { | ||
this.limits[0].addRequest() | ||
this.limits[1].addRequest() | ||
this.limits[region][0].addRequest() | ||
this.limits[region][1].addRequest() | ||
} | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
@@ -85,0 +90,0 @@ let statusMessage |
Sorry, the diff of this file is not supported yet
307440
2573
438