Search in sources :

Example 1 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.

the class MasteryAPI method getChampionMastery.

/**
 * The response object contains the summoners mastery of a champion.
 * Only championid and summonerid is present if the level == 0
 *
 * @param server     the region to execute against
 * @param summonerId the summonerId
 * @param championId the championId
 * @return Optional ChampionMastery
 */
public ChampionMastery getChampionMastery(Platform server, long summonerId, int championId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(summonerId)).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V3_MASTERY_BY_CHAMPION).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MASTERY_BY_CHAMPION, server, summonerId, championId);
    if (chl.isPresent()) {
        return (ChampionMastery) chl.get();
    }
    Object masteryObj = builder.build();
    if (masteryObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, championId);
            Field level = mastery.getClass().getDeclaredField("championLevel");
            level.setAccessible(true);
            level.set(mastery, 0);
            DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, server, summonerId, championId);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, masteryObj, server, summonerId, championId);
    return (ChampionMastery) masteryObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 2 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.

the class StaticAPI method getLanguageStrings.

public Map<String, String> getLanguageStrings(Platform server, @Nullable String version, @Nullable String locale) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS).withURLData(Constants.URL_PARAM_DATA_BY_ID, String.valueOf(true)).withPlatform(server);
    if (version != null) {
        builder.withURLData(Constants.VERSION_PLACEHOLDER_DATA, version);
    }
    if (locale != null) {
        builder.withURLData(Constants.LOCALE_PLACEHOLDER_DATA, locale);
    }
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS, server, version, locale);
    if (chl.isPresent()) {
        return ((LanguageStrings) chl.get()).getData();
    }
    try {
        LanguageStrings list = (LanguageStrings) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_STATIC_LANGUAGE_STRINGS, list, server, version, locale);
        return list.getData();
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : LanguageStrings(no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)

Example 3 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.

the class StaticAPI method getRealm.

public Realm getRealm(Platform server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_STATIC_REALMS).withURLData(Constants.URL_PARAM_DATA_BY_ID, String.valueOf(true)).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_STATIC_REALMS, server);
    if (chl.isPresent()) {
        return (Realm) chl.get();
    }
    try {
        Realm list = (Realm) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_STATIC_REALMS, list, server);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Realm(no.stelar7.api.l4j8.pojo.staticdata.realm.Realm)

Example 4 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.

the class StatusAPI method getShardStatus.

public ShardStatus getShardStatus(Platform server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_SHARD_STATUS).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_SHARD_STATUS, server);
    if (chl.isPresent()) {
        return (ShardStatus) chl.get();
    }
    try {
        ShardStatus list = (ShardStatus) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_SHARD_STATUS, list, server);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : ShardStatus(no.stelar7.api.l4j8.pojo.status.ShardStatus) Optional(java.util.Optional)

Example 5 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.

the class SummonerAPI method getSummonerByName.

/**
 * The response object contains the summoner objects mapped by their username.
 *
 * @param server       the region to execute against
 * @param summonerName summoner name  associated with summoner to retrieve.
 * @return Optional Summoner
 */
public Summoner getSummonerByName(final Platform server, String summonerName) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_NAME_PLACEHOLDER, Utils.normalizeSummonerName(summonerName)).withEndpoint(URLEndpoint.V3_SUMMONER_BY_NAME).withPlatform(server);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_SUMMONER_BY_NAME, server, "", "", summonerName);
    if (chl.isPresent()) {
        return (Summoner) chl.get();
    }
    try {
        Summoner summoner = (Summoner) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_NAME, summoner, server, "", "", summonerName);
        return summoner;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) Optional(java.util.Optional)

Aggregations

DataCallBuilder (no.stelar7.api.r4j.basic.calling.DataCallBuilder)11 Optional (java.util.Optional)7 JsonWriter (com.google.gson.stream.JsonWriter)6 Field (java.lang.reflect.Field)4 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)4 Pair (no.stelar7.api.r4j.basic.utils.Pair)4 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)4 GAMHSMatch (no.stelar7.api.r4j.pojo.shared.GAMHSMatch)4 Pair (no.stelar7.api.l4j8.basic.utils.Pair)3 PlatformData (no.stelar7.api.r4j.pojo.lol.status.PlatformData)3 ChampionMastery (no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery)2 APIResponseException (no.stelar7.api.r4j.basic.exceptions.APIResponseException)2 ChampionRotationInfo (no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)2 ChampionMastery (no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery)2 Match (no.stelar7.api.l4j8.pojo.match.Match)1 MatchTimeline (no.stelar7.api.l4j8.pojo.match.MatchTimeline)1 LanguageStrings (no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)1 Realm (no.stelar7.api.l4j8.pojo.staticdata.realm.Realm)1 ShardStatus (no.stelar7.api.l4j8.pojo.status.ShardStatus)1 LanguageStrings (no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings)1