Search in sources :

Example 1 with LanguageStrings

use of no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings 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 2 with LanguageStrings

use of no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings 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

LanguageStrings (no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)1 Pair (no.stelar7.api.r4j.basic.utils.Pair)1 LanguageStrings (no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings)1