Search in sources :

Example 41 with DataCallBuilder

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

the class LORMatchAPI method getMatchRAW.

public GAMHSMatch getMatchRAW(RuneterraShard 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_LOR_MATCH).withPlatform(platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("gameid", gameId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_LOR_MATCH, data);
    if (chl.isPresent()) {
        return (GAMHSMatch) chl.get();
    }
    try {
        GAMHSMatch match = (GAMHSMatch) builder.build();
        data.put("value", match);
        DataCall.getCacheProvider().store(URLEndpoint.V1_LOR_MATCH, data);
        return match;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : GAMHSMatch(no.stelar7.api.r4j.pojo.shared.GAMHSMatch)

Example 42 with DataCallBuilder

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

the class DDragonAPI method getLanguageStrings.

public Map<String, String> getLanguageStrings(String version, String locale) {
    DataCallBuilder builder = new DataCallBuilder().withLimiters(false).withProxy(Constants.DDRAGON_PROXY).withEndpoint(URLEndpoint.DDRAGON_LANGUAGE_STRINGS);
    builder.withURLParameter(Constants.VERSION_PLACEHOLDER, version == null ? getVersions().get(0) : version);
    builder.withURLParameter(Constants.LOCALE_PLACEHOLDER, locale == null ? "en_US" : locale);
    Map<String, Object> data = new TreeMap<>();
    data.put("version", version);
    data.put("locale", locale);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.DDRAGON_LANGUAGE_STRINGS, data);
    if (chl.isPresent()) {
        return ((LanguageStrings) chl.get()).getData();
    }
    try {
        Object ret = builder.build();
        if (ret instanceof Pair) {
            return Collections.emptyMap();
        }
        LanguageStrings list = (LanguageStrings) ret;
        data.put("value", list);
        DataCall.getCacheProvider().store(URLEndpoint.DDRAGON_LANGUAGE_STRINGS, data);
        return list.getData();
    } catch (ClassCastException e) {
        return Collections.emptyMap();
    }
}
Also used : LanguageStrings(no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings) Pair(no.stelar7.api.r4j.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