Skip to content

Commit

Permalink
feat: add/use RFC3339 fields in requests
Browse files Browse the repository at this point in the history
Timestamp fields that store time as milliseconds since epoch are
being replaced by fields that store it as a RFC 3339 string.

This commit:
- Removes POST /feedbacks `timestamp` field, replacing it with
`occurred_at`. Removal is possible because this field is not in
the public API.
- Add `collected_at` to POST /signups' `additional_locations`. This
field should be used instead of the existing `timestamp`.
  • Loading branch information
figueredo committed Jul 17, 2024
1 parent 2a42d43 commit 33c576a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation platform("com.squareup.okhttp3:okhttp-bom:4.12.0")
implementation "com.squareup.okhttp3:okhttp"
implementation "com.fasterxml.jackson.core:jackson-databind:2.17.1"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1"

testImplementation 'com.auth0:java-jwt:4.4.0'
testImplementation 'commons-io:commons-io:2.16.1'
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,14 @@ public void registerFeedback(

public void registerFeedback(
FeedbackEvent feedbackEvent,
Instant timestamp,
Instant occurredAt,
FeedbackIdentifiers identifiers,
boolean dryRun)
throws IncogniaException {
PostFeedbackRequestBody requestBody =
PostFeedbackRequestBody.builder()
.event(feedbackEvent)
.timestamp(timestamp.toEpochMilli())
.occurredAt(occurredAt)
.installationId(identifiers.getInstallationId())
.sessionToken(identifiers.getSessionToken())
.accountId(identifiers.getAccountId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

public class ObjectMapperFactory {
@SuppressWarnings("deprecation")
// PropertyNamingStrategy.SNAKE_CASE is deprecated but we use it for compatibility with older
// jackson versions
public static final ObjectMapper OBJECT_MAPPER =
new ObjectMapper()
.registerModule(new JavaTimeModule())
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
.setSerializationInclusion(Include.NON_NULL)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/incognia/common/AdditionalLocation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.incognia.common;

import java.time.Instant;
import lombok.Builder;
import lombok.Value;

Expand All @@ -8,5 +9,6 @@
public class AdditionalLocation {
Double lat;
Double lng;
Long timestamp;
@Deprecated Long timestamp;
Instant collectedAt;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.incognia.feedback;

import java.time.Instant;
import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class PostFeedbackRequestBody {
FeedbackEvent event;
Long timestamp;
Instant occurredAt;
String accountId;
String externalId;
String installationId;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/incognia/api/IncogniaAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
.signupId(signupId)
.accountId(accountId)
.event(FeedbackEvent.ACCOUNT_TAKEOVER)
.timestamp(timestamp.toEpochMilli())
.occurredAt(timestamp)
.build());
mockServer.setDispatcher(dispatcher);
client.registerFeedback(
Expand Down

0 comments on commit 33c576a

Please sign in to comment.