Search in sources :

Example 21 with Pair

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

the class LCUApi method joinLobby.

/**
 * Joins the lobby with the specified id
 * <p>
 * returns true if lobby exists, and we are able to join
 * @param id the lobbyid
 * @return true if able to join
 */
public static boolean joinLobby(String id) {
    try {
        Pair<String, String> header = LCUConnection.getAuthorizationHeader();
        new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_LOBBY_JOIN).withURLParameter(Constants.ID_PLACEHOLDER, id).withRequestMethod("POST").withHeader(header.getKey(), header.getValue()).build();
        return true;
    } catch (APIResponseException e) {
        return false;
    }
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) APIResponseException(no.stelar7.api.r4j.basic.exceptions.APIResponseException)

Example 22 with Pair

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

the class LCUApi method downloadReplay.

/**
 * Downloads replay
 * @param gameid the id to download
 */
public static void downloadReplay(Long gameid) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        jw.beginObject().name("componentType").value("string").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_REPLAY_DOWNLOAD).withRequestMethod("POST").withURLParameter(Constants.GAMEID_PLACEHOLDER, gameid.toString()).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 23 with Pair

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

the class LCUApi method login.

/**
 * Attempts to login to the client
 *
 * @param username your username
 * @param password your password
 * @return the login object
 */
public static JsonObject login(String username, String password) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        jw.beginObject().name("username").value(username).name("password").value(password).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_LOGIN).withRequestMethod("POST").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
    return obj;
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

Example 24 with Pair

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

the class LCUApi method spectateGame.

/**
 * Start spectator on game
 * @param gameid the id to spectate
 */
public static void spectateGame(Long gameid) {
    Pair<String, String> header = LCUConnection.getAuthorizationHeader();
    StringWriter sw = new StringWriter();
    try {
        JsonWriter jw = new JsonWriter(sw);
        jw.beginObject().name("componentType").value("string").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_REPLAY_WATCH).withRequestMethod("POST").withURLParameter(Constants.GAMEID_PLACEHOLDER, gameid.toString()).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 25 with Pair

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

the class LiveClientDataAPI method getGameData.

public static ActiveGameData getGameData() {
    try {
        Object data = new DataCallBuilder().withLimiters(false).withProxy(Constants.CLIENT_PROXY).withEndpoint(URLEndpoint.LIVECLIENT_GAME_DATA).withRequestMethod("GET").build();
        if (data instanceof Pair) {
            return null;
        }
        JsonObject obj = ((JsonElement) data).getAsJsonObject();
        ActiveGameData returnMe = new ActiveGameData(Utils.getGson().fromJson(obj.get("activePlayer"), ActiveGameClientPlayer.class), Utils.getGson().fromJson(obj.get("allPlayers"), new TypeToken<List<ActiveGamePlayer>>() {
        }.getType()), parseEventObjectToList(obj.get("events")), Utils.getGson().fromJson(obj.get("gameData"), ActiveGameState.class));
        return returnMe;
    } catch (APIResponseException e) {
        return null;
    }
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) APIResponseException(no.stelar7.api.r4j.basic.exceptions.APIResponseException)

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