All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.robrua.orianna.api.dto.LeagueAPI Maven / Gradle / Ivy

There is a newer version: 2.4.5
Show newest version
package com.robrua.orianna.api.dto;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.gson.reflect.TypeToken;
import com.robrua.orianna.api.Utils;
import com.robrua.orianna.type.api.ParamsBuilder;
import com.robrua.orianna.type.core.common.QueueType;
import com.robrua.orianna.type.dto.league.League;

public abstract class LeagueAPI {
    private static final Set RANKED_QUEUES = new HashSet<>(Arrays.asList(new QueueType[] {QueueType.RANKED_SOLO_5x5, QueueType.RANKED_TEAM_3x3,
            QueueType.RANKED_TEAM_5x5}));

    /**
     * @param queueType
     *            the queue type to get the challenger league for
     * @return the challenger league
     * @see Riot
     *      API Specification
     */
    public static League getChallenger(final QueueType queueType) {
        if(!RANKED_QUEUES.contains(queueType)) {
            throw new IllegalArgumentException("Can't get challenger for a non-ranked queue type!");
        }

        final String request = BaseRiotAPI.API_VERSIONS.get("league") + "/league/challenger";
        final Map params = new ParamsBuilder().add("type", queueType).build();
        return BaseRiotAPI.GSON.fromJson(BaseRiotAPI.get(request, params, false), League.class);
    }

    /**
     * @param summonerIDs
     *            the summoners to get league entries for
     * @return the summoners' league entries
     * @see Riot
     *      API Specification
     */
    public static Map> getSummonerLeagueEntries(final List summonerIDs) {
        if(summonerIDs.isEmpty()) {
            return new HashMap<>();
        }
        if(summonerIDs.size() > 10) {
            throw new IllegalArgumentException("Can't get league entries for more than 10 summoners!");
        }

        final String request = BaseRiotAPI.API_VERSIONS.get("league") + "/league/by-summoner/" + Utils.getIDString(summonerIDs) + "/entry";
        final Type type = new TypeToken>>() {}.getType();
        return BaseRiotAPI.GSON.fromJson(BaseRiotAPI.get(request, null, false), type);
    }

    /**
     * @param summonerIDs
     *            the summoners to get league entries for
     * @return the summoners' league entries
     * @see Riot
     *      API Specification
     */
    public static Map> getSummonerLeagueEntries(final long... summonerIDs) {
        return getSummonerLeagueEntries(Utils.convert(summonerIDs));
    }

    /**
     * @param summonerIDs
     *            the summoners to get leagues for
     * @return the summoners' league
     * @see Riot
     *      API Specification
     */
    public static Map> getSummonerLeagues(final List summonerIDs) {
        if(summonerIDs.isEmpty()) {
            return new HashMap<>();
        }
        if(summonerIDs.size() > 10) {
            throw new IllegalArgumentException("Can't get leagues for more than 10 summoners!");
        }

        final String request = BaseRiotAPI.API_VERSIONS.get("league") + "/league/by-summoner/" + Utils.getIDString(summonerIDs);
        final Type type = new TypeToken>>() {}.getType();
        return BaseRiotAPI.GSON.fromJson(BaseRiotAPI.get(request, null, false), type);
    }

    /**
     * @param summonerIDs
     *            the summoners to get leagues for
     * @return the summoners' league
     * @see Riot
     *      API Specification
     */
    public static Map> getSummonerLeagues(final long... summonerIDs) {
        return getSummonerLeagues(Utils.convert(summonerIDs));
    }

    /**
     * @param teamIDs
     *            the summoners to get leagues for
     * @return the team's leagues
     * @see Riot
     *      API Specification
     */
    public static Map> getTeamLeagueEntries(final List teamIDs) {
        if(teamIDs.isEmpty()) {
            return new HashMap<>();
        }
        if(teamIDs.size() > 10) {
            throw new IllegalArgumentException("Can't get leagues for more than 10 teams!");
        }

        final String request = BaseRiotAPI.API_VERSIONS.get("league") + "/league/by-team/" + Utils.getIDString(teamIDs) + "/entry";
        final Type type = new TypeToken>>() {}.getType();
        return BaseRiotAPI.GSON.fromJson(BaseRiotAPI.get(request, null, false), type);
    }

    /**
     * @param teamIDs
     *            the summoners to get leagues for
     * @return the team's leagues
     * @see Riot
     *      API Specification
     */
    public static Map> getTeamLeagueEntries(final String... teamIDs) {
        return getTeamLeagueEntries(Arrays.asList(teamIDs));
    }

    /**
     * @param teamIDs
     *            the summoners to get leagues for
     * @return the team's leagues
     * @see Riot
     *      API Specification
     */
    public static Map> getTeamLeagues(final List teamIDs) {
        if(teamIDs.isEmpty()) {
            return new HashMap<>();
        }
        if(teamIDs.size() > 10) {
            throw new IllegalArgumentException("Can't get leagues for more than 10 teams!");
        }

        final String request = BaseRiotAPI.API_VERSIONS.get("league") + "/league/by-team/" + Utils.getIDString(teamIDs);
        final Type type = new TypeToken>>() {}.getType();
        return BaseRiotAPI.GSON.fromJson(BaseRiotAPI.get(request, null, false), type);
    }

    /**
     * @param teamIDs
     *            the summoners to get leagues for
     * @return the team's leagues
     * @see Riot
     *      API Specification
     */
    public static Map> getTeamLeagues(final String... teamIDs) {
        return getTeamLeagues(Arrays.asList(teamIDs));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy