Search in sources :

Example 16 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 17 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 18 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 19 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 20 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair 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 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