Search in sources :

Example 26 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 JsonWriter (com.google.gson.stream.JsonWriter)6 Pair (no.stelar7.api.l4j8.basic.utils.Pair)6 java.awt (java.awt)4 AffineTransform (java.awt.geom.AffineTransform)4 java.awt.image (java.awt.image)4 java.io (java.io)4 Field (java.lang.reflect.Field)4 URL (java.net.URL)4 java.util (java.util)4 List (java.util.List)4 Predicate (java.util.function.Predicate)4 IntStream (java.util.stream.IntStream)4 ImageIO (javax.imageio.ImageIO)4 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)3 Pair (no.stelar7.api.r4j.basic.utils.Pair)3 Optional (java.util.Optional)2 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)2 DataCall (no.stelar7.api.l4j8.basic.calling.DataCall)2 Platform (no.stelar7.api.l4j8.basic.constants.api.Platform)2