Skip to content

Commit 79a76d2

Browse files
Automatically update Java SDK
1 parent 7249d6f commit 79a76d2

File tree

11 files changed

+844
-2
lines changed

11 files changed

+844
-2
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.40</version>
11+
<version>1.0.42</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.2597");}});
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.3057");}});
3434
this.headerSuppliers = headerSuppliers;
3535
this.httpClient = httpClient;
3636
this.timeout = timeout;

src/main/java/so/trophy/resources/users/AsyncRawUsersClient.java

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import okhttp3.Response;
3636
import okhttp3.ResponseBody;
3737
import org.jetbrains.annotations.NotNull;
38+
import so.trophy.resources.users.requests.UpdateUserPreferencesRequest;
3839
import so.trophy.resources.users.requests.UsersAchievementsRequest;
3940
import so.trophy.resources.users.requests.UsersLeaderboardRequest;
4041
import so.trophy.resources.users.requests.UsersMetricEventSummaryRequest;
@@ -53,6 +54,7 @@
5354
import so.trophy.types.User;
5455
import so.trophy.types.UserAchievementWithStatsResponse;
5556
import so.trophy.types.UserLeaderboardResponseWithHistory;
57+
import so.trophy.types.UserPreferencesResponse;
5658
import so.trophy.types.WrappedResponse;
5759

5860
public class AsyncRawUsersClient {
@@ -365,6 +367,158 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
365367
return future;
366368
}
367369

370+
/**
371+
* Get a user's notification preferences.
372+
*/
373+
public CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> getPreferences(
374+
String id) {
375+
return getPreferences(id,null);
376+
}
377+
378+
/**
379+
* Get a user's notification preferences.
380+
*/
381+
public CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> getPreferences(String id,
382+
RequestOptions requestOptions) {
383+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
384+
385+
.addPathSegments("users")
386+
.addPathSegment(id)
387+
.addPathSegments("preferences")
388+
.build();
389+
Request okhttpRequest = new Request.Builder()
390+
.url(httpUrl)
391+
.method("GET", null)
392+
.headers(Headers.of(clientOptions.headers(requestOptions)))
393+
.addHeader("Accept", "application/json")
394+
.build();
395+
OkHttpClient client = clientOptions.httpClient();
396+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
397+
client = clientOptions.httpClientWithTimeout(requestOptions);
398+
}
399+
CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> future = new CompletableFuture<>();
400+
client.newCall(okhttpRequest).enqueue(new Callback() {
401+
@Override
402+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
403+
try (ResponseBody responseBody = response.body()) {
404+
if (response.isSuccessful()) {
405+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UserPreferencesResponse.class), response));
406+
return;
407+
}
408+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
409+
try {
410+
switch (response.code()) {
411+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
412+
return;
413+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
414+
return;
415+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
416+
return;
417+
}
418+
}
419+
catch (JsonProcessingException ignored) {
420+
// unable to map error response, throwing generic error
421+
}
422+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
423+
return;
424+
}
425+
catch (IOException e) {
426+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
427+
}
428+
}
429+
430+
@Override
431+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
432+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
433+
}
434+
});
435+
return future;
436+
}
437+
438+
/**
439+
* Update a user's notification preferences.
440+
*/
441+
public CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> updatePreferences(
442+
String id) {
443+
return updatePreferences(id,UpdateUserPreferencesRequest.builder().build());
444+
}
445+
446+
/**
447+
* Update a user's notification preferences.
448+
*/
449+
public CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> updatePreferences(
450+
String id, UpdateUserPreferencesRequest request) {
451+
return updatePreferences(id,request,null);
452+
}
453+
454+
/**
455+
* Update a user's notification preferences.
456+
*/
457+
public CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> updatePreferences(
458+
String id, UpdateUserPreferencesRequest request, RequestOptions requestOptions) {
459+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
460+
461+
.addPathSegments("users")
462+
.addPathSegment(id)
463+
.addPathSegments("preferences")
464+
.build();
465+
RequestBody body;
466+
try {
467+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
468+
}
469+
catch(JsonProcessingException e) {
470+
throw new TrophyApiException("Failed to serialize request", e);
471+
}
472+
Request okhttpRequest = new Request.Builder()
473+
.url(httpUrl)
474+
.method("PATCH", body)
475+
.headers(Headers.of(clientOptions.headers(requestOptions)))
476+
.addHeader("Content-Type", "application/json")
477+
.addHeader("Accept", "application/json")
478+
.build();
479+
OkHttpClient client = clientOptions.httpClient();
480+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
481+
client = clientOptions.httpClientWithTimeout(requestOptions);
482+
}
483+
CompletableFuture<TrophyApiHttpResponse<UserPreferencesResponse>> future = new CompletableFuture<>();
484+
client.newCall(okhttpRequest).enqueue(new Callback() {
485+
@Override
486+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
487+
try (ResponseBody responseBody = response.body()) {
488+
if (response.isSuccessful()) {
489+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UserPreferencesResponse.class), response));
490+
return;
491+
}
492+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
493+
try {
494+
switch (response.code()) {
495+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
496+
return;
497+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
498+
return;
499+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
500+
return;
501+
}
502+
}
503+
catch (JsonProcessingException ignored) {
504+
// unable to map error response, throwing generic error
505+
}
506+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
507+
return;
508+
}
509+
catch (IOException e) {
510+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
511+
}
512+
}
513+
514+
@Override
515+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
516+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
517+
}
518+
});
519+
return future;
520+
}
521+
368522
/**
369523
* Get a single user's progress against all active metrics.
370524
*/

src/main/java/so/trophy/resources/users/AsyncUsersClient.java

Lines changed: 40 additions & 0 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.users.requests.UpdateUserPreferencesRequest;
1314
import so.trophy.resources.users.requests.UsersAchievementsRequest;
1415
import so.trophy.resources.users.requests.UsersLeaderboardRequest;
1516
import so.trophy.resources.users.requests.UsersMetricEventSummaryRequest;
@@ -27,6 +28,7 @@
2728
import so.trophy.types.User;
2829
import so.trophy.types.UserAchievementWithStatsResponse;
2930
import so.trophy.types.UserLeaderboardResponseWithHistory;
31+
import so.trophy.types.UserPreferencesResponse;
3032
import so.trophy.types.WrappedResponse;
3133

3234
public class AsyncUsersClient {
@@ -118,6 +120,44 @@ public CompletableFuture<User> update(String id, UpdatedUser request,
118120
return this.rawClient.update(id, request, requestOptions).thenApply(response -> response.body());
119121
}
120122

123+
/**
124+
* Get a user's notification preferences.
125+
*/
126+
public CompletableFuture<UserPreferencesResponse> getPreferences(String id) {
127+
return this.rawClient.getPreferences(id).thenApply(response -> response.body());
128+
}
129+
130+
/**
131+
* Get a user's notification preferences.
132+
*/
133+
public CompletableFuture<UserPreferencesResponse> getPreferences(String id,
134+
RequestOptions requestOptions) {
135+
return this.rawClient.getPreferences(id, requestOptions).thenApply(response -> response.body());
136+
}
137+
138+
/**
139+
* Update a user's notification preferences.
140+
*/
141+
public CompletableFuture<UserPreferencesResponse> updatePreferences(String id) {
142+
return this.rawClient.updatePreferences(id).thenApply(response -> response.body());
143+
}
144+
145+
/**
146+
* Update a user's notification preferences.
147+
*/
148+
public CompletableFuture<UserPreferencesResponse> updatePreferences(String id,
149+
UpdateUserPreferencesRequest request) {
150+
return this.rawClient.updatePreferences(id, request).thenApply(response -> response.body());
151+
}
152+
153+
/**
154+
* Update a user's notification preferences.
155+
*/
156+
public CompletableFuture<UserPreferencesResponse> updatePreferences(String id,
157+
UpdateUserPreferencesRequest request, RequestOptions requestOptions) {
158+
return this.rawClient.updatePreferences(id, request, requestOptions).thenApply(response -> response.body());
159+
}
160+
121161
/**
122162
* Get a single user's progress against all active metrics.
123163
*/

src/main/java/so/trophy/resources/users/RawUsersClient.java

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import okhttp3.RequestBody;
3131
import okhttp3.Response;
3232
import okhttp3.ResponseBody;
33+
import so.trophy.resources.users.requests.UpdateUserPreferencesRequest;
3334
import so.trophy.resources.users.requests.UsersAchievementsRequest;
3435
import so.trophy.resources.users.requests.UsersLeaderboardRequest;
3536
import so.trophy.resources.users.requests.UsersMetricEventSummaryRequest;
@@ -48,6 +49,7 @@
4849
import so.trophy.types.User;
4950
import so.trophy.types.UserAchievementWithStatsResponse;
5051
import so.trophy.types.UserLeaderboardResponseWithHistory;
52+
import so.trophy.types.UserPreferencesResponse;
5153
import so.trophy.types.WrappedResponse;
5254

5355
public class RawUsersClient {
@@ -293,6 +295,124 @@ public TrophyApiHttpResponse<User> update(String id, UpdatedUser request,
293295
}
294296
}
295297

298+
/**
299+
* Get a user's notification preferences.
300+
*/
301+
public TrophyApiHttpResponse<UserPreferencesResponse> getPreferences(String id) {
302+
return getPreferences(id,null);
303+
}
304+
305+
/**
306+
* Get a user's notification preferences.
307+
*/
308+
public TrophyApiHttpResponse<UserPreferencesResponse> getPreferences(String id,
309+
RequestOptions requestOptions) {
310+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
311+
312+
.addPathSegments("users")
313+
.addPathSegment(id)
314+
.addPathSegments("preferences")
315+
.build();
316+
Request okhttpRequest = new Request.Builder()
317+
.url(httpUrl)
318+
.method("GET", null)
319+
.headers(Headers.of(clientOptions.headers(requestOptions)))
320+
.addHeader("Accept", "application/json")
321+
.build();
322+
OkHttpClient client = clientOptions.httpClient();
323+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
324+
client = clientOptions.httpClientWithTimeout(requestOptions);
325+
}
326+
try (Response response = client.newCall(okhttpRequest).execute()) {
327+
ResponseBody responseBody = response.body();
328+
if (response.isSuccessful()) {
329+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UserPreferencesResponse.class), response);
330+
}
331+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
332+
try {
333+
switch (response.code()) {
334+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
335+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
336+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
337+
}
338+
}
339+
catch (JsonProcessingException ignored) {
340+
// unable to map error response, throwing generic error
341+
}
342+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
343+
}
344+
catch (IOException e) {
345+
throw new TrophyApiException("Network error executing HTTP request", e);
346+
}
347+
}
348+
349+
/**
350+
* Update a user's notification preferences.
351+
*/
352+
public TrophyApiHttpResponse<UserPreferencesResponse> updatePreferences(String id) {
353+
return updatePreferences(id,UpdateUserPreferencesRequest.builder().build());
354+
}
355+
356+
/**
357+
* Update a user's notification preferences.
358+
*/
359+
public TrophyApiHttpResponse<UserPreferencesResponse> updatePreferences(String id,
360+
UpdateUserPreferencesRequest request) {
361+
return updatePreferences(id,request,null);
362+
}
363+
364+
/**
365+
* Update a user's notification preferences.
366+
*/
367+
public TrophyApiHttpResponse<UserPreferencesResponse> updatePreferences(String id,
368+
UpdateUserPreferencesRequest request, RequestOptions requestOptions) {
369+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
370+
371+
.addPathSegments("users")
372+
.addPathSegment(id)
373+
.addPathSegments("preferences")
374+
.build();
375+
RequestBody body;
376+
try {
377+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
378+
}
379+
catch(JsonProcessingException e) {
380+
throw new TrophyApiException("Failed to serialize request", e);
381+
}
382+
Request okhttpRequest = new Request.Builder()
383+
.url(httpUrl)
384+
.method("PATCH", body)
385+
.headers(Headers.of(clientOptions.headers(requestOptions)))
386+
.addHeader("Content-Type", "application/json")
387+
.addHeader("Accept", "application/json")
388+
.build();
389+
OkHttpClient client = clientOptions.httpClient();
390+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
391+
client = clientOptions.httpClientWithTimeout(requestOptions);
392+
}
393+
try (Response response = client.newCall(okhttpRequest).execute()) {
394+
ResponseBody responseBody = response.body();
395+
if (response.isSuccessful()) {
396+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UserPreferencesResponse.class), response);
397+
}
398+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
399+
try {
400+
switch (response.code()) {
401+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
402+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
403+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
404+
}
405+
}
406+
catch (JsonProcessingException ignored) {
407+
// unable to map error response, throwing generic error
408+
}
409+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
410+
}
411+
catch (IOException e) {
412+
throw new TrophyApiException("Network error executing HTTP request", e);
413+
}
414+
}
415+
296416
/**
297417
* Get a single user's progress against all active metrics.
298418
*/

0 commit comments

Comments
 (0)