Skip to content

Commit b5d0af0

Browse files
Automatically update Java SDK
1 parent c68d0bd commit b5d0af0

File tree

5 files changed

+373
-17
lines changed

5 files changed

+373
-17
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.20</version>
11+
<version>1.0.21</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
@@ -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.1485");}});
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.1530");}});
3232
this.headerSuppliers = headerSuppliers;
3333
this.httpClient = httpClient;
3434
this.timeout = timeout;

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

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import okhttp3.Request;
2525
import okhttp3.Response;
2626
import okhttp3.ResponseBody;
27+
import so.trophy.resources.streaks.requests.StreaksListRequest;
2728
import so.trophy.resources.streaks.requests.StreaksRankingsRequest;
29+
import so.trophy.types.BulkStreakResponseItem;
2830
import so.trophy.types.ErrorBody;
2931
import so.trophy.types.StreakRankingUser;
3032

@@ -36,31 +38,28 @@ public StreaksClient(ClientOptions clientOptions) {
3638
}
3739

3840
/**
39-
* Get the top users by streak length (active or longest).
41+
* Get the streak lengths of a list of users, ranked by streak length from longest to shortest.
4042
*/
41-
public List<StreakRankingUser> rankings() {
42-
return rankings(StreaksRankingsRequest.builder().build());
43+
public List<BulkStreakResponseItem> list() {
44+
return list(StreaksListRequest.builder().build());
4345
}
4446

4547
/**
46-
* Get the top users by streak length (active or longest).
48+
* Get the streak lengths of a list of users, ranked by streak length from longest to shortest.
4749
*/
48-
public List<StreakRankingUser> rankings(StreaksRankingsRequest request) {
49-
return rankings(request,null);
50+
public List<BulkStreakResponseItem> list(StreaksListRequest request) {
51+
return list(request,null);
5052
}
5153

5254
/**
53-
* Get the top users by streak length (active or longest).
55+
* Get the streak lengths of a list of users, ranked by streak length from longest to shortest.
5456
*/
55-
public List<StreakRankingUser> rankings(StreaksRankingsRequest request,
57+
public List<BulkStreakResponseItem> list(StreaksListRequest request,
5658
RequestOptions requestOptions) {
5759
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
5860

59-
.addPathSegments("streaks/rankings");if (request.getLimit().isPresent()) {
60-
httpUrl.addQueryParameter("limit", request.getLimit().get().toString());
61-
}
62-
if (request.getType().isPresent()) {
63-
httpUrl.addQueryParameter("type", request.getType().get().toString());
61+
.addPathSegments("streaks");if (request.getUserIds().isPresent()) {
62+
httpUrl.addQueryParameter("userIds", request.getUserIds().get());
6463
}
6564
Request.Builder _requestBuilder = new Request.Builder()
6665
.url(httpUrl.build())
@@ -75,7 +74,7 @@ public List<StreakRankingUser> rankings(StreaksRankingsRequest request,
7574
try (Response response = client.newCall(okhttpRequest).execute()) {
7675
ResponseBody responseBody = response.body();
7776
if (response.isSuccessful()) {
78-
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<StreakRankingUser>>() {});
77+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<BulkStreakResponseItem>>() {});
7978
}
8079
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
8180
try {
@@ -93,4 +92,63 @@ public List<StreakRankingUser> rankings(StreaksRankingsRequest request,
9392
throw new TrophyApiException("Network error executing HTTP request", e);
9493
}
9594
}
96-
}
95+
96+
/**
97+
* Get the top users by streak length (active or longest).
98+
*/
99+
public List<StreakRankingUser> rankings() {
100+
return rankings(StreaksRankingsRequest.builder().build());
101+
}
102+
103+
/**
104+
* Get the top users by streak length (active or longest).
105+
*/
106+
public List<StreakRankingUser> rankings(StreaksRankingsRequest request) {
107+
return rankings(request,null);
108+
}
109+
110+
/**
111+
* Get the top users by streak length (active or longest).
112+
*/
113+
public List<StreakRankingUser> rankings(StreaksRankingsRequest request,
114+
RequestOptions requestOptions) {
115+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
116+
117+
.addPathSegments("streaks/rankings");if (request.getLimit().isPresent()) {
118+
httpUrl.addQueryParameter("limit", request.getLimit().get().toString());
119+
}
120+
if (request.getType().isPresent()) {
121+
httpUrl.addQueryParameter("type", request.getType().get().toString());
122+
}
123+
Request.Builder _requestBuilder = new Request.Builder()
124+
.url(httpUrl.build())
125+
.method("GET", null)
126+
.headers(Headers.of(clientOptions.headers(requestOptions)))
127+
.addHeader("Content-Type", "application/json").addHeader("Accept", "application/json");
128+
Request okhttpRequest = _requestBuilder.build();
129+
OkHttpClient client = clientOptions.httpClient();
130+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
131+
client = clientOptions.httpClientWithTimeout(requestOptions);
132+
}
133+
try (Response response = client.newCall(okhttpRequest).execute()) {
134+
ResponseBody responseBody = response.body();
135+
if (response.isSuccessful()) {
136+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), new TypeReference<List<StreakRankingUser>>() {});
137+
}
138+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
139+
try {
140+
switch (response.code()) {
141+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
142+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class));
143+
}
144+
}
145+
catch (JsonProcessingException ignored) {
146+
// unable to map error response, throwing generic error
147+
}
148+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
149+
}
150+
catch (IOException e) {
151+
throw new TrophyApiException("Network error executing HTTP request", e);
152+
}
153+
}
154+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package so.trophy.resources.streaks.requests;
2+
3+
/**
4+
* This file was auto-generated by Fern from our API Definition.
5+
*/
6+
7+
8+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
9+
import com.fasterxml.jackson.annotation.JsonAnySetter;
10+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
11+
import com.fasterxml.jackson.annotation.JsonInclude;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.fasterxml.jackson.annotation.JsonSetter;
14+
import com.fasterxml.jackson.annotation.Nulls;
15+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
16+
import so.trophy.core.ObjectMappers;
17+
import java.lang.Object;
18+
import java.lang.String;
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
import java.util.Objects;
22+
import java.util.Optional;
23+
24+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
25+
@JsonDeserialize(
26+
builder = StreaksListRequest.Builder.class
27+
)
28+
public final class StreaksListRequest {
29+
private final Optional<String> userIds;
30+
31+
private final Map<String, Object> additionalProperties;
32+
33+
private StreaksListRequest(Optional<String> userIds, Map<String, Object> additionalProperties) {
34+
this.userIds = userIds;
35+
this.additionalProperties = additionalProperties;
36+
}
37+
38+
/**
39+
* @return A list of up to 100 user IDs.
40+
*/
41+
@JsonProperty("userIds")
42+
public Optional<String> getUserIds() {
43+
return userIds;
44+
}
45+
46+
@java.lang.Override
47+
public boolean equals(Object other) {
48+
if (this == other) return true;
49+
return other instanceof StreaksListRequest && equalTo((StreaksListRequest) other);
50+
}
51+
52+
@JsonAnyGetter
53+
public Map<String, Object> getAdditionalProperties() {
54+
return this.additionalProperties;
55+
}
56+
57+
private boolean equalTo(StreaksListRequest other) {
58+
return userIds.equals(other.userIds);
59+
}
60+
61+
@java.lang.Override
62+
public int hashCode() {
63+
return Objects.hash(this.userIds);
64+
}
65+
66+
@java.lang.Override
67+
public String toString() {
68+
return ObjectMappers.stringify(this);
69+
}
70+
71+
public static Builder builder() {
72+
return new Builder();
73+
}
74+
75+
@JsonIgnoreProperties(
76+
ignoreUnknown = true
77+
)
78+
public static final class Builder {
79+
private Optional<String> userIds = Optional.empty();
80+
81+
@JsonAnySetter
82+
private Map<String, Object> additionalProperties = new HashMap<>();
83+
84+
private Builder() {
85+
}
86+
87+
public Builder from(StreaksListRequest other) {
88+
userIds(other.getUserIds());
89+
return this;
90+
}
91+
92+
@JsonSetter(
93+
value = "userIds",
94+
nulls = Nulls.SKIP
95+
)
96+
public Builder userIds(Optional<String> userIds) {
97+
this.userIds = userIds;
98+
return this;
99+
}
100+
101+
public Builder userIds(String userIds) {
102+
this.userIds = Optional.ofNullable(userIds);
103+
return this;
104+
}
105+
106+
public StreaksListRequest build() {
107+
return new StreaksListRequest(userIds, additionalProperties);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)