Skip to content

Commit

Permalink
Merge pull request #37 from SiftScience/cchi_ato_api_updates_multiple…
Browse files Browse the repository at this point in the history
…_events

Add support for multiple new fields/events
- $verification
- $create_account and $update_account
- $update_password
  • Loading branch information
ChloeChi authored Feb 1, 2019
2 parents 7cb7d47 + 978a8a5 commit d5242d0
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.6.0 (2019-01-30)
=================

- Add support for `$account_types` to the `$create_account` event and the `$update_account` event
- Add support for the new event `$update_password`
- Add support for `$verified_event`, `$reason`, `$verified_entity_id` to the `$verification` event
- Add support for `$ip`, `$browser`, `$app` to the `$verification` event

2.5.0 (2019-01-09)
=================

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Java 1.7 or later.
<dependency>
<groupId>com.siftscience</groupId>
<artifactId>sift-java</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
</dependency>
```
### Gradle
```
dependencies {
compile 'com.siftscience:sift-java:2.5.0'
compile 'com.siftscience:sift-java:2.6.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 = '2.5.0'
version = '2.6.0'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static CreateAccountFieldSet fromJson(String json) {
return gson.fromJson(json, CreateAccountFieldSet.class);
}

@Expose @SerializedName("$account_types") private List<String> accountTypes;
@Expose @SerializedName("$promotions") private List<Promotion> promotions;

@Override
Expand All @@ -25,4 +26,11 @@ public CreateAccountFieldSet setPromotions(List<Promotion> promotions) {
this.promotions = promotions;
return this;
}

public List<String> getAccountTypes() { return accountTypes; }

public CreateAccountFieldSet setAccountTypes(List<String> accountTypes) {
this.accountTypes = accountTypes;
return this;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/siftscience/model/UpdateAccountFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.List;

public class UpdateAccountFieldSet extends BaseAccountFieldSet<UpdateAccountFieldSet> {
public static UpdateAccountFieldSet fromJson(String json) {
return gson.fromJson(json, UpdateAccountFieldSet.class);
}

@Expose @SerializedName("$account_types") private List<String> accountTypes;
@Expose @SerializedName("$changed_password") private Boolean changedPassword;

@Override
Expand All @@ -23,4 +26,11 @@ public UpdateAccountFieldSet setChangedPassword(Boolean changedPassword) {
this.changedPassword = changedPassword;
return this;
}

public List<String> getAccountTypes() { return accountTypes; }

public UpdateAccountFieldSet setAccountTypes(List<String> accountTypes) {
this.accountTypes = accountTypes;
return this;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/siftscience/model/UpdatePasswordFieldSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class UpdatePasswordFieldSet extends BaseAppBrowserFieldSet<UpdatePasswordFieldSet> {
public static UpdatePasswordFieldSet fromJson(String json) {
return gson.fromJson(json, UpdatePasswordFieldSet.class);
}

@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName("$status") private String status;

@Override
public String getEventType() {
return "$update_password";
}

public String getReason() { return reason; }

public UpdatePasswordFieldSet setReason(String reason) {
this.reason = reason;
return this;
}

public String getStatus() { return status; }

public UpdatePasswordFieldSet setStatus(String status) {
this.status = status;
return this;
}
}
26 changes: 25 additions & 1 deletion src/main/java/com/siftscience/model/VerificationFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class VerificationFieldSet extends EventsApiRequestFieldSet<VerificationFieldSet> {
public class VerificationFieldSet extends BaseAppBrowserFieldSet<VerificationFieldSet> {
public static VerificationFieldSet fromJson(String json) {
return gson.fromJson(json, VerificationFieldSet.class);
}

@Expose @SerializedName("$status") private String status;
@Expose @SerializedName("$verification_type") private String verificationType;
@Expose @SerializedName("$verified_value") private String verifiedValue;
@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName("$verified_event") private String verifiedEvent;
@Expose @SerializedName("$verified_entity_id") private String verifiedEntityId;

@Override
public String getEventType() {
Expand Down Expand Up @@ -43,4 +46,25 @@ public VerificationFieldSet setVerifiedValue(String verifiedValue) {
this.verifiedValue = verifiedValue;
return this;
}

public String getReason() { return reason; }

public VerificationFieldSet setReason(String reason) {
this.reason = reason;
return this;
}

public String getVerifiedEvent() { return verifiedEvent; }

public VerificationFieldSet setVerifiedEvent(String verifiedEvent) {
this.verifiedEvent = verifiedEvent;
return this;
}

public String getVerifiedEntityId() { return verifiedEntityId; }

public VerificationFieldSet setVerifiedEntityId(String verifiedEntityId) {
this.verifiedEntityId = verifiedEntityId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import com.siftscience.model.UpdateListingFieldSet;
import com.siftscience.model.UpdateMessageFieldSet;
import com.siftscience.model.UpdateOrderFieldSet;
import com.siftscience.model.UpdatePasswordFieldSet;
import com.siftscience.model.UpdatePostFieldSet;
import com.siftscience.model.UpdateProfileFieldSet;
import com.siftscience.model.UpdateReviewFieldSet;
import com.siftscience.model.VerificationFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand Down Expand Up @@ -76,9 +78,11 @@ public void testAllSubclasses() {
UpdateListingFieldSet.class,
UpdateMessageFieldSet.class,
UpdateOrderFieldSet.class,
UpdatePasswordFieldSet.class,
UpdatePostFieldSet.class,
UpdateProfileFieldSet.class,
UpdateReviewFieldSet.class
UpdateReviewFieldSet.class,
VerificationFieldSet.class
};

for (Class<?> subclass : subclasses) {
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/siftscience/CreateAccountEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.net.HttpURLConnection.HTTP_OK;
Expand Down Expand Up @@ -76,7 +77,8 @@ public void testCreateAccount() throws Exception {
" \"location\" : \"New London, NH\",\n" +
" \"referral_code\" : \"MIKEFRIENDS\",\n" +
" \"email_confirmed_status\" : \"$pending\",\n" +
" \"phone_confirmed_status\" : \"$pending\"\n" +
" \"phone_confirmed_status\" : \"$pending\",\n" +
" \"$account_types\" : [\"merchant\", \"premium\"]\n" +
"}";

// Start a new mock server and enqueue a mock response.
Expand Down Expand Up @@ -124,7 +126,9 @@ public void testCreateAccount() throws Exception {
.setCustomField("location", "New London, NH")
.setCustomField("referral_code", "MIKEFRIENDS")
.setCustomField("email_confirmed_status", "$pending")
.setCustomField("phone_confirmed_status", "$pending"));
.setCustomField("phone_confirmed_status", "$pending")
.setAccountTypes(Arrays.asList("merchant", "premium")));

SiftResponse siftResponse = request.send();

// Verify the request.
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/siftscience/UpdateAccountEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.net.HttpURLConnection.HTTP_OK;
Expand Down Expand Up @@ -57,7 +58,8 @@ public void testUpdateAccount() throws Exception {
" },\n" +
" \"$social_sign_on_type\" : \"$twitter\",\n" +
" \"email_confirmed_status\" : \"$success\",\n" +
" \"phone_confirmed_status\" : \"$success\"\n" +
" \"phone_confirmed_status\" : \"$success\",\n" +
" \"$account_types\" : [\"merchant\", \"premium\"]\n" +
"}";

// Start a new mock server and enqueue a mock response.
Expand Down Expand Up @@ -96,7 +98,8 @@ public void testUpdateAccount() throws Exception {
.setShippingAddress(TestUtils.sampleAddress2())
.setSocialSignOnType("$twitter")
.setCustomField("email_confirmed_status", "$success")
.setCustomField("phone_confirmed_status", "$success"));
.setCustomField("phone_confirmed_status", "$success")
.setAccountTypes(Arrays.asList("merchant", "premium")));

SiftResponse siftResponse = request.send();

Expand Down
88 changes: 88 additions & 0 deletions src/test/java/com/siftscience/UpdatePasswordEventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.siftscience;

import com.siftscience.model.App;
import com.siftscience.model.UpdatePasswordFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;

import static java.net.HttpURLConnection.HTTP_OK;

/**
* Unit tests around the Update_password events.
*/

public class UpdatePasswordEventTest {
@Test
public void testUpdatePassword() throws Exception {
String expectedRequestBody = "{\n" +
" \"$type\" : \"$update_password\",\n" +
" \"$api_key\" : \"your_api_key_here\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$session_id\" : \"gigtleqddo84l8cm15qe4il\",\n" +
" \"$app\" : {\n" +
" \"$os\" : \"iOS\",\n" +
" \"$app_name\" : \"Calculator\",\n" +
" \"$device_manufacturer\" : \"Apple\",\n" +
" \"$device_model\" : \"iPhone 4,2\",\n" +
" \"$device_unique_id\" : \"A3D261E4-DE0A-470B-9E4A-720F3D3D22E6\",\n" +
" \"$app_version\" : \"3.2.7\",\n" +
" },\n" +
" \"$reason\" : \"$forced_reset\",\n" +
" \"$status\" : \"$success\",\n" +
" \"$ip\" : \"128.148.1.135\",\n" +
"}";

MockWebServer server = new MockWebServer();
MockResponse response = new MockResponse();
response.setResponseCode(HTTP_OK);
response.setBody("{\n" +
" \"status\" : 0,\n" +
" \"error_message\" : \"OK\",\n" +
" \"time\" : 1327604222,\n" +
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
"}");
server.enqueue(response);
server.start();
HttpUrl baseUrl = server.url("");

// Create a new client and link it to the mock server.
SiftClient client = new SiftClient("your_api_key_here");
client.setBaseUrl(baseUrl);

// Build and execute the request against the mock server.
UpdatePasswordFieldSet fieldSet = new UpdatePasswordFieldSet()
.setUserId("billy_jones_301")
.setSessionId("gigtleqddo84l8cm15qe4il")
.setReason("$forced_reset")
.setStatus("$success")
.setIp("128.148.1.135")
.setApp(new App()
.setAppName("Calculator")
.setAppVersion("3.2.7")
.setDeviceManufacturer("Apple")
.setDeviceModel("iPhone 4,2")
.setDeviceUniqueId("A3D261E4-DE0A-470B-9E4A-720F3D3D22E6")
.setOperatingSystem("iOS"));

SiftRequest request = client.buildRequest(fieldSet);
SiftResponse siftResponse = request.send();

//Verify the request
RecordedRequest request1 = server.takeRequest();
Assert.assertEquals("POST", request1.getMethod());
Assert.assertEquals("/v205/events", request1.getPath());
JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true);

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

server.shutdown();
}
}
32 changes: 29 additions & 3 deletions src/test/java/com/siftscience/VerificationEventTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.siftscience;

import com.siftscience.model.App;
import com.siftscience.model.VerificationFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
Expand All @@ -17,15 +18,30 @@ public class VerificationEventTest {
public void testVerification() throws Exception {
String sessionId = "gigtleqddo84l8cm15qe4il";
String verifiedValue = "14155551212";
String verifiedEvent = "$create_content";
String verifiedEntityId = "chekle212452";
String reason = "$user_setting";

String expectedRequestBody = "{\n" +
" \"$type\" : \"$verification\",\n" +
" \"$api_key\" : \"your_api_key_here\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$session_id\" : \"" + sessionId + "\",\n" +
" \"$app\" : {\n" +
" \"$os\" : \"iOS\",\n" +
" \"$app_name\" : \"Calculator\",\n" +
" \"$device_manufacturer\" : \"Apple\",\n" +
" \"$device_model\" : \"iPhone 4,2\",\n" +
" \"$device_unique_id\" : \"A3D261E4-DE0A-470B-9E4A-720F3D3D22E6\",\n" +
" \"$app_version\" : \"3.2.7\",\n" +
" },\n" +
" \"$status\" : \"$pending\",\n" +
" \"$verification_type\" : \"$sms\",\n" +
" \"$verified_value\" : \"" + verifiedValue + "\"\n" +
" \"$verified_value\" : \"" + verifiedValue + "\",\n" +
" \"$verified_event\" : \"" + verifiedEvent + "\",\n" +
" \"$verified_entity_id\" : \"" + verifiedEntityId + "\",\n" +
" \"$reason\" : \"" + reason + "\",\n" +
" \"$ip\" : \"128.148.1.135\",\n" +
"}";

// Start a new mock server and enqueue a mock response.
Expand All @@ -52,7 +68,18 @@ public void testVerification() throws Exception {
.setSessionId(sessionId)
.setStatus("$pending")
.setVerificationType("$sms")
.setVerifiedValue(verifiedValue));
.setVerifiedValue(verifiedValue)
.setReason(reason)
.setVerifiedEvent(verifiedEvent)
.setVerifiedEntityId(verifiedEntityId)
.setIp("128.148.1.135")
.setApp(new App()
.setAppName("Calculator")
.setAppVersion("3.2.7")
.setDeviceManufacturer("Apple")
.setDeviceModel("iPhone 4,2")
.setDeviceUniqueId("A3D261E4-DE0A-470B-9E4A-720F3D3D22E6")
.setOperatingSystem("iOS")));

SiftResponse siftResponse = request.send();

Expand All @@ -69,6 +96,5 @@ public void testVerification() throws Exception {
siftResponse.getBody().toJson(), true);

server.shutdown();

}
}

0 comments on commit d5242d0

Please sign in to comment.