Skip to content

Commit

Permalink
Add ingame api, add getter for client path and update generated model…
Browse files Browse the repository at this point in the history
…s to 10.4
  • Loading branch information
stirante committed Feb 26, 2020
1 parent 98e3749 commit 6a7434e
Show file tree
Hide file tree
Showing 134 changed files with 2,125 additions and 355 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Add the project as a dependency:

```java
dependencies {
compile 'com.github.stirante:lol-client-java-api:1.1.7'
compile 'com.github.stirante:lol-client-java-api:1.2.0'
}
```

Expand All @@ -56,7 +56,7 @@ Add the project as a dependency:
<dependency>
<groupId>com.github.stirante</groupId>
<artifactId>lol-client-java-api</artifactId>
<version>1.1.7</version>
<version>1.2.0</version>
</dependency>
```

Expand Down Expand Up @@ -252,6 +252,15 @@ public class WebSocketExample {
}
```

## Live game API

Since version 1.2.0, this api allows for requesting live game data. The example is in `src/main/java/examples/IngameApiExample.java`.
To check how it's working, run this example while in game.

Generated documentation can be found [here](https://files.stirante.com/ingame-api.html) (not generated by me).

Generated models for live game API are in `generated.live` package (It's not very useful right now, because the schema in documentation is lacking. I hope it will be added in the future).

## Contributing
All contributions are appreciated.
If you would like to contribute to this project, please send a pull request.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.stirante</groupId>
<artifactId>lol-client-java-api</artifactId>
<version>1.1.8</version>
<version>1.2.0</version>

<properties>
<java.version>1.8</java.version>
Expand Down
61 changes: 46 additions & 15 deletions src/main/java/com/stirante/lolclient/ClientApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import generated.*;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.EntityBuilder;
Expand Down Expand Up @@ -83,11 +84,13 @@ public class ClientApi {
"lol-simple-dialog-messages",
"lol-spectator",
"lol-suggested-players",
"lol-trophies"
"lol-trophies",
"liveclientdata"
);
private static final Pattern INSTALL_DIR =
Pattern.compile(".+\"--install-directory=([()a-zA-Z_0-9- :.\\\\/]+)\".+");
private static final Gson GSON = new GsonBuilder().create();
private static final int LIVE_PORT = 2999;
/**
* Enabled 'legacy' mode
*/
Expand Down Expand Up @@ -227,6 +230,13 @@ public ClientApi(String clientPath, int connectTimeout, int readTimeout) {
start();
}

/**
* @return a {@code java.lang.String} that points to the League of Legends client directory
*/
public String getClientPath() {
return clientPath;
}

/**
* Adds client connection listener
*/
Expand Down Expand Up @@ -516,20 +526,33 @@ public boolean isAuthorized() throws IOException {
}

public String getSwaggerJson() throws IOException {
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", new HttpGet()));
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", port, new HttpGet()));
}

public String getOpenapiJson() throws IOException {
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", new HttpGet()));
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", port, new HttpGet()));
}

public String getLiveSwaggerJson() throws IOException {
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", LIVE_PORT, new HttpGet()));
}

public String getLiveOpenapiJson() throws IOException {
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", LIVE_PORT, new HttpGet()));
}

public <T> T executeGet(String path, Class<T> clz) throws IOException {
HttpGet conn = getConnection(path, new HttpGet());
HttpGet conn = getConnection(path, port, new HttpGet());
return getResponseObject(clz, conn);
}

public <T> T executeLiveGet(String path, Class<T> clz) throws IOException {
HttpGet conn = getConnection(path, LIVE_PORT, new HttpGet());
return getResponseObject(clz, conn);
}

public InputStream executeBinaryGet(String path) throws IOException {
HttpGet conn = getConnection(path, new HttpGet());
HttpGet conn = getConnection(path, port, new HttpGet());
CloseableHttpResponse response = client.execute(conn);
boolean b = response.getStatusLine().getStatusCode() == 200;
if (!b) {
Expand All @@ -540,45 +563,45 @@ public InputStream executeBinaryGet(String path) throws IOException {
}

public <T> T executeGet(String path, Class<T> clz, String... queryParams) throws IOException {
HttpGet conn = getConnection(path, new HttpGet(), queryParams);
HttpGet conn = getConnection(path, port, new HttpGet(), queryParams);
return getResponseObject(clz, conn);
}

public boolean executePut(String path, Object jsonObject) throws IOException {
HttpPut conn = getConnection(path, new HttpPut());
HttpPut conn = getConnection(path, port, new HttpPut());
addJsonBody(jsonObject, conn);
return isOk(conn);
}

public <T> T executePost(String path, Object jsonObject, Class<T> clz) throws IOException {
HttpPost conn = getConnection(path, new HttpPost());
HttpPost conn = getConnection(path, port, new HttpPost());
addJsonBody(jsonObject, conn);
return getResponseObject(clz, conn);
}

public <T> T executePost(String path, Class<T> clz) throws IOException {
HttpPost conn = getConnection(path, new HttpPost());
HttpPost conn = getConnection(path, port, new HttpPost());
return getResponseObject(clz, conn);
}

public boolean executePost(String path, Object jsonObject) throws IOException {
HttpPost conn = getConnection(path, new HttpPost());
HttpPost conn = getConnection(path, port, new HttpPost());
addJsonBody(jsonObject, conn);
return isOk(conn);
}

public boolean executePatch(String path, Object jsonObject) throws IOException {
HttpPatch conn = getConnection(path, new HttpPatch());
HttpPatch conn = getConnection(path, port, new HttpPatch());
addJsonBody(jsonObject, conn);
return isOk(conn);
}

public boolean executePost(String path) throws IOException {
return isOk(getConnection(path, new HttpPost()));
return isOk(getConnection(path, port, new HttpPost()));
}

public boolean executeDelete(String path) throws IOException {
return isOk(getConnection(path, new HttpDelete()));
return isOk(getConnection(path, port, new HttpDelete()));
}

private <T extends HttpEntityEnclosingRequestBase> void addJsonBody(Object jsonObject, T method) {
Expand Down Expand Up @@ -619,7 +642,7 @@ private <T extends HttpRequestBase> boolean isOk(T method) throws IOException {
* @param method Base request
* @param queryParams Pairs of get parameters. Must be divisible by 2.
*/
private <T extends HttpRequestBase> T getConnection(String endpoint, T method, String... queryParams) {
private <T extends HttpRequestBase> T getConnection(String endpoint, int port, T method, String... queryParams) {
if (!connected.get()) {
throw new IllegalStateException("API not connected!");
}
Expand All @@ -641,7 +664,7 @@ private <T extends HttpRequestBase> T getConnection(String endpoint, T method, S
sb.append(queryParams[i]).append("=").append(queryParams[i + 1]);
}
URI uri = new URI(sb.toString());
if (!disableEndpointWarnings.get()) {
if (!disableEndpointWarnings.get() && uri.getPath().substring(1).indexOf('/') != -1) {
String path = uri.getPath().substring(1, uri.getPath().substring(1).indexOf('/') + 1);
if (!ALLOWED_ENDPOINTS.contains(path)) {
System.err.println(
Expand Down Expand Up @@ -669,6 +692,14 @@ public LolRsoAuthAuthorization getAuth() throws IOException {
return executeGet("/rso-auth/v1/authorization", LolRsoAuthAuthorization.class);
}

/**
* @deprecated Will be removed someday. It should be moved and organized.
*/
@Deprecated
public JsonObject getLiveGameData() throws IOException {
return executeGet("/liveclientdata/allgamedata", JsonObject.class);
}

/**
* @deprecated Will be removed someday. It should be moved and organized.
*/
Expand Down
Loading

0 comments on commit 6a7434e

Please sign in to comment.