Search in sources :

Example 31 with DataCallBuilder

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

the class DDragonAPI method getRealm.

public Realm getRealm(LeagueShard region) {
    DataCallBuilder builder = new DataCallBuilder().withLimiters(false).withProxy(Constants.DDRAGON_PROXY).withURLParameter(Constants.REGION_PLACEHOLDER, region.getRealmValue()).withEndpoint(URLEndpoint.DDRAGON_REALMS);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", region);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.DDRAGON_REALMS, data);
    if (chl.isPresent()) {
        return (Realm) chl.get();
    }
    try {
        Realm list = (Realm) builder.build();
        data.put("value", list);
        DataCall.getCacheProvider().store(URLEndpoint.DDRAGON_REALMS, data);
        return list;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Realm(no.stelar7.api.r4j.pojo.lol.staticdata.realm.Realm)

Example 32 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 == LeagueShard.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(this.platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("id", summonerId);
    data.put("champion", championId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
    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);
            data.put("value", mastery);
            DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
            return mastery;
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Logger.getGlobal().warning("Class has changed, please fix me");
        }
    }
    data.put("value", masterObj);
    DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
    return (ChampionMastery) masterObj;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) Pair(no.stelar7.api.r4j.basic.utils.Pair)

Example 33 with DataCallBuilder

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

the class MatchBuilder method getMatchRAW.

public GAMHSMatch getMatchRAW() {
    if (this.id.isEmpty() || this.platform == RegionShard.UNKNOWN) {
        return null;
    }
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, this.id).withEndpoint(URLEndpoint.V5_MATCH).withPlatform(this.platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", this.platform);
    data.put("gameid", this.id);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V5_MATCH, data);
    if (chl.isPresent()) {
        return (GAMHSMatch) chl.get();
    }
    Object matchObj = builder.build();
    if (matchObj instanceof Pair) {
        return null;
    }
    GAMHSMatch match = (GAMHSMatch) matchObj;
    data.put("value", match);
    DataCall.getCacheProvider().store(URLEndpoint.V5_MATCH, data);
    return match;
}
Also used : GAMHSMatch(no.stelar7.api.r4j.pojo.shared.GAMHSMatch) Pair(no.stelar7.api.r4j.basic.utils.Pair)

Example 34 with DataCallBuilder

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

the class LCUApi method createNotification.

/**
 * Creates a notification
 *
 * @param title       title of notification
 * @param content     body of notification
 * @param icon        icon of notification
 * @param background  background image of notification
 * @param dismissable true if able to dismiss
 * @param state       read or unread
 * @return the notification id
 */
public static int createNotification(String title, String content, String icon, String background, boolean dismissable, String state) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        jw.beginObject().name("backgroundUrl").value(background).name("created").value(LocalDateTime.now().toString()).name("dismissible").value(dismissable).name("detailKey").value("pre_translated_details").name("titleKey").value("pre_translated_title").name("data").beginObject().name("title").value(title).name("content").value(content).endObject().name("iconUrl").value(icon).name("state").value(state).endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String postData = sw.toString();
    JsonObject obj = (JsonObject) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_CREATE_NOTIFICATION).withRequestMethod("POST").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
    return obj.get("id").getAsInt();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

Example 35 with DataCallBuilder

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

the class LCUApi method getReplaySavePath.

/**
 * Fetches the replay save path
 * @return the path
 */
public static String getReplaySavePath() {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    String obj = (String) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_REPLAY_DOWNLOAD_PATH).withRequestMethod("GET").withHeader(header.getKey(), header.getValue()).build();
    return obj;
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder)

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