Issues (33)

lib/mastery.js (1 issue)

1 View Code Duplication
"use strict";
2
Object.defineProperty(exports, "__esModule", { value: true });
3
var utils_1 = require("./utils");
4
var SummonerMastery = /** @class */ (function () {
5
    function SummonerMastery(APIKEY, region, summonerId) {
6
        this.summonerId = summonerId;
7
        this.APIKEY = APIKEY;
8
        this.region = region;
9
    }
10
    SummonerMastery.prototype.level = function (callback) {
11
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/scores/by-summoner/"
12
            + (this.summonerId + "?api_key=" + this.APIKEY);
13
        utils_1.getJSON(url, function (res, err) {
14
            if (err) {
15
                callback(null, err);
16
            }
17
            else {
18
                callback(res.data);
19
            }
20
        });
21
    };
22
    SummonerMastery.prototype.points = function (callback) {
23
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
24
            + (this.summonerId + "?api_key=" + this.APIKEY);
25
        utils_1.getJSON(url, function (res) {
26
            var points = 0;
27
            res.data.forEach(function (champion) {
28
                points += champion.championPoints;
29
            });
30
            callback(points);
31
        });
32
    };
33
    SummonerMastery.prototype.top = function (amount, callback) {
34
        if (amount === void 0) { amount = 0; }
0 ignored issues
show
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
35
        var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
36
            + (this.summonerId + "?api_key=" + this.APIKEY);
37
        utils_1.getJSON(url, function (res) {
38
            var slice = amount === 0 ? res.data.length : amount;
39
            callback(res.data.slice(0, slice));
40
        });
41
    };
42
    SummonerMastery.prototype.champion = function (champion, callback) {
43
        if (Array.isArray(champion)) {
44
            var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
45
                + (this.summonerId + "?api_key=" + this.APIKEY);
46
            var returner_1 = [];
47
            utils_1.getJSON(url, function (res) {
48
                res.data.forEach(function (element) {
49
                    if (champion.indexOf(element.championId) !== -1) {
50
                        returner_1.push(element);
51
                    }
52
                });
53
                callback(returner_1);
54
            });
55
        }
56
        else {
57
            var url = utils_1.getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
58
                + (this.summonerId + "/by-champion/" + champion + "?api_key=" + this.APIKEY);
59
            utils_1.getJSON(url, function (res, err) {
60
                if (err) {
61
                    callback(null, err);
62
                }
63
                else {
64
                    callback(res.data);
65
                }
66
            });
67
        }
68
    };
69
    return SummonerMastery;
70
}());
71
exports.SummonerMastery = SummonerMastery;
72
//# sourceMappingURL=mastery.js.map