Skip to content

Commit ec148ab

Browse files
Automatically update Java SDK
1 parent 746fa33 commit ec148ab

14 files changed

+1834
-13
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.1.2</version>
11+
<version>1.2.1</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.341");}});
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.555");}});
3434
this.headerSuppliers = headerSuppliers;
3535
this.httpClient = httpClient;
3636
this.timeout = timeout;

src/main/java/so/trophy/resources/points/AsyncPointsClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import so.trophy.resources.points.requests.PointsBoostsRequest;
1414
import so.trophy.resources.points.requests.PointsSummaryRequest;
1515
import so.trophy.types.PointsBoost;
16+
import so.trophy.types.PointsLevel;
17+
import so.trophy.types.PointsLevelSummaryResponseItem;
1618
import so.trophy.types.PointsRange;
1719
import so.trophy.types.PointsSystemResponse;
1820

@@ -90,4 +92,33 @@ public CompletableFuture<List<PointsBoost>> boosts(String key, PointsBoostsReque
9092
RequestOptions requestOptions) {
9193
return this.rawClient.boosts(key, request, requestOptions).thenApply(response -> response.body());
9294
}
95+
96+
/**
97+
* Get all levels for a points system.
98+
*/
99+
public CompletableFuture<List<PointsLevel>> levels(String key) {
100+
return this.rawClient.levels(key).thenApply(response -> response.body());
101+
}
102+
103+
/**
104+
* Get all levels for a points system.
105+
*/
106+
public CompletableFuture<List<PointsLevel>> levels(String key, RequestOptions requestOptions) {
107+
return this.rawClient.levels(key, requestOptions).thenApply(response -> response.body());
108+
}
109+
110+
/**
111+
* Get a breakdown of the number of users at each level in a points system.
112+
*/
113+
public CompletableFuture<List<PointsLevelSummaryResponseItem>> levelSummary(String key) {
114+
return this.rawClient.levelSummary(key).thenApply(response -> response.body());
115+
}
116+
117+
/**
118+
* Get a breakdown of the number of users at each level in a points system.
119+
*/
120+
public CompletableFuture<List<PointsLevelSummaryResponseItem>> levelSummary(String key,
121+
RequestOptions requestOptions) {
122+
return this.rawClient.levelSummary(key, requestOptions).thenApply(response -> response.body());
123+
}
93124
}

src/main/java/so/trophy/resources/points/AsyncRawPointsClient.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import so.trophy.resources.points.requests.PointsSummaryRequest;
3737
import so.trophy.types.ErrorBody;
3838
import so.trophy.types.PointsBoost;
39+
import so.trophy.types.PointsLevel;
40+
import so.trophy.types.PointsLevelSummaryResponseItem;
3941
import so.trophy.types.PointsRange;
4042
import so.trophy.types.PointsSystemResponse;
4143

@@ -259,4 +261,137 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
259261
});
260262
return future;
261263
}
264+
265+
/**
266+
* Get all levels for a points system.
267+
*/
268+
public CompletableFuture<TrophyApiHttpResponse<List<PointsLevel>>> levels(String key) {
269+
return levels(key,null);
270+
}
271+
272+
/**
273+
* Get all levels for a points system.
274+
*/
275+
public CompletableFuture<TrophyApiHttpResponse<List<PointsLevel>>> levels(String key,
276+
RequestOptions requestOptions) {
277+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
278+
279+
.addPathSegments("points")
280+
.addPathSegment(key)
281+
.addPathSegments("levels")
282+
.build();
283+
Request okhttpRequest = new Request.Builder()
284+
.url(httpUrl)
285+
.method("GET", null)
286+
.headers(Headers.of(clientOptions.headers(requestOptions)))
287+
.addHeader("Accept", "application/json")
288+
.build();
289+
OkHttpClient client = clientOptions.httpClient();
290+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
291+
client = clientOptions.httpClientWithTimeout(requestOptions);
292+
}
293+
CompletableFuture<TrophyApiHttpResponse<List<PointsLevel>>> future = new CompletableFuture<>();
294+
client.newCall(okhttpRequest).enqueue(new Callback() {
295+
@Override
296+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
297+
try (ResponseBody responseBody = response.body()) {
298+
if (response.isSuccessful()) {
299+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<PointsLevel>>() {}), response));
300+
return;
301+
}
302+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
303+
try {
304+
switch (response.code()) {
305+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
306+
return;
307+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
308+
return;
309+
}
310+
}
311+
catch (JsonProcessingException ignored) {
312+
// unable to map error response, throwing generic error
313+
}
314+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
315+
return;
316+
}
317+
catch (IOException e) {
318+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
319+
}
320+
}
321+
322+
@Override
323+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
324+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
325+
}
326+
});
327+
return future;
328+
}
329+
330+
/**
331+
* Get a breakdown of the number of users at each level in a points system.
332+
*/
333+
public CompletableFuture<TrophyApiHttpResponse<List<PointsLevelSummaryResponseItem>>> levelSummary(
334+
String key) {
335+
return levelSummary(key,null);
336+
}
337+
338+
/**
339+
* Get a breakdown of the number of users at each level in a points system.
340+
*/
341+
public CompletableFuture<TrophyApiHttpResponse<List<PointsLevelSummaryResponseItem>>> levelSummary(
342+
String key, RequestOptions requestOptions) {
343+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
344+
345+
.addPathSegments("points")
346+
.addPathSegment(key)
347+
.addPathSegments("level-summary")
348+
.build();
349+
Request okhttpRequest = new Request.Builder()
350+
.url(httpUrl)
351+
.method("GET", null)
352+
.headers(Headers.of(clientOptions.headers(requestOptions)))
353+
.addHeader("Accept", "application/json")
354+
.build();
355+
OkHttpClient client = clientOptions.httpClient();
356+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
357+
client = clientOptions.httpClientWithTimeout(requestOptions);
358+
}
359+
CompletableFuture<TrophyApiHttpResponse<List<PointsLevelSummaryResponseItem>>> future = new CompletableFuture<>();
360+
client.newCall(okhttpRequest).enqueue(new Callback() {
361+
@Override
362+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
363+
try (ResponseBody responseBody = response.body()) {
364+
if (response.isSuccessful()) {
365+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<PointsLevelSummaryResponseItem>>() {}), response));
366+
return;
367+
}
368+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
369+
try {
370+
switch (response.code()) {
371+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
372+
return;
373+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
374+
return;
375+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response));
376+
return;
377+
}
378+
}
379+
catch (JsonProcessingException ignored) {
380+
// unable to map error response, throwing generic error
381+
}
382+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
383+
return;
384+
}
385+
catch (IOException e) {
386+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
387+
}
388+
}
389+
390+
@Override
391+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
392+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
393+
}
394+
});
395+
return future;
396+
}
262397
}

src/main/java/so/trophy/resources/points/PointsClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import so.trophy.resources.points.requests.PointsBoostsRequest;
1313
import so.trophy.resources.points.requests.PointsSummaryRequest;
1414
import so.trophy.types.PointsBoost;
15+
import so.trophy.types.PointsLevel;
16+
import so.trophy.types.PointsLevelSummaryResponseItem;
1517
import so.trophy.types.PointsRange;
1618
import so.trophy.types.PointsSystemResponse;
1719

@@ -89,4 +91,33 @@ public List<PointsBoost> boosts(String key, PointsBoostsRequest request,
8991
RequestOptions requestOptions) {
9092
return this.rawClient.boosts(key, request, requestOptions).body();
9193
}
94+
95+
/**
96+
* Get all levels for a points system.
97+
*/
98+
public List<PointsLevel> levels(String key) {
99+
return this.rawClient.levels(key).body();
100+
}
101+
102+
/**
103+
* Get all levels for a points system.
104+
*/
105+
public List<PointsLevel> levels(String key, RequestOptions requestOptions) {
106+
return this.rawClient.levels(key, requestOptions).body();
107+
}
108+
109+
/**
110+
* Get a breakdown of the number of users at each level in a points system.
111+
*/
112+
public List<PointsLevelSummaryResponseItem> levelSummary(String key) {
113+
return this.rawClient.levelSummary(key).body();
114+
}
115+
116+
/**
117+
* Get a breakdown of the number of users at each level in a points system.
118+
*/
119+
public List<PointsLevelSummaryResponseItem> levelSummary(String key,
120+
RequestOptions requestOptions) {
121+
return this.rawClient.levelSummary(key, requestOptions).body();
122+
}
92123
}

src/main/java/so/trophy/resources/points/RawPointsClient.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import so.trophy.resources.points.requests.PointsSummaryRequest;
3232
import so.trophy.types.ErrorBody;
3333
import so.trophy.types.PointsBoost;
34+
import so.trophy.types.PointsLevel;
35+
import so.trophy.types.PointsLevelSummaryResponseItem;
3436
import so.trophy.types.PointsRange;
3537
import so.trophy.types.PointsSystemResponse;
3638

@@ -208,4 +210,105 @@ public TrophyApiHttpResponse<List<PointsBoost>> boosts(String key, PointsBoostsR
208210
throw new TrophyApiException("Network error executing HTTP request", e);
209211
}
210212
}
213+
214+
/**
215+
* Get all levels for a points system.
216+
*/
217+
public TrophyApiHttpResponse<List<PointsLevel>> levels(String key) {
218+
return levels(key,null);
219+
}
220+
221+
/**
222+
* Get all levels for a points system.
223+
*/
224+
public TrophyApiHttpResponse<List<PointsLevel>> levels(String key,
225+
RequestOptions requestOptions) {
226+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
227+
228+
.addPathSegments("points")
229+
.addPathSegment(key)
230+
.addPathSegments("levels")
231+
.build();
232+
Request okhttpRequest = new Request.Builder()
233+
.url(httpUrl)
234+
.method("GET", null)
235+
.headers(Headers.of(clientOptions.headers(requestOptions)))
236+
.addHeader("Accept", "application/json")
237+
.build();
238+
OkHttpClient client = clientOptions.httpClient();
239+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
240+
client = clientOptions.httpClientWithTimeout(requestOptions);
241+
}
242+
try (Response response = client.newCall(okhttpRequest).execute()) {
243+
ResponseBody responseBody = response.body();
244+
if (response.isSuccessful()) {
245+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<PointsLevel>>() {}), response);
246+
}
247+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
248+
try {
249+
switch (response.code()) {
250+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
251+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
252+
}
253+
}
254+
catch (JsonProcessingException ignored) {
255+
// unable to map error response, throwing generic error
256+
}
257+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
258+
}
259+
catch (IOException e) {
260+
throw new TrophyApiException("Network error executing HTTP request", e);
261+
}
262+
}
263+
264+
/**
265+
* Get a breakdown of the number of users at each level in a points system.
266+
*/
267+
public TrophyApiHttpResponse<List<PointsLevelSummaryResponseItem>> levelSummary(String key) {
268+
return levelSummary(key,null);
269+
}
270+
271+
/**
272+
* Get a breakdown of the number of users at each level in a points system.
273+
*/
274+
public TrophyApiHttpResponse<List<PointsLevelSummaryResponseItem>> levelSummary(String key,
275+
RequestOptions requestOptions) {
276+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getApiURL()).newBuilder()
277+
278+
.addPathSegments("points")
279+
.addPathSegment(key)
280+
.addPathSegments("level-summary")
281+
.build();
282+
Request okhttpRequest = new Request.Builder()
283+
.url(httpUrl)
284+
.method("GET", null)
285+
.headers(Headers.of(clientOptions.headers(requestOptions)))
286+
.addHeader("Accept", "application/json")
287+
.build();
288+
OkHttpClient client = clientOptions.httpClient();
289+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
290+
client = clientOptions.httpClientWithTimeout(requestOptions);
291+
}
292+
try (Response response = client.newCall(okhttpRequest).execute()) {
293+
ResponseBody responseBody = response.body();
294+
if (response.isSuccessful()) {
295+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<PointsLevelSummaryResponseItem>>() {}), response);
296+
}
297+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
298+
try {
299+
switch (response.code()) {
300+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
301+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
302+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response);
303+
}
304+
}
305+
catch (JsonProcessingException ignored) {
306+
// unable to map error response, throwing generic error
307+
}
308+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
309+
}
310+
catch (IOException e) {
311+
throw new TrophyApiException("Network error executing HTTP request", e);
312+
}
313+
}
211314
}

0 commit comments

Comments
 (0)