| @@ 1-156 (lines=156) @@ | ||
| 1 | "use strict"; |
|
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); |
|
| 3 | var utils_1 = require("./utils"); |
|
| 4 | var mastery_1 = require("./mastery"); |
|
| 5 | var regions_1 = require("./regions"); |
|
| 6 | var summoner_1 = require("./summoner"); |
|
| 7 | var cache_1 = require("./cache"); |
|
| 8 | var realm_1 = require("./realm"); |
|
| 9 | var icon_1 = require("./icon"); |
|
| 10 | var LoLNode = /** @class */ (function () { |
|
| 11 | /** |
|
| 12 | * Represents the Riot API Wrapper Object. |
|
| 13 | * @constructor |
|
| 14 | * @param {string} APIKEY - Riot API Key |
|
| 15 | */ |
|
| 16 | function LoLNode(APIKEY) { |
|
| 17 | this.cacheList = {}; |
|
| 18 | this.APIKEY = APIKEY; |
|
| 19 | for (var region in regions_1.RegionDomains) { |
|
| 20 | if (this.cacheList[region] !== {}) { |
|
| 21 | this.cacheList[region] = {}; |
|
| 22 | } |
|
| 23 | } |
|
| 24 | } |
|
| 25 | /** |
|
| 26 | * @function |
|
| 27 | * Creates a Realm Object of said region |
|
| 28 | * @param {string} region - Region being called |
|
| 29 | * @callback Realm - Returns a Realm Object |
|
| 30 | */ |
|
| 31 | LoLNode.prototype.realm = function (region, callback) { |
|
| 32 | var _this = this; |
|
| 33 | region = region.toUpperCase(); |
|
| 34 | var realmCache = this.cacheList[region].realm; |
|
| 35 | var cacheState; |
|
| 36 | if (typeof realmCache === 'undefined') { |
|
| 37 | cacheState = 0; |
|
| 38 | } |
|
| 39 | else if (realmCache.get() === null) { |
|
| 40 | cacheState = 1; |
|
| 41 | } |
|
| 42 | else { |
|
| 43 | cacheState = 2; |
|
| 44 | } |
|
| 45 | if (cacheState < 2) { |
|
| 46 | var regionURL = utils_1.getRegion(region); |
|
| 47 | var url = regionURL + "/lol/static-data/v3/realms?api_key=" + this.APIKEY; |
|
| 48 | utils_1.getJSON(url, function (res, err) { |
|
| 49 | if (err) { |
|
| 50 | callback(null, err); |
|
| 51 | } |
|
| 52 | else { |
|
| 53 | var data = res.data; |
|
| 54 | var realm = new realm_1.Realm(data.lg, data.dd, data.l, data.n, data.profileiconmax, data.v, data.cdn, data.css); |
|
| 55 | cacheState === 1 ? |
|
| 56 | _this.cacheList[region].realm.refresh(realm) : |
|
| 57 | _this.cacheList[region].realm = new cache_1.Cache(realm, 1800); |
|
| 58 | callback(realm); |
|
| 59 | } |
|
| 60 | }); |
|
| 61 | } |
|
| 62 | else { |
|
| 63 | callback(realmCache.get()); |
|
| 64 | } |
|
| 65 | }; |
|
| 66 | /** |
|
| 67 | * Creates a Summoner Object of said region |
|
| 68 | * @param {string} region - Region being called |
|
| 69 | * @param {array} identifier Identification for |
|
| 70 | * how you enter your data. |
|
| 71 | * _________________________ |
|
| 72 | * structure => [type, val] |
|
| 73 | * |
|
| 74 | * - type => account|name|id |
|
| 75 | * - - account => The Account ID |
|
| 76 | * - - name => The Summoner Name |
|
| 77 | * - - id => The Summoner ID |
|
| 78 | * |
|
| 79 | * - val => Either a string containing the name or |
|
| 80 | * a number containing the Account ID or Summoner ID |
|
| 81 | * |
|
| 82 | * @param callback - Returns a Summoner Object |
|
| 83 | * @callback Summoner - Returns a Summoner Object |
|
| 84 | */ |
|
| 85 | LoLNode.prototype.summoner = function (region, identifier, callback) { |
|
| 86 | var _this = this; |
|
| 87 | region = region.toUpperCase(); |
|
| 88 | var regionURL = utils_1.getRegion(region); |
|
| 89 | var url = regionURL + "/lol/summoner/v3/summoners"; |
|
| 90 | switch (identifier[0]) { |
|
| 91 | case 'account': |
|
| 92 | url += "/by-account/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 93 | break; |
|
| 94 | case 'name': |
|
| 95 | url += "/by-name/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 96 | break; |
|
| 97 | case 'id': |
|
| 98 | url += "/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 99 | break; |
|
| 100 | } |
|
| 101 | utils_1.getJSON(url, function (res, err) { |
|
| 102 | if (err) { |
|
| 103 | callback(null, err); |
|
| 104 | } |
|
| 105 | else { |
|
| 106 | var data_1 = res.data; |
|
| 107 | _this.realm(region, function (_a) { |
|
| 108 | var dd = _a.dd, cdn = _a.cdn; |
|
| 109 | callback(new summoner_1.Summoner(data_1.id, data_1.name, new icon_1.Icon(data_1.profileIconId, dd, cdn), data_1.summonerLevel, data_1.accountId, data_1.revisionDate, new mastery_1.SummonerMastery(_this.APIKEY, region, data_1.id))); |
|
| 110 | }); |
|
| 111 | } |
|
| 112 | }); |
|
| 113 | }; |
|
| 114 | /** |
|
| 115 | * |
|
| 116 | * @param region |
|
| 117 | * @param identifier |
|
| 118 | * @param type |
|
| 119 | * @param callback |
|
| 120 | */ |
|
| 121 | LoLNode.prototype.mastery = function (region, identifier, type, callback) { |
|
| 122 | this.summoner(region, identifier, function (summoner) { |
|
| 123 | switch (type[0]) { |
|
| 124 | case 'level': |
|
| 125 | summoner.mastery.level(function (level) { return callback(level); }); |
|
| 126 | break; |
|
| 127 | case 'points': |
|
| 128 | summoner.mastery.level(function (points) { return callback(points); }); |
|
| 129 | break; |
|
| 130 | case 'top': |
|
| 131 | var size = void 0; |
|
| 132 | type.length > 1 ? size = type[1] : size = 0; |
|
| 133 | summoner.mastery.top(size, function (data) { return callback(data); }); |
|
| 134 | break; |
|
| 135 | case 'champion': |
|
| 136 | summoner.mastery.champion(type[1], function (data) { return callback(data); }); |
|
| 137 | break; |
|
| 138 | default: |
|
| 139 | callback(null, 'incorrect type to mastery method in the LoLNode object'); |
|
| 140 | } |
|
| 141 | }); |
|
| 142 | }; |
|
| 143 | /** |
|
| 144 | * |
|
| 145 | * @param region |
|
| 146 | * @param value |
|
| 147 | * - test |
|
| 148 | * -- test2 |
|
| 149 | * @param callback |
|
| 150 | */ |
|
| 151 | LoLNode.prototype.champion = function (region, value, options, callback) { |
|
| 152 | callback(); |
|
| 153 | }; |
|
| 154 | return LoLNode; |
|
| 155 | }()); |
|
| 156 | exports.LoLNode = LoLNode; |
|
| 157 | //# sourceMappingURL=index.js.map |
|
| @@ 1-154 (lines=154) @@ | ||
| 1 | import { getJSON, getRegion } from './utils'; |
|
| 2 | import { SummonerMastery } from './mastery'; |
|
| 3 | import { RegionDomains } from './regions'; |
|
| 4 | import { Summoner } from './summoner'; |
|
| 5 | import { Cache } from './cache'; |
|
| 6 | import { Realm } from './realm'; |
|
| 7 | import { Icon } from './icon'; |
|
| 8 | var LoLNode = /** @class */ (function () { |
|
| 9 | /** |
|
| 10 | * Represents the Riot API Wrapper Object. |
|
| 11 | * @constructor |
|
| 12 | * @param {string} APIKEY - Riot API Key |
|
| 13 | */ |
|
| 14 | function LoLNode(APIKEY) { |
|
| 15 | this.cacheList = {}; |
|
| 16 | this.APIKEY = APIKEY; |
|
| 17 | for (var region in RegionDomains) { |
|
| 18 | if (this.cacheList[region] !== {}) { |
|
| 19 | this.cacheList[region] = {}; |
|
| 20 | } |
|
| 21 | } |
|
| 22 | } |
|
| 23 | /** |
|
| 24 | * @function |
|
| 25 | * Creates a Realm Object of said region |
|
| 26 | * @param {string} region - Region being called |
|
| 27 | * @callback Realm - Returns a Realm Object |
|
| 28 | */ |
|
| 29 | LoLNode.prototype.realm = function (region, callback) { |
|
| 30 | var _this = this; |
|
| 31 | region = region.toUpperCase(); |
|
| 32 | var realmCache = this.cacheList[region].realm; |
|
| 33 | var cacheState; |
|
| 34 | if (typeof realmCache === 'undefined') { |
|
| 35 | cacheState = 0; |
|
| 36 | } |
|
| 37 | else if (realmCache.get() === null) { |
|
| 38 | cacheState = 1; |
|
| 39 | } |
|
| 40 | else { |
|
| 41 | cacheState = 2; |
|
| 42 | } |
|
| 43 | if (cacheState < 2) { |
|
| 44 | var regionURL = getRegion(region); |
|
| 45 | var url = regionURL + "/lol/static-data/v3/realms?api_key=" + this.APIKEY; |
|
| 46 | getJSON(url, function (res, err) { |
|
| 47 | if (err) { |
|
| 48 | callback(null, err); |
|
| 49 | } |
|
| 50 | else { |
|
| 51 | var data = res.data; |
|
| 52 | var realm = new Realm(data.lg, data.dd, data.l, data.n, data.profileiconmax, data.v, data.cdn, data.css); |
|
| 53 | cacheState === 1 ? |
|
| 54 | _this.cacheList[region].realm.refresh(realm) : |
|
| 55 | _this.cacheList[region].realm = new Cache(realm, 1800); |
|
| 56 | callback(realm); |
|
| 57 | } |
|
| 58 | }); |
|
| 59 | } |
|
| 60 | else { |
|
| 61 | callback(realmCache.get()); |
|
| 62 | } |
|
| 63 | }; |
|
| 64 | /** |
|
| 65 | * Creates a Summoner Object of said region |
|
| 66 | * @param {string} region - Region being called |
|
| 67 | * @param {array} identifier Identification for |
|
| 68 | * how you enter your data. |
|
| 69 | * _________________________ |
|
| 70 | * structure => [type, val] |
|
| 71 | * |
|
| 72 | * - type => account|name|id |
|
| 73 | * - - account => The Account ID |
|
| 74 | * - - name => The Summoner Name |
|
| 75 | * - - id => The Summoner ID |
|
| 76 | * |
|
| 77 | * - val => Either a string containing the name or |
|
| 78 | * a number containing the Account ID or Summoner ID |
|
| 79 | * |
|
| 80 | * @param callback - Returns a Summoner Object |
|
| 81 | * @callback Summoner - Returns a Summoner Object |
|
| 82 | */ |
|
| 83 | LoLNode.prototype.summoner = function (region, identifier, callback) { |
|
| 84 | var _this = this; |
|
| 85 | region = region.toUpperCase(); |
|
| 86 | var regionURL = getRegion(region); |
|
| 87 | var url = regionURL + "/lol/summoner/v3/summoners"; |
|
| 88 | switch (identifier[0]) { |
|
| 89 | case 'account': |
|
| 90 | url += "/by-account/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 91 | break; |
|
| 92 | case 'name': |
|
| 93 | url += "/by-name/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 94 | break; |
|
| 95 | case 'id': |
|
| 96 | url += "/" + identifier[1] + "?api_key=" + this.APIKEY; |
|
| 97 | break; |
|
| 98 | } |
|
| 99 | getJSON(url, function (res, err) { |
|
| 100 | if (err) { |
|
| 101 | callback(null, err); |
|
| 102 | } |
|
| 103 | else { |
|
| 104 | var data_1 = res.data; |
|
| 105 | _this.realm(region, function (_a) { |
|
| 106 | var dd = _a.dd, cdn = _a.cdn; |
|
| 107 | callback(new Summoner(data_1.id, data_1.name, new Icon(data_1.profileIconId, dd, cdn), data_1.summonerLevel, data_1.accountId, data_1.revisionDate, new SummonerMastery(_this.APIKEY, region, data_1.id))); |
|
| 108 | }); |
|
| 109 | } |
|
| 110 | }); |
|
| 111 | }; |
|
| 112 | /** |
|
| 113 | * |
|
| 114 | * @param region |
|
| 115 | * @param identifier |
|
| 116 | * @param type |
|
| 117 | * @param callback |
|
| 118 | */ |
|
| 119 | LoLNode.prototype.mastery = function (region, identifier, type, callback) { |
|
| 120 | this.summoner(region, identifier, function (summoner) { |
|
| 121 | switch (type[0]) { |
|
| 122 | case 'level': |
|
| 123 | summoner.mastery.level(function (level) { return callback(level); }); |
|
| 124 | break; |
|
| 125 | case 'points': |
|
| 126 | summoner.mastery.level(function (points) { return callback(points); }); |
|
| 127 | break; |
|
| 128 | case 'top': |
|
| 129 | var size = void 0; |
|
| 130 | type.length > 1 ? size = type[1] : size = 0; |
|
| 131 | summoner.mastery.top(size, function (data) { return callback(data); }); |
|
| 132 | break; |
|
| 133 | case 'champion': |
|
| 134 | summoner.mastery.champion(type[1], function (data) { return callback(data); }); |
|
| 135 | break; |
|
| 136 | default: |
|
| 137 | callback(null, 'incorrect type to mastery method in the LoLNode object'); |
|
| 138 | } |
|
| 139 | }); |
|
| 140 | }; |
|
| 141 | /** |
|
| 142 | * |
|
| 143 | * @param region |
|
| 144 | * @param value |
|
| 145 | * - test |
|
| 146 | * -- test2 |
|
| 147 | * @param callback |
|
| 148 | */ |
|
| 149 | LoLNode.prototype.champion = function (region, value, options, callback) { |
|
| 150 | callback(); |
|
| 151 | }; |
|
| 152 | return LoLNode; |
|
| 153 | }()); |
|
| 154 | export { LoLNode }; |
|
| 155 | //# sourceMappingURL=index.js.map |
|