Search in sources :

Example 6 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair in project L4J8 by stelar7.

the class LCUApi method customUrl.

/**
 * Makes a call to a url not specifically supported in the api
 *
 * @param url      the url to call
 * @param postData null if not a POST call
 * @param method the http method to use
 * @return whatever the api returns
 */
public static Object customUrl(String url, String postData, String method) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    DataCallBuilder obj = new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + url).withPostData(postData).withRequestMethod(method).withHeader(header.getKey(), header.getValue());
    return obj.build();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder)

Example 7 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair in project L4J8 by stelar7.

the class LCUApi method setLobbyPositions.

/**
 * Sets your roles in the lobby
 * @param primary first role
 * @param secondary second role
 */
public static void setLobbyPositions(LCULobbyPositionType primary, LCULobbyPositionType secondary) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        jw.beginObject().name("firstPreference").value(primary.name()).name("secondPreference").value(secondary.name()).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_LOBBY_POSITION).withRequestMethod("PUT").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

Example 8 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair in project L4J8 by stelar7.

the class MasteryAPI method getChampionMastery.

/**
 * The response object contains the summoners mastery of a champion.
 * Only championid and summonerid is present if the level == 0
 *
 * @param server     the region to execute against
 * @param summonerId the summonerId
 * @param championId the championId
 * @return Optional ChampionMastery
 */
public ChampionMastery getChampionMastery(LeagueShard server, String summonerId, int championId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(server);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", server);
    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 masteryObj = builder.build();
    if (masteryObj instanceof Pair) {
        try {
            ChampionMastery mastery = new ChampionMastery();
            Field player = mastery.getClass().getDeclaredField("playerId");
            player.setAccessible(true);
            player.set(mastery, summonerId);
            Field champ = mastery.getClass().getDeclaredField("championId");
            champ.setAccessible(true);
            champ.set(mastery, 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", masteryObj);
    DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
    return (ChampionMastery) masteryObj;
}
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 9 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair in project L4J8 by stelar7.

the class LCUApi method restart.

/**
 * Restarts the client after waitTimeout seconds
 * @param waitTimeout the time to wait in seconds
 */
public static void restart(int waitTimeout) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_RESTART).withHeader(header.getKey(), header.getValue()).withQueryParameter("delaySeconds", String.valueOf(waitTimeout)).withRequestMethod("POST").build();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder)

Example 10 with Pair

use of no.stelar7.api.l4j8.basic.utils.Pair in project L4J8 by stelar7.

the class LCUApi method inviteSummoner.

/**
 * Invites the summoner to your game
 * @param name the name
 */
public static void inviteSummoner(String name) {
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        JsonObject obj = getSummoner(name);
        jw.beginArray().beginObject().name("toSummonerId").value(obj.get("summonerId").getAsString()).name("toSummonerName").value(obj.get("internalName").getAsString()).endObject().endArray();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String postData = sw.toString();
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    JsonArray obj = (JsonArray) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_LOBBY_INVITE).withRequestMethod("POST").withHeader(header.getKey(), header.getValue()).withPostData(postData).build();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

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