Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add/use RFC3339 fields in requests #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
63 changes: 45 additions & 18 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public IncogniaAPI(String clientId, String clientSecret) {
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Address address = Address address =
* Address.builder()
Expand Down Expand Up @@ -128,7 +128,7 @@ public SignupAssessment registerSignup(RegisterSignupRequest request) throws Inc
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
* .installationId("installation-id")
Expand Down Expand Up @@ -183,7 +183,7 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
* .accountId("account-id")
Expand Down Expand Up @@ -237,7 +237,7 @@ public TransactionAssessment registerWebLogin(RegisterWebLoginRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterWebSignupRequest webSignupRequest = RegisterWebSignupRequest.builder().sessionToken(sessionToken).address(address).build();
* SignupAssessment assessment = api.registerSignup(webSignupRequest);
Expand Down Expand Up @@ -275,7 +275,7 @@ public SignupAssessment registerWebSignup(RegisterWebSignupRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Address address = Address address =
* Address.builder()
Expand Down Expand Up @@ -374,19 +374,16 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant timestamp = Instant.now();
* client.registerFeedback(
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* api.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* timestamp,
* occurredAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .sessionToken("session-token")
* .accountId("account-id")
* .externalId("external-id")
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
* .build();
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
Expand All @@ -395,27 +392,57 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param timestamp Instant when the fraud or event happened
* @param occurredAt Instant when the fraud or event happened
* @param identifiers the user's identifiers
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
FeedbackEvent feedbackEvent, Instant timestamp, FeedbackIdentifiers identifiers)
FeedbackEvent feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, timestamp, identifiers, false);
registerFeedback(feedbackEvent, occurredAt, identifiers, false);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* api.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* occurredAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param identifiers the user's identifiers
* @param dryRun whether this request is a dry-run
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
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,14 +4,18 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
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);
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
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,12 +1,14 @@
package com.incognia.common;

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

@Value

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
AdditionalLocation.getTimestamp
should be avoided because it has been deprecated.
@Builder
public class AdditionalLocation {
Double lat;
Double lng;
Long timestamp;
@Deprecated Long timestamp;
Instant collectedAt;
Comment on lines +12 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to mark the old field as deprecated and add the new here as this class is used by the user. Given that we are bumping the major due to the removal of GetSignup, should we take the opportunity and remove the old field too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

@figueredo figueredo Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it later together with the other breaking changes.

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.incognia.feedback;

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

@Value

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
PostFeedbackRequestBody.getTimestamp
should be avoided because it has been deprecated.
@Builder
public class PostFeedbackRequestBody {
FeedbackEvent event;
Long timestamp;
@Deprecated Long timestamp;
Instant occurredAt;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change once PostFeedbackRequestBody is public, but I'm considering it as not because the user isn't supposed to use this class directly. Should change the visiblity of these internal classes to avoid issues?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it in another PR to be released together with the breaking changes.

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
Loading