Search in sources :

Example 36 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder 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 37 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder 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 38 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder 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 39 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder 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 40 with DataCallBuilder

use of no.stelar7.api.r4j.basic.calling.DataCallBuilder 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 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