com.robrua.orianna.api.dto.LeagueAPI Maven / Gradle / Ivy
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