Skip to content

Commit 2defb18

Browse files
Automatically update Java SDK
1 parent ae421c4 commit 2defb18

12 files changed

Lines changed: 687 additions & 13 deletions

‎.fern/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"enable-forward-compatible-enums": false,
77
"retry-status-codes": "legacy"
88
},
9-
"originGitCommit": "19712978734e8ed2f50ee8914cc8ff1f3a01c459",
9+
"originGitCommit": "ecf3b4b5a4d81bc291b24618eb182a70526728e2",
1010
"originGitCommitIsDirty": false,
1111
"invokedBy": "ci",
1212
"ciProvider": "github"

‎.gitignore‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ hs_err_pid*
2424
replay_pid*
2525

2626
# OSX
27-
.DS_Store
28-
29-
# Maven
30-
target/
27+
.DS_Store

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- General project information -->
99
<groupId>so.trophy</groupId>
1010
<artifactId>trophy-java</artifactId>
11-
<version>1.25.0</version>
11+
<version>1.26.0</version>
1212
<packaging>jar</packaging>
1313
<name>Trophy</name>
1414
<description>Java client library for the Trophy API</description>

‎src/main/java/so/trophy/core/ClientOptions.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private ClientOptions(Environment environment, Map<String, String> headers,
3535
this.environment = environment;
3636
this.headers = new HashMap<>();
3737
this.headers.putAll(headers);
38-
this.headers.putAll(new HashMap<String,String>() {{put("X-Fern-Language", "JAVA");put("X-Fern-SDK-Name", "com.trophy.fern:api-sdk");put("X-Fern-SDK-Version", "0.0.7518");}});
38+
this.headers.putAll(new HashMap<String,String>() {{put("X-Fern-Language", "JAVA");put("X-Fern-SDK-Name", "com.trophy.fern:api-sdk");put("X-Fern-SDK-Version", "0.0.8002");}});
3939
this.headerSuppliers = headerSuppliers;
4040
this.httpClient = httpClient;
4141
this.timeout = timeout;

‎src/main/java/so/trophy/resources/admin/streaks/AsyncRawStreaksClient.java‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import okhttp3.Response;
3333
import okhttp3.ResponseBody;
3434
import org.jetbrains.annotations.NotNull;
35+
import so.trophy.resources.admin.streaks.requests.ResetStreaksRequest;
3536
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
37+
import so.trophy.types.ResetStreaksResponse;
3638
import so.trophy.types.RestoreStreaksResponse;
3739

3840
public class AsyncRawStreaksClient {
@@ -122,4 +124,85 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
122124
});
123125
return future;
124126
}
125-
}
127+
128+
/**
129+
* Reset the current streak to zero for multiple users.
130+
*/
131+
public CompletableFuture<TrophyApiHttpResponse<ResetStreaksResponse>> reset(
132+
ResetStreaksRequest request) {
133+
return reset(request,null);
134+
}
135+
136+
/**
137+
* Reset the current streak to zero for multiple users.
138+
*/
139+
public CompletableFuture<TrophyApiHttpResponse<ResetStreaksResponse>> reset(
140+
ResetStreaksRequest request, RequestOptions requestOptions) {
141+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
142+
143+
.addPathSegments("streaks/reset");if (requestOptions != null) {
144+
requestOptions.getQueryParameters().forEach((_key, _value) -> {
145+
httpUrl.addQueryParameter(_key, _value);
146+
} );
147+
}
148+
RequestBody body;
149+
try {
150+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
151+
}
152+
catch(JsonProcessingException e) {
153+
throw new TrophyApiException("Failed to serialize request", e);
154+
}
155+
Request okhttpRequest = new Request.Builder()
156+
.url(httpUrl.build())
157+
.method("POST", body)
158+
.headers(Headers.of(clientOptions.headers(requestOptions)))
159+
.addHeader("Content-Type", "application/json")
160+
.addHeader("Accept", "application/json")
161+
.build();
162+
OkHttpClient client = clientOptions.httpClient();
163+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
164+
client = clientOptions.httpClientWithTimeout(requestOptions);
165+
}
166+
if (requestOptions != null && requestOptions.getMaxRetries().isPresent()) {
167+
okhttpRequest = okhttpRequest.newBuilder().tag(RetryInterceptor.MaxRetriesOverride.class, new RetryInterceptor.MaxRetriesOverride(requestOptions.getMaxRetries().get())).build();
168+
}
169+
CompletableFuture<TrophyApiHttpResponse<ResetStreaksResponse>> future = new CompletableFuture<>();
170+
client.newCall(okhttpRequest).enqueue(new Callback() {
171+
@Override
172+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
173+
try (ResponseBody responseBody = response.body()) {
174+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
175+
if (response.isSuccessful()) {
176+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ResetStreaksResponse.class), response));
177+
return;
178+
}
179+
try {
180+
switch (response.code()) {
181+
case 400:future.completeExceptionally(new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
182+
return;
183+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
184+
return;
185+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
186+
return;
187+
}
188+
}
189+
catch (JsonProcessingException ignored) {
190+
// unable to map error response, throwing generic error
191+
}
192+
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
193+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), errorBody, response));
194+
return;
195+
}
196+
catch (IOException e) {
197+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
198+
}
199+
}
200+
201+
@Override
202+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
203+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
204+
}
205+
});
206+
return future;
207+
}
208+
}

‎src/main/java/so/trophy/resources/admin/streaks/AsyncStreaksClient.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import java.util.function.Supplier;
1313
import so.trophy.resources.admin.streaks.freezes.AsyncFreezesClient;
1414
import so.trophy.resources.admin.streaks.pauses.AsyncPausesClient;
15+
import so.trophy.resources.admin.streaks.requests.ResetStreaksRequest;
1516
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
1617
import so.trophy.resources.admin.streaks.settings.AsyncSettingsClient;
18+
import so.trophy.types.ResetStreaksResponse;
1719
import so.trophy.types.RestoreStreaksResponse;
1820

1921
public class AsyncStreaksClient {
@@ -57,6 +59,21 @@ public CompletableFuture<RestoreStreaksResponse> restore(RestoreStreaksRequest r
5759
return this.rawClient.restore(request, requestOptions).thenApply(response -> response.body());
5860
}
5961

62+
/**
63+
* Reset the current streak to zero for multiple users.
64+
*/
65+
public CompletableFuture<ResetStreaksResponse> reset(ResetStreaksRequest request) {
66+
return this.rawClient.reset(request).thenApply(response -> response.body());
67+
}
68+
69+
/**
70+
* Reset the current streak to zero for multiple users.
71+
*/
72+
public CompletableFuture<ResetStreaksResponse> reset(ResetStreaksRequest request,
73+
RequestOptions requestOptions) {
74+
return this.rawClient.reset(request, requestOptions).thenApply(response -> response.body());
75+
}
76+
6077
public AsyncFreezesClient freezes() {
6178
return this.freezesClient.get();
6279
}

‎src/main/java/so/trophy/resources/admin/streaks/RawStreaksClient.java‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import okhttp3.RequestBody;
2828
import okhttp3.Response;
2929
import okhttp3.ResponseBody;
30+
import so.trophy.resources.admin.streaks.requests.ResetStreaksRequest;
3031
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
32+
import so.trophy.types.ResetStreaksResponse;
3133
import so.trophy.types.RestoreStreaksResponse;
3234

3335
public class RawStreaksClient {
@@ -100,4 +102,68 @@ public TrophyApiHttpResponse<RestoreStreaksResponse> restore(RestoreStreaksReque
100102
throw new TrophyApiException("Network error executing HTTP request", e);
101103
}
102104
}
103-
}
105+
106+
/**
107+
* Reset the current streak to zero for multiple users.
108+
*/
109+
public TrophyApiHttpResponse<ResetStreaksResponse> reset(ResetStreaksRequest request) {
110+
return reset(request,null);
111+
}
112+
113+
/**
114+
* Reset the current streak to zero for multiple users.
115+
*/
116+
public TrophyApiHttpResponse<ResetStreaksResponse> reset(ResetStreaksRequest request,
117+
RequestOptions requestOptions) {
118+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
119+
120+
.addPathSegments("streaks/reset");if (requestOptions != null) {
121+
requestOptions.getQueryParameters().forEach((_key, _value) -> {
122+
httpUrl.addQueryParameter(_key, _value);
123+
} );
124+
}
125+
RequestBody body;
126+
try {
127+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
128+
}
129+
catch(JsonProcessingException e) {
130+
throw new TrophyApiException("Failed to serialize request", e);
131+
}
132+
Request okhttpRequest = new Request.Builder()
133+
.url(httpUrl.build())
134+
.method("POST", body)
135+
.headers(Headers.of(clientOptions.headers(requestOptions)))
136+
.addHeader("Content-Type", "application/json")
137+
.addHeader("Accept", "application/json")
138+
.build();
139+
OkHttpClient client = clientOptions.httpClient();
140+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
141+
client = clientOptions.httpClientWithTimeout(requestOptions);
142+
}
143+
if (requestOptions != null && requestOptions.getMaxRetries().isPresent()) {
144+
okhttpRequest = okhttpRequest.newBuilder().tag(RetryInterceptor.MaxRetriesOverride.class, new RetryInterceptor.MaxRetriesOverride(requestOptions.getMaxRetries().get())).build();
145+
}
146+
try (Response response = client.newCall(okhttpRequest).execute()) {
147+
ResponseBody responseBody = response.body();
148+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
149+
if (response.isSuccessful()) {
150+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ResetStreaksResponse.class), response);
151+
}
152+
try {
153+
switch (response.code()) {
154+
case 400:throw new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
155+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
156+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
157+
}
158+
}
159+
catch (JsonProcessingException ignored) {
160+
// unable to map error response, throwing generic error
161+
}
162+
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
163+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), errorBody, response);
164+
}
165+
catch (IOException e) {
166+
throw new TrophyApiException("Network error executing HTTP request", e);
167+
}
168+
}
169+
}

‎src/main/java/so/trophy/resources/admin/streaks/StreaksClient.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import java.util.function.Supplier;
1212
import so.trophy.resources.admin.streaks.freezes.FreezesClient;
1313
import so.trophy.resources.admin.streaks.pauses.PausesClient;
14+
import so.trophy.resources.admin.streaks.requests.ResetStreaksRequest;
1415
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
1516
import so.trophy.resources.admin.streaks.settings.SettingsClient;
17+
import so.trophy.types.ResetStreaksResponse;
1618
import so.trophy.types.RestoreStreaksResponse;
1719

1820
public class StreaksClient {
@@ -56,6 +58,20 @@ public RestoreStreaksResponse restore(RestoreStreaksRequest request,
5658
return this.rawClient.restore(request, requestOptions).body();
5759
}
5860

61+
/**
62+
* Reset the current streak to zero for multiple users.
63+
*/
64+
public ResetStreaksResponse reset(ResetStreaksRequest request) {
65+
return this.rawClient.reset(request).body();
66+
}
67+
68+
/**
69+
* Reset the current streak to zero for multiple users.
70+
*/
71+
public ResetStreaksResponse reset(ResetStreaksRequest request, RequestOptions requestOptions) {
72+
return this.rawClient.reset(request, requestOptions).body();
73+
}
74+
5975
public FreezesClient freezes() {
6076
return this.freezesClient.get();
6177
}

0 commit comments

Comments
 (0)