-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from SiftScience/atpaino_verification_app_browser
(For Arjun) Add support for verification event, app and browser complex fields
- Loading branch information
Showing
9 changed files
with
316 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.siftscience.model; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class App { | ||
@Expose @SerializedName("$os") private String operatingSystem; | ||
@Expose @SerializedName("$os_version") private String operatingSystemVersion; | ||
@Expose @SerializedName("$device_manufacturer") private String deviceManufacturer; | ||
@Expose @SerializedName("$device_model") private String deviceModel; | ||
@Expose @SerializedName("$device_unique_id") private String deviceUniqueId; | ||
@Expose @SerializedName("$app_name") private String appName; | ||
@Expose @SerializedName("$app_version") private String appVersion; | ||
|
||
public String getOperatingSystem() { | ||
return operatingSystem; | ||
} | ||
|
||
public App setOperatingSystem(String operatingSystem) { | ||
this.operatingSystem = operatingSystem; | ||
return this; | ||
} | ||
|
||
public String getOperatingSystemVersion() { | ||
return operatingSystemVersion; | ||
} | ||
|
||
public App setOperatingSystemVersion(String operatingSystemVersion) { | ||
this.operatingSystemVersion = operatingSystemVersion; | ||
return this; | ||
} | ||
|
||
public String getDeviceManufacturer() { | ||
return deviceManufacturer; | ||
} | ||
|
||
public App setDeviceManufacturer(String deviceManufacturer) { | ||
this.deviceManufacturer = deviceManufacturer; | ||
return this; | ||
} | ||
|
||
public String getDeviceModel() { | ||
return deviceModel; | ||
} | ||
|
||
public App setDeviceModel(String deviceModel) { | ||
this.deviceModel = deviceModel; | ||
return this; | ||
} | ||
|
||
public String getDeviceUniqueId() { | ||
return deviceUniqueId; | ||
} | ||
|
||
public App setDeviceUniqueId(String deviceUniqueId) { | ||
this.deviceUniqueId = deviceUniqueId; | ||
return this; | ||
} | ||
|
||
public String getAppName() { | ||
return appName; | ||
} | ||
|
||
public App setAppName(String appName) { | ||
this.appName = appName; | ||
return this; | ||
} | ||
|
||
public String getAppVersion() { | ||
return appVersion; | ||
} | ||
|
||
public App setAppVersion(String appVersion) { | ||
this.appVersion = appVersion; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.siftscience.model; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class Browser { | ||
@Expose @SerializedName("$user_agent") private String userAgent; | ||
|
||
public String getUserAgent() { | ||
return userAgent; | ||
} | ||
|
||
public Browser setUserAgent(String userAgent) { | ||
this.userAgent = userAgent; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/siftscience/model/VerificationFieldSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.siftscience.model; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class VerificationFieldSet extends EventsApiRequestFieldSet<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; | ||
|
||
@Override | ||
public String getEventType() { | ||
return "$verification"; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public VerificationFieldSet setStatus(String status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public String getVerificationType() { | ||
return verificationType; | ||
} | ||
|
||
public VerificationFieldSet setVerificationType(String verificationType) { | ||
this.verificationType = verificationType; | ||
return this; | ||
} | ||
|
||
public String getVerifiedValue() { | ||
return verifiedValue; | ||
} | ||
|
||
public VerificationFieldSet setVerifiedValue(String verifiedValue) { | ||
this.verifiedValue = verifiedValue; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.siftscience; | ||
|
||
import com.siftscience.model.VerificationFieldSet; | ||
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; | ||
|
||
public class VerificationEventTest { | ||
|
||
@Test | ||
public void testVerification() throws Exception { | ||
String sessionId = "gigtleqddo84l8cm15qe4il"; | ||
String verifiedValue = "14155551212"; | ||
|
||
String expectedRequestBody = "{\n" + | ||
" \"$type\" : \"$verification\",\n" + | ||
" \"$api_key\" : \"your_api_key_here\",\n" + | ||
" \"$user_id\" : \"billy_jones_301\",\n" + | ||
" \"$session_id\" : \"" + sessionId + "\",\n" + | ||
" \"$status\" : \"$pending\",\n" + | ||
" \"$verification_type\" : \"$sms\",\n" + | ||
" \"$verified_value\" : \"" + verifiedValue + "\"\n" + | ||
"}"; | ||
|
||
// Start a new mock server and enqueue a mock response. | ||
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. | ||
SiftRequest request = client.buildRequest(new VerificationFieldSet() | ||
.setUserId("billy_jones_301") | ||
.setSessionId(sessionId) | ||
.setStatus("$pending") | ||
.setVerificationType("$sms") | ||
.setVerifiedValue(verifiedValue)); | ||
|
||
SiftResponse siftResponse = request.send(); | ||
|
||
// Verify the request. | ||
RecordedRequest request1 = server.takeRequest(); | ||
Assert.assertEquals("POST", request1.getMethod()); | ||
Assert.assertEquals("/v204/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(); | ||
|
||
} | ||
} |