Skip to content

Commit 0a44bab

Browse files
Automatically update Java SDK
1 parent b31ce8a commit 0a44bab

File tree

128 files changed

+13664
-2733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+13664
-2733
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424
replay_pid*
25+
26+
# OSX
27+
.DS_Store

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.29</version>
11+
<version>1.0.30</version>
1212
<packaging>jar</packaging>
1313
<name>Trophy</name>
1414
<description>Java client library for the Trophy API</description>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package so.trophy;
2+
3+
/**
4+
* This file was auto-generated by Fern from our API Definition.
5+
*/
6+
7+
import so.trophy.core.ClientOptions;
8+
import so.trophy.core.Suppliers;
9+
import java.util.function.Supplier;
10+
import so.trophy.resources.achievements.AsyncAchievementsClient;
11+
import so.trophy.resources.admin.AsyncAdminClient;
12+
import so.trophy.resources.leaderboards.AsyncLeaderboardsClient;
13+
import so.trophy.resources.metrics.AsyncMetricsClient;
14+
import so.trophy.resources.points.AsyncPointsClient;
15+
import so.trophy.resources.streaks.AsyncStreaksClient;
16+
import so.trophy.resources.users.AsyncUsersClient;
17+
18+
public class AsyncTrophyApiClient {
19+
protected final ClientOptions clientOptions;
20+
21+
protected final Supplier<AsyncAchievementsClient> achievementsClient;
22+
23+
protected final Supplier<AsyncMetricsClient> metricsClient;
24+
25+
protected final Supplier<AsyncUsersClient> usersClient;
26+
27+
protected final Supplier<AsyncStreaksClient> streaksClient;
28+
29+
protected final Supplier<AsyncPointsClient> pointsClient;
30+
31+
protected final Supplier<AsyncLeaderboardsClient> leaderboardsClient;
32+
33+
protected final Supplier<AsyncAdminClient> adminClient;
34+
35+
public AsyncTrophyApiClient(ClientOptions clientOptions) {
36+
this.clientOptions = clientOptions;
37+
this.achievementsClient = Suppliers.memoize(() -> new AsyncAchievementsClient(clientOptions));
38+
this.metricsClient = Suppliers.memoize(() -> new AsyncMetricsClient(clientOptions));
39+
this.usersClient = Suppliers.memoize(() -> new AsyncUsersClient(clientOptions));
40+
this.streaksClient = Suppliers.memoize(() -> new AsyncStreaksClient(clientOptions));
41+
this.pointsClient = Suppliers.memoize(() -> new AsyncPointsClient(clientOptions));
42+
this.leaderboardsClient = Suppliers.memoize(() -> new AsyncLeaderboardsClient(clientOptions));
43+
this.adminClient = Suppliers.memoize(() -> new AsyncAdminClient(clientOptions));
44+
}
45+
46+
public AsyncAchievementsClient achievements() {
47+
return this.achievementsClient.get();
48+
}
49+
50+
public AsyncMetricsClient metrics() {
51+
return this.metricsClient.get();
52+
}
53+
54+
public AsyncUsersClient users() {
55+
return this.usersClient.get();
56+
}
57+
58+
public AsyncStreaksClient streaks() {
59+
return this.streaksClient.get();
60+
}
61+
62+
public AsyncPointsClient points() {
63+
return this.pointsClient.get();
64+
}
65+
66+
public AsyncLeaderboardsClient leaderboards() {
67+
return this.leaderboardsClient.get();
68+
}
69+
70+
public AsyncAdminClient admin() {
71+
return this.adminClient.get();
72+
}
73+
74+
public static AsyncTrophyApiClientBuilder builder() {
75+
return new AsyncTrophyApiClientBuilder();
76+
}
77+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
package so.trophy;
2+
3+
/**
4+
* This file was auto-generated by Fern from our API Definition.
5+
*/
6+
7+
import so.trophy.core.ClientOptions;
8+
import so.trophy.core.Environment;
9+
import java.lang.Integer;
10+
import java.lang.String;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import java.util.Optional;
14+
import okhttp3.OkHttpClient;
15+
16+
public class AsyncTrophyApiClientBuilder {
17+
private Optional<Integer> timeout = Optional.empty();
18+
19+
private Optional<Integer> maxRetries = Optional.empty();
20+
21+
private final Map<String, String> customHeaders = new HashMap<>();
22+
23+
private String apiKey = null;
24+
25+
private Environment environment = Environment.PRODUCTION;
26+
27+
private OkHttpClient httpClient;
28+
29+
/**
30+
* Sets apiKey
31+
*/
32+
public AsyncTrophyApiClientBuilder apiKey(String apiKey) {
33+
this.apiKey = apiKey;
34+
return this;
35+
}
36+
37+
public AsyncTrophyApiClientBuilder environment(Environment environment) {
38+
this.environment = environment;
39+
return this;
40+
}
41+
42+
/**
43+
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
44+
*/
45+
public AsyncTrophyApiClientBuilder timeout(int timeout) {
46+
this.timeout = Optional.of(timeout);
47+
return this;
48+
}
49+
50+
/**
51+
* Sets the maximum number of retries for the client. Defaults to 2 retries.
52+
*/
53+
public AsyncTrophyApiClientBuilder maxRetries(int maxRetries) {
54+
this.maxRetries = Optional.of(maxRetries);
55+
return this;
56+
}
57+
58+
/**
59+
* Sets the underlying OkHttp client
60+
*/
61+
public AsyncTrophyApiClientBuilder httpClient(OkHttpClient httpClient) {
62+
this.httpClient = httpClient;
63+
return this;
64+
}
65+
66+
/**
67+
* Add a custom header to be sent with all requests.
68+
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
69+
*
70+
* @param name The header name
71+
* @param value The header value
72+
* @return This builder for method chaining
73+
*/
74+
public AsyncTrophyApiClientBuilder addHeader(String name, String value) {
75+
this.customHeaders.put(name, value);
76+
return this;
77+
}
78+
79+
protected ClientOptions buildClientOptions() {
80+
ClientOptions.Builder builder = ClientOptions.builder();
81+
setEnvironment(builder);
82+
setAuthentication(builder);
83+
setHttpClient(builder);
84+
setTimeouts(builder);
85+
setRetries(builder);
86+
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
87+
builder.addHeader(header.getKey(), header.getValue());
88+
}
89+
setAdditional(builder);
90+
return builder.build();
91+
}
92+
93+
/**
94+
* Sets the environment configuration for the client.
95+
* Override this method to modify URLs or add environment-specific logic.
96+
*
97+
* @param builder The ClientOptions.Builder to configure
98+
*/
99+
protected void setEnvironment(ClientOptions.Builder builder) {
100+
builder.environment(this.environment);
101+
}
102+
103+
/**
104+
* Override this method to customize authentication.
105+
* This method is called during client options construction to set up authentication headers.
106+
*
107+
* @param builder The ClientOptions.Builder to configure
108+
*
109+
* Example:
110+
* <pre>{@code
111+
* &#64;Override
112+
* protected void setAuthentication(ClientOptions.Builder builder) {
113+
* super.setAuthentication(builder); // Keep existing auth
114+
* builder.addHeader("X-API-Key", this.apiKey);
115+
* }
116+
* }</pre>
117+
*/
118+
protected void setAuthentication(ClientOptions.Builder builder) {
119+
builder.addHeader("X-API-KEY", this.apiKey);
120+
}
121+
122+
/**
123+
* Sets the request timeout configuration.
124+
* Override this method to customize timeout behavior.
125+
*
126+
* @param builder The ClientOptions.Builder to configure
127+
*/
128+
protected void setTimeouts(ClientOptions.Builder builder) {
129+
if (this.timeout.isPresent()) {
130+
builder.timeout(this.timeout.get());
131+
}
132+
}
133+
134+
/**
135+
* Sets the retry configuration for failed requests.
136+
* Override this method to implement custom retry strategies.
137+
*
138+
* @param builder The ClientOptions.Builder to configure
139+
*/
140+
protected void setRetries(ClientOptions.Builder builder) {
141+
if (this.maxRetries.isPresent()) {
142+
builder.maxRetries(this.maxRetries.get());
143+
}
144+
}
145+
146+
/**
147+
* Sets the OkHttp client configuration.
148+
* Override this method to customize HTTP client behavior (interceptors, connection pools, etc).
149+
*
150+
* @param builder The ClientOptions.Builder to configure
151+
*/
152+
protected void setHttpClient(ClientOptions.Builder builder) {
153+
if (this.httpClient != null) {
154+
builder.httpClient(this.httpClient);
155+
}
156+
}
157+
158+
/**
159+
* Override this method to add any additional configuration to the client.
160+
* This method is called at the end of the configuration chain, allowing you to add
161+
* custom headers, modify settings, or perform any other client customization.
162+
*
163+
* @param builder The ClientOptions.Builder to configure
164+
*
165+
* Example:
166+
* <pre>{@code
167+
* &#64;Override
168+
* protected void setAdditional(ClientOptions.Builder builder) {
169+
* builder.addHeader("X-Request-ID", () -&gt; UUID.randomUUID().toString());
170+
* builder.addHeader("X-Client-Version", "1.0.0");
171+
* }
172+
* }</pre>
173+
*/
174+
protected void setAdditional(ClientOptions.Builder builder) {
175+
}
176+
177+
/**
178+
* Override this method to add custom validation logic before the client is built.
179+
* This method is called at the beginning of the build() method to ensure the configuration is valid.
180+
* Throw an exception to prevent client creation if validation fails.
181+
*
182+
* Example:
183+
* <pre>{@code
184+
* &#64;Override
185+
* protected void validateConfiguration() {
186+
* super.validateConfiguration(); // Run parent validations
187+
* if (tenantId == null || tenantId.isEmpty()) {
188+
* throw new IllegalStateException("tenantId is required");
189+
* }
190+
* }
191+
* }</pre>
192+
*/
193+
protected void validateConfiguration() {
194+
}
195+
196+
public AsyncTrophyApiClient build() {
197+
if (apiKey == null) {
198+
throw new RuntimeException("Please provide apiKey");
199+
}
200+
validateConfiguration();
201+
return new AsyncTrophyApiClient(buildClientOptions());
202+
}
203+
}

0 commit comments

Comments
 (0)