Skip to content

Commit 8d3877f

Browse files
committed
Save cookies globally
1 parent 789705f commit 8d3877f

6 files changed

Lines changed: 32 additions & 30 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Below is an example on how to login to the API and fetch your own user informati
5353
// e.g. (WorldsApi, UsersApi, FilesApi, NotificationsApi, FriendsApi, etc...)
5454
// Here we instantiate the Authentication API which is required for logging in.
5555
ApiClient defaultClient = Configuration.getDefaultApiClient();
56-
AuthenticationApi apiInstance = new AuthenticationApi(defaultClient);
56+
AuthenticationApi authApi = new AuthenticationApi(defaultClient);
5757

5858
// Step 2. We begin with creating a Configuration
5959
// This contains the username and password for authentication.
@@ -66,7 +66,7 @@ authCookie.setApiKey("JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26");
6666

6767
// Step 3. Call getCurrentUser on Authentication API.
6868
// This logs you in if the user isn't already logged in.
69-
CurrentUser result = apiInstance.getCurrentUser();
69+
CurrentUser result = authApi.getCurrentUser();
7070
System.out.println(result.getDisplayName());
7171
```
7272

‎examples/.classpath‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,9 @@
66
<attribute name="maven.pomderived" value="true"/>
77
</attributes>
88
</classpathentry>
9-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10-
<attributes>
11-
<attribute name="maven.pomderived" value="true"/>
12-
</attributes>
13-
</classpathentry>
14-
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15-
<attributes>
16-
<attribute name="optional" value="true"/>
17-
<attribute name="maven.pomderived" value="true"/>
18-
<attribute name="test" value="true"/>
19-
</attributes>
20-
</classpathentry>
21-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
22-
<attributes>
23-
<attribute name="maven.pomderived" value="true"/>
24-
<attribute name="test" value="true"/>
25-
</attributes>
26-
</classpathentry>
279
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
2810
<attributes>
11+
<attribute name="module" value="true"/>
2912
<attribute name="maven.pomderived" value="true"/>
3013
</attributes>
3114
</classpathentry>

‎examples/pom.xml‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
<maven.compiler.target>1.8</maven.compiler.target>
1313
</properties>
1414

15-
<repositories>
16-
<repository>
17-
<id>github-vrchatapi</id>
18-
<name>your custom repo</name>
19-
<url>https://maven.pkg.github.com</url>
20-
</repository>
21-
</repositories>
15+
<repositories>
16+
<repository>
17+
<id>jitpack.io</id>
18+
<url>https://jitpack.io</url>
19+
</repository>
20+
</repositories>
2221

2322
<dependencies>
2423
<dependency>
25-
<groupId>io.github.vrchatapi</groupId>
26-
<artifactId>vrchatapi</artifactId>
24+
<groupId>com.github.vrchatapi</groupId>
25+
<artifactId>vrchatapi-java</artifactId>
2726
<version>1.0.1</version>
2827
</dependency>
2928
</dependencies>

‎generate.sh‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,17 @@ openapi-generator-cli generate \
88
--git-repo-id=vrchatapi-java \
99
-o . \
1010
-i https://vrchatapi.github.io/specification/openapi.yaml \
11-
--http-user-agent="vrchatapi-java"
11+
--http-user-agent="vrchatapi-java"
12+
13+
sed -i '/<\/dependencies>/i \
14+
<!-- Custom VRChat API dependencies -->\
15+
<dependency>\
16+
<groupId>com.squareup.okhttp3</groupId>\
17+
<artifactId>okhttp-urlconnection</artifactId>\
18+
<version>${okhttp-version}</version>\
19+
</dependency>' pom.xml
20+
21+
addNetworkInterceptor
22+
23+
sed -i '/addNetworkInterceptor/a \
24+
builder.cookieJar(new JavaNetCookieJar(new java.net.CookieManager()));' src/main/java/io/github/vrchatapi/ApiClient.java

‎pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@
275275
<version>3.11.2</version>
276276
<scope>test</scope>
277277
</dependency>
278+
<!-- Custom VRChat API dependencies -->
279+
<dependency>
280+
<groupId>com.squareup.okhttp3</groupId>
281+
<artifactId>okhttp-urlconnection</artifactId>
282+
<version>${okhttp-version}</version>
283+
</dependency>
278284
</dependencies>
279285
<properties>
280286
<java.version>1.7</java.version>

‎src/main/java/io/github/vrchatapi/ApiClient.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private void initHttpClient() {
120120
private void initHttpClient(List<Interceptor> interceptors) {
121121
OkHttpClient.Builder builder = new OkHttpClient.Builder();
122122
builder.addNetworkInterceptor(getProgressInterceptor());
123+
builder.cookieJar(new JavaNetCookieJar(new java.net.CookieManager()));
123124
for (Interceptor interceptor: interceptors) {
124125
builder.addInterceptor(interceptor);
125126
}

0 commit comments

Comments
 (0)