Skip to content

Commit d06673b

Browse files
Automatically update Java SDK
1 parent 801e37e commit d06673b

16 files changed

+3917
-11
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.23</version>
11+
<version>1.0.24</version>
1212
<packaging>jar</packaging>
1313
<name>Trophy</name>
1414
<description>Java client library for the Trophy API</description>

src/main/java/so/trophy/TrophyApiClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import so.trophy.core.Suppliers;
99
import java.util.function.Supplier;
1010
import so.trophy.resources.achievements.AchievementsClient;
11+
import so.trophy.resources.leaderboards.LeaderboardsClient;
1112
import so.trophy.resources.metrics.MetricsClient;
1213
import so.trophy.resources.points.PointsClient;
1314
import so.trophy.resources.streaks.StreaksClient;
@@ -26,13 +27,16 @@ public class TrophyApiClient {
2627

2728
protected final Supplier<PointsClient> pointsClient;
2829

30+
protected final Supplier<LeaderboardsClient> leaderboardsClient;
31+
2932
public TrophyApiClient(ClientOptions clientOptions) {
3033
this.clientOptions = clientOptions;
3134
this.achievementsClient = Suppliers.memoize(() -> new AchievementsClient(clientOptions));
3235
this.metricsClient = Suppliers.memoize(() -> new MetricsClient(clientOptions));
3336
this.usersClient = Suppliers.memoize(() -> new UsersClient(clientOptions));
3437
this.streaksClient = Suppliers.memoize(() -> new StreaksClient(clientOptions));
3538
this.pointsClient = Suppliers.memoize(() -> new PointsClient(clientOptions));
39+
this.leaderboardsClient = Suppliers.memoize(() -> new LeaderboardsClient(clientOptions));
3640
}
3741

3842
public AchievementsClient achievements() {
@@ -55,6 +59,10 @@ public PointsClient points() {
5559
return this.pointsClient.get();
5660
}
5761

62+
public LeaderboardsClient leaderboards() {
63+
return this.leaderboardsClient.get();
64+
}
65+
5866
public static TrophyApiClientBuilder builder() {
5967
return new TrophyApiClientBuilder();
6068
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private ClientOptions(Environment environment, Map<String, String> headers,
2828
this.environment = environment;
2929
this.headers = new HashMap<>();
3030
this.headers.putAll(headers);
31-
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.1571");}});
31+
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.1608");}});
3232
this.headerSuppliers = headerSuppliers;
3333
this.httpClient = httpClient;
3434
this.timeout = timeout;
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
package so.trophy.resources.leaderboards;
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 com.fasterxml.jackson.core.type.TypeReference;
10+
import so.trophy.core.ClientOptions;
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.errors.NotFoundError;
16+
import so.trophy.errors.UnauthorizedError;
17+
import so.trophy.errors.UnprocessableEntityError;
18+
import java.io.IOException;
19+
import java.lang.Object;
20+
import java.lang.String;
21+
import java.util.List;
22+
import okhttp3.Headers;
23+
import okhttp3.HttpUrl;
24+
import okhttp3.OkHttpClient;
25+
import okhttp3.Request;
26+
import okhttp3.Response;
27+
import okhttp3.ResponseBody;
28+
import so.trophy.resources.leaderboards.requests.LeaderboardsGetRequest;
29+
import so.trophy.resources.leaderboards.requests.UsersLeaderboardsRequest;
30+
import so.trophy.types.ErrorBody;
31+
import so.trophy.types.LeaderboardResponse;
32+
import so.trophy.types.LeaderboardResponseWithRankings;
33+
import so.trophy.types.UserLeaderboardResponse;
34+
35+
public class LeaderboardsClient {
36+
protected final ClientOptions clientOptions;
37+
38+
public LeaderboardsClient(ClientOptions clientOptions) {
39+
this.clientOptions = clientOptions;
40+
}
41+
42+
/**
43+
* Get all active leaderboards for your organization.
44+
*/
45+
public List<LeaderboardResponse> all() {
46+
return all(null);
47+
}
48+
49+
/**
50+
* Get all active leaderboards for your organization.
51+
*/
52+
public List<LeaderboardResponse> all(RequestOptions requestOptions) {
53+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
54+
55+
.addPathSegments("leaderboards")
56+
.build();
57+
Request okhttpRequest = new Request.Builder()
58+
.url(httpUrl)
59+
.method("GET", null)
60+
.headers(Headers.of(clientOptions.headers(requestOptions)))
61+
.addHeader("Content-Type", "application/json")
62+
.addHeader("Accept", "application/json")
63+
.build();
64+
OkHttpClient client = clientOptions.httpClient();
65+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
66+
client = clientOptions.httpClientWithTimeout(requestOptions);
67+
}
68+
try (Response response = client.newCall(okhttpRequest).execute()) {
69+
ResponseBody responseBody = response.body();
70+
if (response.isSuccessful()) {
71+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<LeaderboardResponse>>() {});
72+
}
73+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
74+
try {
75+
switch (response.code()) {
76+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
77+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
78+
}
79+
}
80+
catch (JsonProcessingException ignored) {
81+
// unable to map error response, throwing generic error
82+
}
83+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
84+
}
85+
catch (IOException e) {
86+
throw new TrophyApiException("Network error executing HTTP request", e);
87+
}
88+
}
89+
90+
/**
91+
* Get a specific leaderboard by its key.
92+
*/
93+
public LeaderboardResponseWithRankings get(String key) {
94+
return get(key,LeaderboardsGetRequest.builder().build());
95+
}
96+
97+
/**
98+
* Get a specific leaderboard by its key.
99+
*/
100+
public LeaderboardResponseWithRankings get(String key, LeaderboardsGetRequest request) {
101+
return get(key,request,null);
102+
}
103+
104+
/**
105+
* Get a specific leaderboard by its key.
106+
*/
107+
public LeaderboardResponseWithRankings get(String key, LeaderboardsGetRequest request,
108+
RequestOptions requestOptions) {
109+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
110+
111+
.addPathSegments("leaderboards")
112+
.addPathSegment(key);if (request.getOffset().isPresent()) {
113+
httpUrl.addQueryParameter("offset", request.getOffset().get().toString());
114+
}
115+
if (request.getLimit().isPresent()) {
116+
httpUrl.addQueryParameter("limit", request.getLimit().get().toString());
117+
}
118+
if (request.getRun().isPresent()) {
119+
httpUrl.addQueryParameter("run", request.getRun().get());
120+
}
121+
if (request.getUserId().isPresent()) {
122+
httpUrl.addQueryParameter("userId", request.getUserId().get());
123+
}
124+
Request.Builder _requestBuilder = new Request.Builder()
125+
.url(httpUrl.build())
126+
.method("GET", null)
127+
.headers(Headers.of(clientOptions.headers(requestOptions)))
128+
.addHeader("Content-Type", "application/json").addHeader("Accept", "application/json");
129+
Request okhttpRequest = _requestBuilder.build();
130+
OkHttpClient client = clientOptions.httpClient();
131+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
132+
client = clientOptions.httpClientWithTimeout(requestOptions);
133+
}
134+
try (Response response = client.newCall(okhttpRequest).execute()) {
135+
ResponseBody responseBody = response.body();
136+
if (response.isSuccessful()) {
137+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), LeaderboardResponseWithRankings.class);
138+
}
139+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
140+
try {
141+
switch (response.code()) {
142+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
143+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
144+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
145+
}
146+
}
147+
catch (JsonProcessingException ignored) {
148+
// unable to map error response, throwing generic error
149+
}
150+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
151+
}
152+
catch (IOException e) {
153+
throw new TrophyApiException("Network error executing HTTP request", e);
154+
}
155+
}
156+
157+
/**
158+
* Get a user's rank, value, and history for a specific leaderboard.
159+
*/
160+
public UserLeaderboardResponse usersLeaderboards(String userId, String key) {
161+
return usersLeaderboards(userId,key,UsersLeaderboardsRequest.builder().build());
162+
}
163+
164+
/**
165+
* Get a user's rank, value, and history for a specific leaderboard.
166+
*/
167+
public UserLeaderboardResponse usersLeaderboards(String userId, String key,
168+
UsersLeaderboardsRequest request) {
169+
return usersLeaderboards(userId,key,request,null);
170+
}
171+
172+
/**
173+
* Get a user's rank, value, and history for a specific leaderboard.
174+
*/
175+
public UserLeaderboardResponse usersLeaderboards(String userId, String key,
176+
UsersLeaderboardsRequest request, RequestOptions requestOptions) {
177+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
178+
179+
.addPathSegments("users")
180+
.addPathSegment(userId)
181+
.addPathSegments("leaderboards")
182+
.addPathSegment(key);if (request.getRun().isPresent()) {
183+
httpUrl.addQueryParameter("run", request.getRun().get());
184+
}
185+
Request.Builder _requestBuilder = new Request.Builder()
186+
.url(httpUrl.build())
187+
.method("GET", null)
188+
.headers(Headers.of(clientOptions.headers(requestOptions)))
189+
.addHeader("Content-Type", "application/json").addHeader("Accept", "application/json");
190+
Request okhttpRequest = _requestBuilder.build();
191+
OkHttpClient client = clientOptions.httpClient();
192+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
193+
client = clientOptions.httpClientWithTimeout(requestOptions);
194+
}
195+
try (Response response = client.newCall(okhttpRequest).execute()) {
196+
ResponseBody responseBody = response.body();
197+
if (response.isSuccessful()) {
198+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UserLeaderboardResponse.class);
199+
}
200+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
201+
try {
202+
switch (response.code()) {
203+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
204+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
205+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
206+
}
207+
}
208+
catch (JsonProcessingException ignored) {
209+
// unable to map error response, throwing generic error
210+
}
211+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
212+
}
213+
catch (IOException e) {
214+
throw new TrophyApiException("Network error executing HTTP request", e);
215+
}
216+
}
217+
}

0 commit comments

Comments
 (0)