Skip to content

Commit

Permalink
Merge pull request #94 from SiftScience/API-7197
Browse files Browse the repository at this point in the history
API-7197: Implement missing fields in Events API
  • Loading branch information
advornichenko-sift authored Jul 6, 2023
2 parents 54eb0a1 + b3d6c84 commit 09c2f3a
Show file tree
Hide file tree
Showing 25 changed files with 901 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.11.0 (2023-06-29)
=================
- Add support for `$user_email` field to `$add_item_to_cart`, `$add_promotion`, `$content_status`, `$flag_content`, `$remove_item_from_cart` and `$update_password` events
- Add support for `$shipping_carrier` and `$shipping_tracking_numbers` fields to `$create_order` and `$update_order` events
- Add support for `$reason` field to `$flag_content` event

3.10.0 (2023-06-06)
=================
- Remove support for `$keyless_user_id` field for Events API
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Java 1.7 or later.
<dependency>
<groupId>com.siftscience</groupId>
<artifactId>sift-java</artifactId>
<version>3.10.0</version>
<version>3.11.0</version>
</dependency>
```
### Gradle
```
dependencies {
compile 'com.siftscience:sift-java:3.10.0'
compile 'com.siftscience:sift-java:3.11.0'
}
```
### Other
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'signing'
apply plugin: 'java-library-distribution'

group = 'com.siftscience'
version = '3.10.0'
version = '3.11.0'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/siftscience/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class Constants {

public static final String API_VERSION = "v205";
public static final String LIB_VERSION = "3.8.0";
public static final String LIB_VERSION = "3.11.0";
public static final String USER_AGENT_HEADER = String.format("SiftScience/%s sift-java/%s", API_VERSION, LIB_VERSION);
}
1 change: 1 addition & 0 deletions src/main/java/com/siftscience/FieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class FieldSet<T extends FieldSet<T>> {
public static final String TIME = "$time";
public static final String IS_BAD = "$is_bad";
public static final String ABUSE_TYPE = "$abuse_type";
public static final String USER_EMAIL = "$user_email";
public static final String VERIFICATION_PHONE_NUMBER = "$verification_phone_number";

// Serialization happens in two stages. First, the object is serialized with `defaultGson`
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/AddItemToCartFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static AddItemToCartFieldSet fromJson(String json) {
}

@Expose @SerializedName("$item") private Item item;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -25,6 +26,15 @@ public AddItemToCartFieldSet setItem(Item item) {
return this;
}

public String getUserEmail() {
return userEmail;
}

public AddItemToCartFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/AddPromotionFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static AddPromotionFieldSet fromJson(String json) {
}

@Expose @SerializedName("$promotions") private List<Promotion> promotions;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -27,6 +28,15 @@ public AddPromotionFieldSet setPromotions(List<Promotion> promotions) {
return this;
}

public String getUserEmail() {
return userEmail;
}

public AddPromotionFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public abstract class BaseAccountFieldSet<T extends BaseAccountFieldSet<T>>
extends BaseAppBrowserSiteBrandFieldSet<T> {
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$name") private String name;
@Expose @SerializedName("$phone") private String phone;
@Expose @SerializedName("$referrer_user_id") private String referrerUserId;
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/com/siftscience/model/BaseOrderFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class BaseOrderFieldSet<T extends BaseOrderFieldSet<T>>
extends BaseAppBrowserSiteBrandFieldSet<T> {
@Expose @SerializedName("$order_id") private String orderId;
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$billing_address") private Address billingAddress;
Expand All @@ -19,6 +19,8 @@ public abstract class BaseOrderFieldSet<T extends BaseOrderFieldSet<T>>
@Expose @SerializedName("$seller_user_id") private String sellerUserId;
@Expose @SerializedName("$promotions") private List<Promotion> promotions;
@Expose @SerializedName("$shipping_method") private String shippingMethod;
@Expose @SerializedName("$shipping_carrier") private String shippingCarrier;
@Expose @SerializedName("$shipping_tracking_numbers") private List<String> shippingTrackingNumbers;
@Expose @SerializedName("$bookings") private List<Booking> bookings;
@Expose @SerializedName("$ordered_from") private OrderedFrom orderedFrom;
@Expose @SerializedName("$merchant_profile") private MerchantProfile merchantProfile;
Expand Down Expand Up @@ -146,6 +148,24 @@ public T setShippingMethod(String shippingMethod) {
return (T) this;
}

public String getShippingCarrier() {
return shippingCarrier;
}

public T setShippingCarrier(String shippingCarrier) {
this.shippingCarrier = shippingCarrier;
return (T) this;
}

public List<String> getShippingTrackingNumbers() {
return shippingTrackingNumbers;
}

public T setShippingTrackingNumbers(List<String> shippingTrackingNumbers) {
this.shippingTrackingNumbers = shippingTrackingNumbers;
return (T) this;
}

public OrderedFrom getOrderedFrom() {
return orderedFrom;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/ContentStatusFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static ContentStatusFieldSet fromJson(String json) {

@Expose @SerializedName("$content_id") private String contentId;
@Expose @SerializedName("$status") private String status;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -35,6 +36,15 @@ public ContentStatusFieldSet setContentId(String contentId) {
return this;
}

public String getUserEmail() {
return userEmail;
}

public ContentStatusFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static CustomEventFieldSet fromJson(String json) {
}

@Expose @SerializedName(EVENT_TYPE) private String eventType;
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$name") private String name;
@Expose @SerializedName("$phone") private String phone;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/siftscience/model/FlagContentFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,32 @@ public static FlagContentFieldSet fromJson(String json) {
return gson.fromJson(json, FlagContentFieldSet.class);
}

public enum FlagContentReason {
TOXIC("$toxic"),
IRRELEVANT("$irrelevant"),
COMMERCIAL("$commercial"),
PHISHING("$phishing"),
PRIVATE("$private"),
SCAM("$scam"),
COPYRIGHT("$copyright"),
OTHER("$other");

public final String value;

FlagContentReason(String value) {
this.value = value;
}

@Override
public String toString() {
return value;
}
}

@Expose @SerializedName("$content_id") private String contentId;
@Expose @SerializedName("$flagged_by") private String flaggedBy;
@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -35,6 +59,24 @@ public FlagContentFieldSet setFlaggedBy(String flaggedBy) {
return this;
}

public String getReason() {
return reason;
}

public FlagContentFieldSet setReason(FlagContentReason reason) {
this.reason = reason.value;
return this;
}

public String getUserEmail() {
return userEmail;
}

public FlagContentFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/siftscience/model/LoginFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static LoginFieldSet fromJson(String json) {
@Expose @SerializedName("$username") private String username;
@Expose @SerializedName("$social_sign_on_type") private String socialSignOnType;
@Expose @SerializedName("$account_types") private List<String> accountTypes;
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static RemoveItemFromCartFieldSet fromJson(String json) {
}

@Expose @SerializedName("$item") private Item item;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -25,6 +26,15 @@ public RemoveItemFromCartFieldSet setItem(Item item) {
return this;
}

public String getUserEmail() {
return userEmail;
}

public RemoveItemFromCartFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class TransactionFieldSet extends BaseAppBrowserSiteBrandFieldSet<TransactionFieldSet> {
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName("$transaction_type") private String transactionType;
@Expose @SerializedName("$transaction_status") private String transactionStatus;
@Expose @SerializedName("$order_id") private String orderId;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static UpdatePasswordFieldSet fromJson(String json) {

@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName("$status") private String status;
@Expose @SerializedName(USER_EMAIL) private String userEmail;
@Expose @SerializedName(VERIFICATION_PHONE_NUMBER) private String verificationPhoneNumber;

@Override
Expand All @@ -31,6 +32,15 @@ public UpdatePasswordFieldSet setStatus(String status) {
return this;
}

public String getUserEmail() {
return userEmail;
}

public UpdatePasswordFieldSet setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public String getVerificationPhoneNumber() {
return verificationPhoneNumber;
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/siftscience/AddItemToCartEventTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.siftscience;

import com.siftscience.model.AddItemToCartFieldSet;
import com.siftscience.model.EventResponseBody;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand Down Expand Up @@ -34,6 +35,7 @@ public void testAddItemToCart() throws Exception {
" \"$color\" : \"Texas Tea\",\n" +
" \"$quantity\" : 2\n" +
" },\n" +
" \"$user_email\" : \"[email protected]\",\n" +
" \"$verification_phone_number\" : \"+12345678901\"\n" +
"}";

Expand All @@ -57,13 +59,14 @@ public void testAddItemToCart() throws Exception {
.build());

// Build and execute the request against the mock server.
SiftRequest request = client.buildRequest(new AddItemToCartFieldSet()
SiftRequest<EventResponse> request = client.buildRequest(new AddItemToCartFieldSet()
.setUserId("billy_jones_301")
.setSessionId("gigtleqddo84l8cm15qe4il")
.setItem(TestUtils.sampleItem2())
.setUserEmail("[email protected]")
.setVerificationPhoneNumber("+12345678901"));

SiftResponse siftResponse = request.send();
SiftResponse<EventResponseBody> siftResponse = request.send();

// Verify the request.
RecordedRequest request1 = server.takeRequest();
Expand All @@ -73,6 +76,7 @@ public void testAddItemToCart() throws Exception {

// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/siftscience/AddPromotionEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import com.siftscience.model.AddPromotionFieldSet;
import com.siftscience.model.EventResponseBody;
import com.siftscience.model.Promotion;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
Expand Down Expand Up @@ -34,6 +35,7 @@ public void testAddPromotion() throws Exception {
" }\n" +
" }\n" +
" ],\n" +
" \"$user_email\" : \"[email protected]\",\n" +
" \"$verification_phone_number\" : \"+12345678901\"\n" +
"}";

Expand Down Expand Up @@ -61,12 +63,13 @@ public void testAddPromotion() throws Exception {
promotions.add(TestUtils.samplePromotion3());

// Build and execute the request against the mock server.
SiftRequest request = client.buildRequest(new AddPromotionFieldSet()
SiftRequest<EventResponse> request = client.buildRequest(new AddPromotionFieldSet()
.setUserId("billy_jones_301")
.setPromotions(promotions)
.setUserEmail("[email protected]")
.setVerificationPhoneNumber("+12345678901"));

SiftResponse siftResponse = request.send();
SiftResponse<EventResponseBody> siftResponse = request.send();

// Verify the request.
RecordedRequest request1 = server.takeRequest();
Expand All @@ -76,6 +79,7 @@ public void testAddPromotion() throws Exception {

// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
Assert.assertNotNull(siftResponse.getBody());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
Expand Down
Loading

0 comments on commit 09c2f3a

Please sign in to comment.