Skip to content

Commit ab4bb82

Browse files
Automatically update Java SDK
1 parent 1058a4a commit ab4bb82

30 files changed

+4908
-193
lines changed

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.0.36</version>
11+
<version>1.0.38</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
@@ -30,7 +30,7 @@ private ClientOptions(Environment environment, Map<String, String> headers,
3030
this.environment = environment;
3131
this.headers = new HashMap<>();
3232
this.headers.putAll(headers);
33-
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.2326");}});
33+
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.2504");}});
3434
this.headerSuppliers = headerSuppliers;
3535
this.httpClient = httpClient;
3636
this.timeout = timeout;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package so.trophy.resources.admin.streaks;
2+
3+
/**
4+
* This file was auto-generated by Fern from our API Definition.
5+
*/
6+
7+
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import so.trophy.core.ClientOptions;
10+
import so.trophy.core.MediaTypes;
11+
import so.trophy.core.ObjectMappers;
12+
import so.trophy.core.RequestOptions;
13+
import so.trophy.core.TrophyApiApiException;
14+
import so.trophy.core.TrophyApiException;
15+
import so.trophy.core.TrophyApiHttpResponse;
16+
import so.trophy.errors.BadRequestError;
17+
import so.trophy.errors.UnauthorizedError;
18+
import so.trophy.errors.UnprocessableEntityError;
19+
import java.io.IOException;
20+
import java.lang.Object;
21+
import java.lang.Override;
22+
import java.lang.String;
23+
import java.util.concurrent.CompletableFuture;
24+
import okhttp3.Call;
25+
import okhttp3.Callback;
26+
import okhttp3.Headers;
27+
import okhttp3.HttpUrl;
28+
import okhttp3.OkHttpClient;
29+
import okhttp3.Request;
30+
import okhttp3.RequestBody;
31+
import okhttp3.Response;
32+
import okhttp3.ResponseBody;
33+
import org.jetbrains.annotations.NotNull;
34+
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
35+
import so.trophy.types.ErrorBody;
36+
import so.trophy.types.RestoreStreaksResponse;
37+
38+
public class AsyncRawStreaksClient {
39+
protected final ClientOptions clientOptions;
40+
41+
public AsyncRawStreaksClient(ClientOptions clientOptions) {
42+
this.clientOptions = clientOptions;
43+
}
44+
45+
/**
46+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
47+
*/
48+
public CompletableFuture<TrophyApiHttpResponse<RestoreStreaksResponse>> restore(
49+
RestoreStreaksRequest request) {
50+
return restore(request,null);
51+
}
52+
53+
/**
54+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
55+
*/
56+
public CompletableFuture<TrophyApiHttpResponse<RestoreStreaksResponse>> restore(
57+
RestoreStreaksRequest request, RequestOptions requestOptions) {
58+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
59+
60+
.addPathSegments("streaks/restore")
61+
.build();
62+
RequestBody body;
63+
try {
64+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
65+
}
66+
catch(JsonProcessingException e) {
67+
throw new TrophyApiException("Failed to serialize request", e);
68+
}
69+
Request okhttpRequest = new Request.Builder()
70+
.url(httpUrl)
71+
.method("POST", body)
72+
.headers(Headers.of(clientOptions.headers(requestOptions)))
73+
.addHeader("Content-Type", "application/json")
74+
.addHeader("Accept", "application/json")
75+
.build();
76+
OkHttpClient client = clientOptions.httpClient();
77+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
78+
client = clientOptions.httpClientWithTimeout(requestOptions);
79+
}
80+
CompletableFuture<TrophyApiHttpResponse<RestoreStreaksResponse>> future = new CompletableFuture<>();
81+
client.newCall(okhttpRequest).enqueue(new Callback() {
82+
@Override
83+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
84+
try (ResponseBody responseBody = response.body()) {
85+
if (response.isSuccessful()) {
86+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RestoreStreaksResponse.class), response));
87+
return;
88+
}
89+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
90+
try {
91+
switch (response.code()) {
92+
case 400:future.completeExceptionally(new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
93+
return;
94+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
95+
return;
96+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
97+
return;
98+
}
99+
}
100+
catch (JsonProcessingException ignored) {
101+
// unable to map error response, throwing generic error
102+
}
103+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
104+
return;
105+
}
106+
catch (IOException e) {
107+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
108+
}
109+
}
110+
111+
@Override
112+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
113+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
114+
}
115+
});
116+
return future;
117+
}
118+
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,49 @@
66

77

88
import so.trophy.core.ClientOptions;
9+
import so.trophy.core.RequestOptions;
910
import so.trophy.core.Suppliers;
11+
import java.util.concurrent.CompletableFuture;
1012
import java.util.function.Supplier;
1113
import so.trophy.resources.admin.streaks.freezes.AsyncFreezesClient;
14+
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
15+
import so.trophy.types.RestoreStreaksResponse;
1216

1317
public class AsyncStreaksClient {
1418
protected final ClientOptions clientOptions;
1519

20+
private final AsyncRawStreaksClient rawClient;
21+
1622
protected final Supplier<AsyncFreezesClient> freezesClient;
1723

1824
public AsyncStreaksClient(ClientOptions clientOptions) {
1925
this.clientOptions = clientOptions;
26+
this.rawClient = new AsyncRawStreaksClient(clientOptions);
2027
this.freezesClient = Suppliers.memoize(() -> new AsyncFreezesClient(clientOptions));
2128
}
2229

30+
/**
31+
* Get responses with HTTP metadata like headers
32+
*/
33+
public AsyncRawStreaksClient withRawResponse() {
34+
return this.rawClient;
35+
}
36+
37+
/**
38+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
39+
*/
40+
public CompletableFuture<RestoreStreaksResponse> restore(RestoreStreaksRequest request) {
41+
return this.rawClient.restore(request).thenApply(response -> response.body());
42+
}
43+
44+
/**
45+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
46+
*/
47+
public CompletableFuture<RestoreStreaksResponse> restore(RestoreStreaksRequest request,
48+
RequestOptions requestOptions) {
49+
return this.rawClient.restore(request, requestOptions).thenApply(response -> response.body());
50+
}
51+
2352
public AsyncFreezesClient freezes() {
2453
return this.freezesClient.get();
2554
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package so.trophy.resources.admin.streaks;
2+
3+
/**
4+
* This file was auto-generated by Fern from our API Definition.
5+
*/
6+
7+
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import so.trophy.core.ClientOptions;
10+
import so.trophy.core.MediaTypes;
11+
import so.trophy.core.ObjectMappers;
12+
import so.trophy.core.RequestOptions;
13+
import so.trophy.core.TrophyApiApiException;
14+
import so.trophy.core.TrophyApiException;
15+
import so.trophy.core.TrophyApiHttpResponse;
16+
import so.trophy.errors.BadRequestError;
17+
import so.trophy.errors.UnauthorizedError;
18+
import so.trophy.errors.UnprocessableEntityError;
19+
import java.io.IOException;
20+
import java.lang.Object;
21+
import java.lang.String;
22+
import okhttp3.Headers;
23+
import okhttp3.HttpUrl;
24+
import okhttp3.OkHttpClient;
25+
import okhttp3.Request;
26+
import okhttp3.RequestBody;
27+
import okhttp3.Response;
28+
import okhttp3.ResponseBody;
29+
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
30+
import so.trophy.types.ErrorBody;
31+
import so.trophy.types.RestoreStreaksResponse;
32+
33+
public class RawStreaksClient {
34+
protected final ClientOptions clientOptions;
35+
36+
public RawStreaksClient(ClientOptions clientOptions) {
37+
this.clientOptions = clientOptions;
38+
}
39+
40+
/**
41+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
42+
*/
43+
public TrophyApiHttpResponse<RestoreStreaksResponse> restore(RestoreStreaksRequest request) {
44+
return restore(request,null);
45+
}
46+
47+
/**
48+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
49+
*/
50+
public TrophyApiHttpResponse<RestoreStreaksResponse> restore(RestoreStreaksRequest request,
51+
RequestOptions requestOptions) {
52+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
53+
54+
.addPathSegments("streaks/restore")
55+
.build();
56+
RequestBody body;
57+
try {
58+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
59+
}
60+
catch(JsonProcessingException e) {
61+
throw new TrophyApiException("Failed to serialize request", e);
62+
}
63+
Request okhttpRequest = new Request.Builder()
64+
.url(httpUrl)
65+
.method("POST", body)
66+
.headers(Headers.of(clientOptions.headers(requestOptions)))
67+
.addHeader("Content-Type", "application/json")
68+
.addHeader("Accept", "application/json")
69+
.build();
70+
OkHttpClient client = clientOptions.httpClient();
71+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
72+
client = clientOptions.httpClientWithTimeout(requestOptions);
73+
}
74+
try (Response response = client.newCall(okhttpRequest).execute()) {
75+
ResponseBody responseBody = response.body();
76+
if (response.isSuccessful()) {
77+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RestoreStreaksResponse.class), response);
78+
}
79+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
80+
try {
81+
switch (response.code()) {
82+
case 400:throw new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
83+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
84+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
85+
}
86+
}
87+
catch (JsonProcessingException ignored) {
88+
// unable to map error response, throwing generic error
89+
}
90+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
91+
}
92+
catch (IOException e) {
93+
throw new TrophyApiException("Network error executing HTTP request", e);
94+
}
95+
}
96+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,48 @@
66

77

88
import so.trophy.core.ClientOptions;
9+
import so.trophy.core.RequestOptions;
910
import so.trophy.core.Suppliers;
1011
import java.util.function.Supplier;
1112
import so.trophy.resources.admin.streaks.freezes.FreezesClient;
13+
import so.trophy.resources.admin.streaks.requests.RestoreStreaksRequest;
14+
import so.trophy.types.RestoreStreaksResponse;
1215

1316
public class StreaksClient {
1417
protected final ClientOptions clientOptions;
1518

19+
private final RawStreaksClient rawClient;
20+
1621
protected final Supplier<FreezesClient> freezesClient;
1722

1823
public StreaksClient(ClientOptions clientOptions) {
1924
this.clientOptions = clientOptions;
25+
this.rawClient = new RawStreaksClient(clientOptions);
2026
this.freezesClient = Suppliers.memoize(() -> new FreezesClient(clientOptions));
2127
}
2228

29+
/**
30+
* Get responses with HTTP metadata like headers
31+
*/
32+
public RawStreaksClient withRawResponse() {
33+
return this.rawClient;
34+
}
35+
36+
/**
37+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
38+
*/
39+
public RestoreStreaksResponse restore(RestoreStreaksRequest request) {
40+
return this.rawClient.restore(request).body();
41+
}
42+
43+
/**
44+
* Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
45+
*/
46+
public RestoreStreaksResponse restore(RestoreStreaksRequest request,
47+
RequestOptions requestOptions) {
48+
return this.rawClient.restore(request, requestOptions).body();
49+
}
50+
2351
public FreezesClient freezes() {
2452
return this.freezesClient.get();
2553
}

0 commit comments

Comments
 (0)