Search in sources :

Example 21 with DataCallBuilder

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

the class TimelineBuilder method get.

/**
 * Returns the timeline relating to a match.
 * Not avaliable for matches older than a year
 *
 * @return MatchTimeline if avaliable
 */
public MatchTimeline get() {
    if (this.id == -1 || this.platform == Platform.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, String.valueOf(this.id)).withEndpoint(URLEndpoint.V3_TIMELINE).withPlatform(this.platform);
    Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_TIMELINE, this.platform, this.id);
    if (chl.isPresent()) {
        return (MatchTimeline) chl.get();
    }
    try {
        MatchTimeline timeline = (MatchTimeline) builder.build();
        DataCall.getCacheProvider().store(URLEndpoint.V3_TIMELINE, timeline, this.platform, this.id);
        return timeline;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Optional(java.util.Optional) MatchTimeline(no.stelar7.api.l4j8.pojo.match.MatchTimeline)

Example 22 with DataCallBuilder

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

the class SummonerBuilder method get.

/**
 * gets a summoner based on the parameters passed to the builder
 *
 * @return Summoner
 */
public Summoner get() {
    DataCallBuilder builder = new DataCallBuilder().withPlatform(this.platform);
    URLEndpoint endpoint = null;
    if (accId > 0) {
        builder.withURLParameter(Constants.ACCOUNT_ID_PLACEHOLDER, String.valueOf(this.accId));
        endpoint = URLEndpoint.V3_SUMMONER_BY_ACCOUNT;
    }
    if (sumId > 0) {
        builder.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.sumId));
        endpoint = URLEndpoint.V3_SUMMONER_BY_ID;
    }
    if (name.length() > 0) {
        builder.withURLParameter(Constants.SUMMONER_NAME_PLACEHOLDER, Utils.normalizeSummonerName(this.name));
        endpoint = URLEndpoint.V3_SUMMONER_BY_NAME;
    }
    builder.withEndpoint(endpoint);
    Optional chl = DataCall.getCacheProvider().get(endpoint, this.platform, this.accId, this.sumId, this.name);
    if (chl.isPresent()) {
        return (Summoner) chl.get();
    }
    Object sob = builder.build();
    if (sob instanceof Pair) {
        return null;
    }
    DataCall.getCacheProvider().store(endpoint, sob, this.platform, this.accId, this.sumId, this.name);
    return (Summoner) sob;
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) Optional(java.util.Optional)

Example 23 with DataCallBuilder

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

the class StatusAPI method getShardStatus.

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

Example 24 with DataCallBuilder

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

the class StatusAPI method getShardStatus.

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

Example 25 with DataCallBuilder

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

the class TFTMatchAPI method getMatchRAW.

public GAMHSMatch getMatchRAW(RegionShard platform, String gameId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, gameId).withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getTFTAPIKey()).withEndpoint(URLEndpoint.V1_TFT_MATCH).withPlatform(platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("gameid", gameId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_TFT_MATCH, data);
    if (chl.isPresent()) {
        return (GAMHSMatch) chl.get();
    }
    try {
        GAMHSMatch match = (GAMHSMatch) builder.build();
        data.put("value", match);
        DataCall.getCacheProvider().store(URLEndpoint.V1_TFT_MATCH, data);
        return match;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : GAMHSMatch(no.stelar7.api.r4j.pojo.shared.GAMHSMatch)

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