Skip to content

Commit 6a7434e

Browse files
committed
Add ingame api, add getter for client path and update generated models to 10.4
1 parent 98e3749 commit 6a7434e

File tree

134 files changed

+2125
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2125
-355
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Add the project as a dependency:
3333

3434
```java
3535
dependencies {
36-
compile 'com.github.stirante:lol-client-java-api:1.1.7'
36+
compile 'com.github.stirante:lol-client-java-api:1.2.0'
3737
}
3838
```
3939

@@ -56,7 +56,7 @@ Add the project as a dependency:
5656
<dependency>
5757
<groupId>com.github.stirante</groupId>
5858
<artifactId>lol-client-java-api</artifactId>
59-
<version>1.1.7</version>
59+
<version>1.2.0</version>
6060
</dependency>
6161
```
6262

@@ -252,6 +252,15 @@ public class WebSocketExample {
252252
}
253253
```
254254

255+
## Live game API
256+
257+
Since version 1.2.0, this api allows for requesting live game data. The example is in `src/main/java/examples/IngameApiExample.java`.
258+
To check how it's working, run this example while in game.
259+
260+
Generated documentation can be found [here](https://files.stirante.com/ingame-api.html) (not generated by me).
261+
262+
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).
263+
255264
## Contributing
256265
All contributions are appreciated.
257266
If you would like to contribute to this project, please send a pull request.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.stirante</groupId>
88
<artifactId>lol-client-java-api</artifactId>
9-
<version>1.1.8</version>
9+
<version>1.2.0</version>
1010

1111
<properties>
1212
<java.version>1.8</java.version>

src/main/java/com/stirante/lolclient/ClientApi.java

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonObject;
56
import generated.*;
67
import org.apache.http.client.config.RequestConfig;
78
import org.apache.http.client.entity.EntityBuilder;
@@ -83,11 +84,13 @@ public class ClientApi {
8384
"lol-simple-dialog-messages",
8485
"lol-spectator",
8586
"lol-suggested-players",
86-
"lol-trophies"
87+
"lol-trophies",
88+
"liveclientdata"
8789
);
8890
private static final Pattern INSTALL_DIR =
8991
Pattern.compile(".+\"--install-directory=([()a-zA-Z_0-9- :.\\\\/]+)\".+");
9092
private static final Gson GSON = new GsonBuilder().create();
93+
private static final int LIVE_PORT = 2999;
9194
/**
9295
* Enabled 'legacy' mode
9396
*/
@@ -227,6 +230,13 @@ public ClientApi(String clientPath, int connectTimeout, int readTimeout) {
227230
start();
228231
}
229232

233+
/**
234+
* @return a {@code java.lang.String} that points to the League of Legends client directory
235+
*/
236+
public String getClientPath() {
237+
return clientPath;
238+
}
239+
230240
/**
231241
* Adds client connection listener
232242
*/
@@ -516,20 +526,33 @@ public boolean isAuthorized() throws IOException {
516526
}
517527

518528
public String getSwaggerJson() throws IOException {
519-
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", new HttpGet()));
529+
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", port, new HttpGet()));
520530
}
521531

522532
public String getOpenapiJson() throws IOException {
523-
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", new HttpGet()));
533+
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", port, new HttpGet()));
534+
}
535+
536+
public String getLiveSwaggerJson() throws IOException {
537+
return dumpHttpRequest(getConnection("/swagger/v2/swagger.json", LIVE_PORT, new HttpGet()));
538+
}
539+
540+
public String getLiveOpenapiJson() throws IOException {
541+
return dumpHttpRequest(getConnection("/swagger/v3/openapi.json", LIVE_PORT, new HttpGet()));
524542
}
525543

526544
public <T> T executeGet(String path, Class<T> clz) throws IOException {
527-
HttpGet conn = getConnection(path, new HttpGet());
545+
HttpGet conn = getConnection(path, port, new HttpGet());
546+
return getResponseObject(clz, conn);
547+
}
548+
549+
public <T> T executeLiveGet(String path, Class<T> clz) throws IOException {
550+
HttpGet conn = getConnection(path, LIVE_PORT, new HttpGet());
528551
return getResponseObject(clz, conn);
529552
}
530553

531554
public InputStream executeBinaryGet(String path) throws IOException {
532-
HttpGet conn = getConnection(path, new HttpGet());
555+
HttpGet conn = getConnection(path, port, new HttpGet());
533556
CloseableHttpResponse response = client.execute(conn);
534557
boolean b = response.getStatusLine().getStatusCode() == 200;
535558
if (!b) {
@@ -540,45 +563,45 @@ public InputStream executeBinaryGet(String path) throws IOException {
540563
}
541564

542565
public <T> T executeGet(String path, Class<T> clz, String... queryParams) throws IOException {
543-
HttpGet conn = getConnection(path, new HttpGet(), queryParams);
566+
HttpGet conn = getConnection(path, port, new HttpGet(), queryParams);
544567
return getResponseObject(clz, conn);
545568
}
546569

547570
public boolean executePut(String path, Object jsonObject) throws IOException {
548-
HttpPut conn = getConnection(path, new HttpPut());
571+
HttpPut conn = getConnection(path, port, new HttpPut());
549572
addJsonBody(jsonObject, conn);
550573
return isOk(conn);
551574
}
552575

553576
public <T> T executePost(String path, Object jsonObject, Class<T> clz) throws IOException {
554-
HttpPost conn = getConnection(path, new HttpPost());
577+
HttpPost conn = getConnection(path, port, new HttpPost());
555578
addJsonBody(jsonObject, conn);
556579
return getResponseObject(clz, conn);
557580
}
558581

559582
public <T> T executePost(String path, Class<T> clz) throws IOException {
560-
HttpPost conn = getConnection(path, new HttpPost());
583+
HttpPost conn = getConnection(path, port, new HttpPost());
561584
return getResponseObject(clz, conn);
562585
}
563586

564587
public boolean executePost(String path, Object jsonObject) throws IOException {
565-
HttpPost conn = getConnection(path, new HttpPost());
588+
HttpPost conn = getConnection(path, port, new HttpPost());
566589
addJsonBody(jsonObject, conn);
567590
return isOk(conn);
568591
}
569592

570593
public boolean executePatch(String path, Object jsonObject) throws IOException {
571-
HttpPatch conn = getConnection(path, new HttpPatch());
594+
HttpPatch conn = getConnection(path, port, new HttpPatch());
572595
addJsonBody(jsonObject, conn);
573596
return isOk(conn);
574597
}
575598

576599
public boolean executePost(String path) throws IOException {
577-
return isOk(getConnection(path, new HttpPost()));
600+
return isOk(getConnection(path, port, new HttpPost()));
578601
}
579602

580603
public boolean executeDelete(String path) throws IOException {
581-
return isOk(getConnection(path, new HttpDelete()));
604+
return isOk(getConnection(path, port, new HttpDelete()));
582605
}
583606

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

695+
/**
696+
* @deprecated Will be removed someday. It should be moved and organized.
697+
*/
698+
@Deprecated
699+
public JsonObject getLiveGameData() throws IOException {
700+
return executeGet("/liveclientdata/allgamedata", JsonObject.class);
701+
}
702+
672703
/**
673704
* @deprecated Will be removed someday. It should be moved and organized.
674705
*/

0 commit comments

Comments
 (0)