Skip to content

Commit 314bee9

Browse files
Automatically update Java SDK
1 parent cfafe0c commit 314bee9

10 files changed

Lines changed: 1030 additions & 5 deletions

File tree

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

‎src/main/java/so/trophy/.fern/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"enable-forward-compatible-enums": false,
77
"retry-status-codes": "legacy"
88
},
9-
"originGitCommit": "fc9c2289d356522ad24b9464747364dd97f31a15",
9+
"originGitCommit": "e5e0764c693f384265aea6528e87792857387287",
1010
"originGitCommitIsDirty": false,
1111
"invokedBy": "ci",
1212
"ciProvider": "github"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private ClientOptions(Environment environment, Map<String, String> headers,
3535
this.environment = environment;
3636
this.headers = new HashMap<>();
3737
this.headers.putAll(headers);
38-
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.5790");}});
38+
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.5847");}});
3939
this.headerSuppliers = headerSuppliers;
4040
this.httpClient = httpClient;
4141
this.timeout = timeout;

‎src/main/java/so/trophy/src/main/java/resources/admin/metrics/AsyncMetricsClient.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.concurrent.CompletableFuture;
1313
import so.trophy.resources.admin.metrics.requests.MetricsDeleteRequest;
1414
import so.trophy.resources.admin.metrics.requests.MetricsListRequest;
15+
import so.trophy.types.BatchEventsResponse;
16+
import so.trophy.types.BatchMetricEvent;
1517
import so.trophy.types.CreateMetricRequestItem;
1618
import so.trophy.types.CreateMetricsResponse;
1719
import so.trophy.types.CreatedMetric;
@@ -137,4 +139,19 @@ public CompletableFuture<CreatedMetric> get(String id) {
137139
public CompletableFuture<CreatedMetric> get(String id, RequestOptions requestOptions) {
138140
return this.rawClient.get(id, requestOptions).thenApply(response -> response.body());
139141
}
142+
143+
/**
144+
* Submit up to 1,000 metric events for asynchronous processing.
145+
*/
146+
public CompletableFuture<BatchEventsResponse> batchEvents(List<BatchMetricEvent> request) {
147+
return this.rawClient.batchEvents(request).thenApply(response -> response.body());
148+
}
149+
150+
/**
151+
* Submit up to 1,000 metric events for asynchronous processing.
152+
*/
153+
public CompletableFuture<BatchEventsResponse> batchEvents(List<BatchMetricEvent> request,
154+
RequestOptions requestOptions) {
155+
return this.rawClient.batchEvents(request, requestOptions).thenApply(response -> response.body());
156+
}
140157
}

‎src/main/java/so/trophy/src/main/java/resources/admin/metrics/AsyncRawMetricsClient.java‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import so.trophy.core.TrophyApiApiException;
1717
import so.trophy.core.TrophyApiException;
1818
import so.trophy.core.TrophyApiHttpResponse;
19+
import so.trophy.errors.BadRequestError;
1920
import so.trophy.errors.NotFoundError;
2021
import so.trophy.errors.UnauthorizedError;
2122
import so.trophy.errors.UnprocessableEntityError;
@@ -37,6 +38,8 @@
3738
import org.jetbrains.annotations.NotNull;
3839
import so.trophy.resources.admin.metrics.requests.MetricsDeleteRequest;
3940
import so.trophy.resources.admin.metrics.requests.MetricsListRequest;
41+
import so.trophy.types.BatchEventsResponse;
42+
import so.trophy.types.BatchMetricEvent;
4043
import so.trophy.types.CreateMetricRequestItem;
4144
import so.trophy.types.CreateMetricsResponse;
4245
import so.trophy.types.CreatedMetric;
@@ -462,4 +465,87 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
462465
});
463466
return future;
464467
}
465-
}
468+
469+
/**
470+
* Submit up to 1,000 metric events for asynchronous processing.
471+
*/
472+
public CompletableFuture<TrophyApiHttpResponse<BatchEventsResponse>> batchEvents(
473+
List<BatchMetricEvent> request) {
474+
return batchEvents(request,null);
475+
}
476+
477+
/**
478+
* Submit up to 1,000 metric events for asynchronous processing.
479+
*/
480+
public CompletableFuture<TrophyApiHttpResponse<BatchEventsResponse>> batchEvents(
481+
List<BatchMetricEvent> request, RequestOptions requestOptions) {
482+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
483+
484+
.addPathSegments("metrics/events");if (requestOptions != null) {
485+
requestOptions.getQueryParameters().forEach((_key, _value) -> {
486+
httpUrl.addQueryParameter(_key, _value);
487+
} );
488+
}
489+
RequestBody body;
490+
try {
491+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
492+
}
493+
catch(JsonProcessingException e) {
494+
throw new TrophyApiException("Failed to serialize request", e);
495+
}
496+
Request okhttpRequest = new Request.Builder()
497+
.url(httpUrl.build())
498+
.method("POST", body)
499+
.headers(Headers.of(clientOptions.headers(requestOptions)))
500+
.addHeader("Content-Type", "application/json")
501+
.addHeader("Accept", "application/json")
502+
.build();
503+
OkHttpClient client = clientOptions.httpClient();
504+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
505+
client = clientOptions.httpClientWithTimeout(requestOptions);
506+
}
507+
if (requestOptions != null && requestOptions.getMaxRetries().isPresent()) {
508+
okhttpRequest = okhttpRequest.newBuilder().tag(RetryInterceptor.MaxRetriesOverride.class, new RetryInterceptor.MaxRetriesOverride(requestOptions.getMaxRetries().get())).build();
509+
}
510+
CompletableFuture<TrophyApiHttpResponse<BatchEventsResponse>> future = new CompletableFuture<>();
511+
client.newCall(okhttpRequest).enqueue(new Callback() {
512+
@Override
513+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
514+
try (ResponseBody responseBody = response.body()) {
515+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
516+
if (response.isSuccessful()) {
517+
future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchEventsResponse.class), response));
518+
return;
519+
}
520+
try {
521+
switch (response.code()) {
522+
case 400:future.completeExceptionally(new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
523+
return;
524+
case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
525+
return;
526+
case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
527+
return;
528+
case 422:future.completeExceptionally(new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
529+
return;
530+
}
531+
}
532+
catch (JsonProcessingException ignored) {
533+
// unable to map error response, throwing generic error
534+
}
535+
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
536+
future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), errorBody, response));
537+
return;
538+
}
539+
catch (IOException e) {
540+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
541+
}
542+
}
543+
544+
@Override
545+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
546+
future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e));
547+
}
548+
});
549+
return future;
550+
}
551+
}

‎src/main/java/so/trophy/src/main/java/resources/admin/metrics/MetricsClient.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.List;
1212
import so.trophy.resources.admin.metrics.requests.MetricsDeleteRequest;
1313
import so.trophy.resources.admin.metrics.requests.MetricsListRequest;
14+
import so.trophy.types.BatchEventsResponse;
15+
import so.trophy.types.BatchMetricEvent;
1416
import so.trophy.types.CreateMetricRequestItem;
1517
import so.trophy.types.CreateMetricsResponse;
1618
import so.trophy.types.CreatedMetric;
@@ -134,4 +136,19 @@ public CreatedMetric get(String id) {
134136
public CreatedMetric get(String id, RequestOptions requestOptions) {
135137
return this.rawClient.get(id, requestOptions).body();
136138
}
139+
140+
/**
141+
* Submit up to 1,000 metric events for asynchronous processing.
142+
*/
143+
public BatchEventsResponse batchEvents(List<BatchMetricEvent> request) {
144+
return this.rawClient.batchEvents(request).body();
145+
}
146+
147+
/**
148+
* Submit up to 1,000 metric events for asynchronous processing.
149+
*/
150+
public BatchEventsResponse batchEvents(List<BatchMetricEvent> request,
151+
RequestOptions requestOptions) {
152+
return this.rawClient.batchEvents(request, requestOptions).body();
153+
}
137154
}

‎src/main/java/so/trophy/src/main/java/resources/admin/metrics/RawMetricsClient.java‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import so.trophy.core.TrophyApiApiException;
1717
import so.trophy.core.TrophyApiException;
1818
import so.trophy.core.TrophyApiHttpResponse;
19+
import so.trophy.errors.BadRequestError;
1920
import so.trophy.errors.NotFoundError;
2021
import so.trophy.errors.UnauthorizedError;
2122
import so.trophy.errors.UnprocessableEntityError;
@@ -32,6 +33,8 @@
3233
import okhttp3.ResponseBody;
3334
import so.trophy.resources.admin.metrics.requests.MetricsDeleteRequest;
3435
import so.trophy.resources.admin.metrics.requests.MetricsListRequest;
36+
import so.trophy.types.BatchEventsResponse;
37+
import so.trophy.types.BatchMetricEvent;
3538
import so.trophy.types.CreateMetricRequestItem;
3639
import so.trophy.types.CreateMetricsResponse;
3740
import so.trophy.types.CreatedMetric;
@@ -377,4 +380,70 @@ public TrophyApiHttpResponse<CreatedMetric> get(String id,
377380
throw new TrophyApiException("Network error executing HTTP request", e);
378381
}
379382
}
380-
}
383+
384+
/**
385+
* Submit up to 1,000 metric events for asynchronous processing.
386+
*/
387+
public TrophyApiHttpResponse<BatchEventsResponse> batchEvents(
388+
List<BatchMetricEvent> request) {
389+
return batchEvents(request,null);
390+
}
391+
392+
/**
393+
* Submit up to 1,000 metric events for asynchronous processing.
394+
*/
395+
public TrophyApiHttpResponse<BatchEventsResponse> batchEvents(
396+
List<BatchMetricEvent> request, RequestOptions requestOptions) {
397+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder()
398+
399+
.addPathSegments("metrics/events");if (requestOptions != null) {
400+
requestOptions.getQueryParameters().forEach((_key, _value) -> {
401+
httpUrl.addQueryParameter(_key, _value);
402+
} );
403+
}
404+
RequestBody body;
405+
try {
406+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
407+
}
408+
catch(JsonProcessingException e) {
409+
throw new TrophyApiException("Failed to serialize request", e);
410+
}
411+
Request okhttpRequest = new Request.Builder()
412+
.url(httpUrl.build())
413+
.method("POST", body)
414+
.headers(Headers.of(clientOptions.headers(requestOptions)))
415+
.addHeader("Content-Type", "application/json")
416+
.addHeader("Accept", "application/json")
417+
.build();
418+
OkHttpClient client = clientOptions.httpClient();
419+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
420+
client = clientOptions.httpClientWithTimeout(requestOptions);
421+
}
422+
if (requestOptions != null && requestOptions.getMaxRetries().isPresent()) {
423+
okhttpRequest = okhttpRequest.newBuilder().tag(RetryInterceptor.MaxRetriesOverride.class, new RetryInterceptor.MaxRetriesOverride(requestOptions.getMaxRetries().get())).build();
424+
}
425+
try (Response response = client.newCall(okhttpRequest).execute()) {
426+
ResponseBody responseBody = response.body();
427+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
428+
if (response.isSuccessful()) {
429+
return new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, BatchEventsResponse.class), response);
430+
}
431+
try {
432+
switch (response.code()) {
433+
case 400:throw new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
434+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
435+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
436+
case 422:throw new UnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
437+
}
438+
}
439+
catch (JsonProcessingException ignored) {
440+
// unable to map error response, throwing generic error
441+
}
442+
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
443+
throw new TrophyApiApiException("Error with status code " + response.code(), response.code(), errorBody, response);
444+
}
445+
catch (IOException e) {
446+
throw new TrophyApiException("Network error executing HTTP request", e);
447+
}
448+
}
449+
}

0 commit comments

Comments
 (0)