Search in sources :

Example 16 with DataCallBuilder

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

the class StatusAPI method getShardStatus.

public PlatformData getShardStatus(RuneterraShard server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V1_STATUS_LOR).withPlatform(server);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", server);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_STATUS_LOR, data);
    if (chl.isPresent()) {
        return (PlatformData) chl.get();
    }
    try {
        PlatformData list = (PlatformData) builder.build();
        data.put("value", list);
        DataCall.getCacheProvider().store(URLEndpoint.V1_STATUS_LOR, data);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : PlatformData(no.stelar7.api.r4j.pojo.lol.status.PlatformData)

Example 17 with DataCallBuilder

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

the class ChampionBuilder method getFreeToPlayRotation.

public ChampionRotationInfo getFreeToPlayRotation() {
    if (this.platform == LeagueShard.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS).withPlatform(this.platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", this.platform);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
    if (chl.isPresent()) {
        return (ChampionRotationInfo) chl.get();
    }
    try {
        ChampionRotationInfo cl = (ChampionRotationInfo) builder.build();
        data.put("value", cl);
        DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
        return cl;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : ChampionRotationInfo(no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)

Example 18 with DataCallBuilder

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

the class ChampionAPI method getFreeToPlayRotation.

public ChampionRotationInfo getFreeToPlayRotation(LeagueShard server) {
    DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS).withPlatform(server);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", server);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
    if (chl.isPresent()) {
        return (ChampionRotationInfo) chl.get();
    }
    try {
        ChampionRotationInfo cl = (ChampionRotationInfo) builder.build();
        data.put("value", cl);
        DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
        return cl;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : ChampionRotationInfo(no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)

Example 19 with DataCallBuilder

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

the class ChampionMasteryBuilder method getChampionMastery.

public ChampionMastery getChampionMastery() {
    if (this.championId == null || this.summonerId == null || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.summonerId)).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V3_MASTERY_BY_CHAMPION).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MASTERY_BY_CHAMPION, this.platform, this.summonerId, this.championId);
    if (chl.isPresent()) {
        return (ChampionMastery) chl.get();
    }
    Object masterObj = builder.build();
    if (masterObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, this.summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, this.championId);
            Field level = mastery.getClass().getDeclaredField("championLevel");
            level.setAccessible(true);
            level.set(mastery, 0);
            DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, this.platform, this.summonerId, this.championId);
            return mastery;
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, masterObj, this.platform, this.summonerId, this.championId);
    return (ChampionMastery) masterObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

Example 20 with DataCallBuilder

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

the class MatchBuilder method get.

/**
 * Gets a match based on the parameters passed to the builder.
 * Matches older than 3 years will return null
 *
 * @return Match
 */
public Match get() {
    if (this.id < 0 || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, String.valueOf(this.id)).withEndpoint(URLEndpoint.V3_MATCH).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MATCH, this.platform, this.id);
    if (chl.isPresent()) {
        return (Match) chl.get();
    }
    Object matchObj = builder.build();
    if (matchObj instanceof Pair) {
        return null;
    }
    Match match = (Match) matchObj;
    DataCall.getCacheProvider().store(URLEndpoint.V3_MATCH, match, this.platform, this.id);
    return match;
}
Also used : Optional(java.util.Optional) Match(no.stelar7.api.l4j8.pojo.match.Match) Pair(no.stelar7.api.l4j8.basic.utils.Pair)

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