Skip to content

Commit 8fa647e

Browse files
Automatically update Java SDK
1 parent 0a44bab commit 8fa647e

19 files changed

+809
-253
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.30</version>
11+
<version>1.0.31</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.1975");}});
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.2028");}});
3434
this.headerSuppliers = headerSuppliers;
3535
this.httpClient = httpClient;
3636
this.timeout = timeout;

src/main/java/so/trophy/resources/achievements/AchievementsClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import so.trophy.core.RequestOptions;
1010
import java.lang.String;
1111
import java.util.List;
12+
import so.trophy.resources.achievements.requests.AchievementsAllRequest;
1213
import so.trophy.resources.achievements.requests.AchievementsCompleteRequest;
1314
import so.trophy.types.AchievementCompletionResponse;
1415
import so.trophy.types.AchievementWithStatsResponse;
@@ -40,8 +41,16 @@ public List<AchievementWithStatsResponse> all() {
4041
/**
4142
* Get all achievements and their completion stats.
4243
*/
43-
public List<AchievementWithStatsResponse> all(RequestOptions requestOptions) {
44-
return this.rawClient.all(requestOptions).body();
44+
public List<AchievementWithStatsResponse> all(AchievementsAllRequest request) {
45+
return this.rawClient.all(request).body();
46+
}
47+
48+
/**
49+
* Get all achievements and their completion stats.
50+
*/
51+
public List<AchievementWithStatsResponse> all(AchievementsAllRequest request,
52+
RequestOptions requestOptions) {
53+
return this.rawClient.all(request, requestOptions).body();
4554
}
4655

4756
/**

src/main/java/so/trophy/resources/achievements/AsyncAchievementsClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.lang.String;
1111
import java.util.List;
1212
import java.util.concurrent.CompletableFuture;
13+
import so.trophy.resources.achievements.requests.AchievementsAllRequest;
1314
import so.trophy.resources.achievements.requests.AchievementsCompleteRequest;
1415
import so.trophy.types.AchievementCompletionResponse;
1516
import so.trophy.types.AchievementWithStatsResponse;
@@ -41,8 +42,16 @@ public CompletableFuture<List<AchievementWithStatsResponse>> all() {
4142
/**
4243
* Get all achievements and their completion stats.
4344
*/
44-
public CompletableFuture<List<AchievementWithStatsResponse>> all(RequestOptions requestOptions) {
45-
return this.rawClient.all(requestOptions).thenApply(response -> response.body());
45+
public CompletableFuture<List<AchievementWithStatsResponse>> all(AchievementsAllRequest request) {
46+
return this.rawClient.all(request).thenApply(response -> response.body());
47+
}
48+
49+
/**
50+
* Get all achievements and their completion stats.
51+
*/
52+
public CompletableFuture<List<AchievementWithStatsResponse>> all(AchievementsAllRequest request,
53+
RequestOptions requestOptions) {
54+
return this.rawClient.all(request, requestOptions).thenApply(response -> response.body());
4655
}
4756

4857
/**

src/main/java/so/trophy/resources/achievements/AsyncRawAchievementsClient.java

Lines changed: 121 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import so.trophy.core.ClientOptions;
1111
import so.trophy.core.MediaTypes;
1212
import so.trophy.core.ObjectMappers;
13+
import so.trophy.core.QueryStringMapper;
1314
import so.trophy.core.RequestOptions;
1415
import so.trophy.core.TrophyApiApiException;
1516
import so.trophy.core.TrophyApiException;
@@ -33,6 +34,7 @@
3334
import okhttp3.Response;
3435
import okhttp3.ResponseBody;
3536
import org.jetbrains.annotations.NotNull;
37+
import so.trophy.resources.achievements.requests.AchievementsAllRequest;
3638
import so.trophy.resources.achievements.requests.AchievementsCompleteRequest;
3739
import so.trophy.types.AchievementCompletionResponse;
3840
import so.trophy.types.AchievementWithStatsResponse;
@@ -49,138 +51,147 @@ public AsyncRawAchievementsClient(ClientOptions clientOptions) {
4951
* Get all achievements and their completion stats.
5052
*/
5153
public CompletableFuture<TrophyApiHttpResponse<List<AchievementWithStatsResponse>>> all() {
52-
return all(null);
54+
return all(AchievementsAllRequest.builder().build());
5355
}
5456

5557
/**
5658
* Get all achievements and their completion stats.
5759
*/
5860
public CompletableFuture<TrophyApiHttpResponse<List<AchievementWithStatsResponse>>> all(
59-
RequestOptions requestOptions) {
60-
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
61+
AchievementsAllRequest request) {
62+
return all(request,null);
63+
}
6164

62-
.addPathSegments("achievements")
63-
.build();
64-
Request okhttpRequest = new Request.Builder()
65-
.url(httpUrl)
66-
.method("GET", null)
67-
.headers(Headers.of(clientOptions.headers(requestOptions)))
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-
CompletableFuture<TrophyApiHttpResponse<List<AchievementWithStatsResponse>>> future = new CompletableFuture<>();
75-
client.newCall(okhttpRequest).enqueue(new Callback() {
76-
@Override
77-
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
78-
try (ResponseBody responseBody = response.body()) {
79-
if (response.isSuccessful()) {
80-
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<AchievementWithStatsResponse>>() {}), response));
81-
return;
82-
}
83-
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
84-
try {
85-
switch (response.code()) {
86-
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
87-
return;
88-
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
65+
/**
66+
* Get all achievements and their completion stats.
67+
*/
68+
public CompletableFuture<TrophyApiHttpResponse<List<AchievementWithStatsResponse>>> all(
69+
AchievementsAllRequest request, RequestOptions requestOptions) {
70+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
71+
72+
.addPathSegments("achievements");if (request.getUserAttributes().isPresent()) {
73+
QueryStringMapper.addQueryParameter(httpUrl, "userAttributes", request.getUserAttributes().get(), false);
74+
}
75+
Request.Builder _requestBuilder = new Request.Builder()
76+
.url(httpUrl.build())
77+
.method("GET", null)
78+
.headers(Headers.of(clientOptions.headers(requestOptions)))
79+
.addHeader("Accept", "application/json");
80+
Request okhttpRequest = _requestBuilder.build();
81+
OkHttpClient client = clientOptions.httpClient();
82+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
83+
client = clientOptions.httpClientWithTimeout(requestOptions);
84+
}
85+
CompletableFuture<TrophyApiHttpResponse<List<AchievementWithStatsResponse>>> future = new CompletableFuture<>();
86+
client.newCall(okhttpRequest).enqueue(new Callback() {
87+
@Override
88+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
89+
try (ResponseBody responseBody = response.body()) {
90+
if (response.isSuccessful()) {
91+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<AchievementWithStatsResponse>>() {}), response));
8992
return;
9093
}
94+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
95+
try {
96+
switch (response.code()) {
97+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
98+
return;
99+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
100+
return;
101+
}
102+
}
103+
catch (JsonProcessingException ignored) {
104+
// unable to map error response, throwing generic error
105+
}
106+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
107+
return;
91108
}
92-
catch (JsonProcessingException ignored) {
93-
// unable to map error response, throwing generic error
109+
catch (IOException e) {
110+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
94111
}
95-
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
96-
return;
97112
}
98-
catch (IOException e) {
113+
114+
@Override
115+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
99116
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
100117
}
101-
}
102-
103-
@Override
104-
public void onFailure(@NotNull Call call, @NotNull IOException e) {
105-
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
106-
}
107-
});
108-
return future;
109-
}
118+
});
119+
return future;
120+
}
110121

111-
/**
112-
* Mark an achievement as completed for a user.
113-
*/
114-
public CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> complete(
115-
String key, AchievementsCompleteRequest request) {
116-
return complete(key,request,null);
117-
}
122+
/**
123+
* Mark an achievement as completed for a user.
124+
*/
125+
public CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> complete(
126+
String key, AchievementsCompleteRequest request) {
127+
return complete(key,request,null);
128+
}
118129

119-
/**
120-
* Mark an achievement as completed for a user.
121-
*/
122-
public CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> complete(
123-
String key, AchievementsCompleteRequest request, RequestOptions requestOptions) {
124-
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
130+
/**
131+
* Mark an achievement as completed for a user.
132+
*/
133+
public CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> complete(
134+
String key, AchievementsCompleteRequest request, RequestOptions requestOptions) {
135+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
125136

126-
.addPathSegments("achievements")
127-
.addPathSegment(key)
128-
.addPathSegments("complete")
129-
.build();
130-
RequestBody body;
131-
try {
132-
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
133-
}
134-
catch(JsonProcessingException e) {
135-
throw new TrophyApiException("Failed to serialize request", e);
136-
}
137-
Request okhttpRequest = new Request.Builder()
138-
.url(httpUrl)
139-
.method("POST", body)
140-
.headers(Headers.of(clientOptions.headers(requestOptions)))
141-
.addHeader("Content-Type", "application/json")
142-
.addHeader("Accept", "application/json")
143-
.build();
144-
OkHttpClient client = clientOptions.httpClient();
145-
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
146-
client = clientOptions.httpClientWithTimeout(requestOptions);
147-
}
148-
CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> future = new CompletableFuture<>();
149-
client.newCall(okhttpRequest).enqueue(new Callback() {
150-
@Override
151-
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
152-
try (ResponseBody responseBody = response.body()) {
153-
if (response.isSuccessful()) {
154-
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AchievementCompletionResponse.class), response));
155-
return;
156-
}
157-
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
158-
try {
159-
switch (response.code()) {
160-
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
161-
return;
162-
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
163-
return;
164-
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
137+
.addPathSegments("achievements")
138+
.addPathSegment(key)
139+
.addPathSegments("complete")
140+
.build();
141+
RequestBody body;
142+
try {
143+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
144+
}
145+
catch(JsonProcessingException e) {
146+
throw new TrophyApiException("Failed to serialize request", e);
147+
}
148+
Request okhttpRequest = new Request.Builder()
149+
.url(httpUrl)
150+
.method("POST", body)
151+
.headers(Headers.of(clientOptions.headers(requestOptions)))
152+
.addHeader("Content-Type", "application/json")
153+
.addHeader("Accept", "application/json")
154+
.build();
155+
OkHttpClient client = clientOptions.httpClient();
156+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
157+
client = clientOptions.httpClientWithTimeout(requestOptions);
158+
}
159+
CompletableFuture<TrophyApiHttpResponse<AchievementCompletionResponse>> future = new CompletableFuture<>();
160+
client.newCall(okhttpRequest).enqueue(new Callback() {
161+
@Override
162+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
163+
try (ResponseBody responseBody = response.body()) {
164+
if (response.isSuccessful()) {
165+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AchievementCompletionResponse.class), response));
165166
return;
166167
}
168+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
169+
try {
170+
switch (response.code()) {
171+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
172+
return;
173+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
174+
return;
175+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
176+
return;
177+
}
178+
}
179+
catch (JsonProcessingException ignored) {
180+
// unable to map error response, throwing generic error
181+
}
182+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
183+
return;
167184
}
168-
catch (JsonProcessingException ignored) {
169-
// unable to map error response, throwing generic error
185+
catch (IOException e) {
186+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
170187
}
171-
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
172-
return;
173188
}
174-
catch (IOException e) {
189+
190+
@Override
191+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
175192
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
176193
}
177-
}
178-
179-
@Override
180-
public void onFailure(@NotNull Call call, @NotNull IOException e) {
181-
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
182-
}
183-
});
184-
return future;
194+
});
195+
return future;
196+
}
185197
}
186-
}

0 commit comments

Comments
 (0)