Skip to content

Commit 801e37e

Browse files
Automatically update Java SDK
1 parent 3db5109 commit 801e37e

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-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.0.22</version>
11+
<version>1.0.23</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.1555");}});
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");}});
3232
this.headerSuppliers = headerSuppliers;
3333
this.httpClient = httpClient;
3434
this.timeout = timeout;

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import so.trophy.errors.UnauthorizedError;
1717
import so.trophy.errors.UnprocessableEntityError;
1818
import java.io.IOException;
19+
import java.lang.Exception;
1920
import java.lang.Object;
21+
import java.lang.RuntimeException;
2022
import java.lang.String;
23+
import java.util.HashMap;
24+
import java.util.Map;
2125
import okhttp3.Headers;
2226
import okhttp3.HttpUrl;
2327
import okhttp3.OkHttpClient;
@@ -54,20 +58,28 @@ public EventResponse event(String key, MetricsEventRequest request,
5458
.addPathSegment(key)
5559
.addPathSegments("event")
5660
.build();
61+
Map<String, Object> properties = new HashMap<>();
62+
properties.put("user", request.getUser());
63+
properties.put("value", request.getValue());
64+
if (request.getAttributes().isPresent()) {
65+
properties.put("attributes", request.getAttributes());
66+
}
5767
RequestBody body;
5868
try {
59-
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
69+
body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON);
6070
}
61-
catch(JsonProcessingException e) {
62-
throw new TrophyApiException("Failed to serialize request", e);
71+
catch(Exception e) {
72+
throw new RuntimeException(e);
6373
}
64-
Request okhttpRequest = new Request.Builder()
74+
Request.Builder _requestBuilder = new Request.Builder()
6575
.url(httpUrl)
6676
.method("POST", body)
6777
.headers(Headers.of(clientOptions.headers(requestOptions)))
68-
.addHeader("Content-Type", "application/json")
69-
.addHeader("Accept", "application/json")
70-
.build();
78+
.addHeader("Content-Type", "application/json").addHeader("Accept", "application/json");
79+
if (request.getIdempotencyKey().isPresent()) {
80+
_requestBuilder.addHeader("Idempotency-Key", request.getIdempotencyKey().get());
81+
}
82+
Request okhttpRequest = _requestBuilder.build();
7183
OkHttpClient client = clientOptions.httpClient();
7284
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
7385
client = clientOptions.httpClientWithTimeout(requestOptions);

src/main/java/so/trophy/resources/metrics/requests/MetricsEventRequest.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
builder = MetricsEventRequest.Builder.class
2929
)
3030
public final class MetricsEventRequest {
31+
private final Optional<String> idempotencyKey;
32+
3133
private final UpsertedUser user;
3234

3335
private final double value;
@@ -36,14 +38,23 @@ public final class MetricsEventRequest {
3638

3739
private final Map<String, Object> additionalProperties;
3840

39-
private MetricsEventRequest(UpsertedUser user, double value,
41+
private MetricsEventRequest(Optional<String> idempotencyKey, UpsertedUser user, double value,
4042
Optional<Map<String, String>> attributes, Map<String, Object> additionalProperties) {
43+
this.idempotencyKey = idempotencyKey;
4144
this.user = user;
4245
this.value = value;
4346
this.attributes = attributes;
4447
this.additionalProperties = additionalProperties;
4548
}
4649

50+
/**
51+
* @return The idempotency key for the event.
52+
*/
53+
@JsonProperty("Idempotency-Key")
54+
public Optional<String> getIdempotencyKey() {
55+
return idempotencyKey;
56+
}
57+
4758
/**
4859
* @return The user that triggered the event.
4960
*/
@@ -80,12 +91,12 @@ public Map<String, Object> getAdditionalProperties() {
8091
}
8192

8293
private boolean equalTo(MetricsEventRequest other) {
83-
return user.equals(other.user) && value == other.value && attributes.equals(other.attributes);
94+
return idempotencyKey.equals(other.idempotencyKey) && user.equals(other.user) && value == other.value && attributes.equals(other.attributes);
8495
}
8596

8697
@java.lang.Override
8798
public int hashCode() {
88-
return Objects.hash(this.user, this.value, this.attributes);
99+
return Objects.hash(this.idempotencyKey, this.user, this.value, this.attributes);
89100
}
90101

91102
@java.lang.Override
@@ -110,6 +121,10 @@ public interface ValueStage {
110121
public interface _FinalStage {
111122
MetricsEventRequest build();
112123

124+
_FinalStage idempotencyKey(Optional<String> idempotencyKey);
125+
126+
_FinalStage idempotencyKey(String idempotencyKey);
127+
113128
_FinalStage attributes(Optional<Map<String, String>> attributes);
114129

115130
_FinalStage attributes(Map<String, String> attributes);
@@ -125,6 +140,8 @@ public static final class Builder implements UserStage, ValueStage, _FinalStage
125140

126141
private Optional<Map<String, String>> attributes = Optional.empty();
127142

143+
private Optional<String> idempotencyKey = Optional.empty();
144+
128145
@JsonAnySetter
129146
private Map<String, Object> additionalProperties = new HashMap<>();
130147

@@ -133,6 +150,7 @@ private Builder() {
133150

134151
@java.lang.Override
135152
public Builder from(MetricsEventRequest other) {
153+
idempotencyKey(other.getIdempotencyKey());
136154
user(other.getUser());
137155
value(other.getValue());
138156
attributes(other.getAttributes());
@@ -181,9 +199,29 @@ public _FinalStage attributes(Optional<Map<String, String>> attributes) {
181199
return this;
182200
}
183201

202+
/**
203+
* <p>The idempotency key for the event.</p>
204+
* @return Reference to {@code this} so that method calls can be chained together.
205+
*/
206+
@java.lang.Override
207+
public _FinalStage idempotencyKey(String idempotencyKey) {
208+
this.idempotencyKey = Optional.ofNullable(idempotencyKey);
209+
return this;
210+
}
211+
212+
@java.lang.Override
213+
@JsonSetter(
214+
value = "Idempotency-Key",
215+
nulls = Nulls.SKIP
216+
)
217+
public _FinalStage idempotencyKey(Optional<String> idempotencyKey) {
218+
this.idempotencyKey = idempotencyKey;
219+
return this;
220+
}
221+
184222
@java.lang.Override
185223
public MetricsEventRequest build() {
186-
return new MetricsEventRequest(user, value, attributes, additionalProperties);
224+
return new MetricsEventRequest(idempotencyKey, user, value, attributes, additionalProperties);
187225
}
188226
}
189227
}

0 commit comments

Comments
 (0)