![JAR search and dependency download from the Maven repository](/logo.png)
com.siftscience.EventRequest Maven / Gradle / Ivy
The newest version!
package com.siftscience;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Response;
/**
* EventRequest is the request type for the Sift Events API.
* Events API
*/
public class EventRequest extends SiftRequest {
// The abuse types to return synchronous scores for.
private List abuseTypes;
private boolean isWorkflowStatus = false;
private boolean forceWorkflowRun = false;
private boolean isReturnRouteInfo = false;
private boolean returnScorePercentiles = false;
private boolean returnWarnings = false;
EventRequest(HttpUrl baseUrl, String accountId, HttpClient client, FieldSet fields) {
super(baseUrl, accountId, client, fields);
abuseTypes = null;
}
@Override
EventResponse buildResponse(Response response, FieldSet requestFields)
throws IOException {
return new EventResponse(response, requestFields);
}
@Override
protected HttpUrl path(HttpUrl baseUrl) {
HttpUrl.Builder builder = baseUrl.newBuilder()
.addPathSegment("v205").addPathSegment("events");
if (isWorkflowStatus) {
builder.addQueryParameter("return_workflow_status", "true");
} else if (abuseTypes != null) {
builder.addQueryParameter("return_score", "true");
}
if (isReturnRouteInfo) {
builder.addQueryParameter("return_route_info", "true");
}
if (forceWorkflowRun) {
builder.addQueryParameter("force_workflow_run", "true");
}
List fields = new ArrayList<>();
if (returnScorePercentiles) {
fields.add("score_percentiles");
}
if (returnWarnings) {
fields.add("warnings");
}
if (!fields.isEmpty()) {
builder.addQueryParameter("fields", StringUtils.joinWithComma(fields));
}
// returnScore and abuseTypes are encoded into the URL as query params rather than JSON.
if (abuseTypes != null && !abuseTypes.isEmpty()) {
builder.addQueryParameter("abuse_types", StringUtils.joinWithComma(abuseTypes));
}
return builder.build();
}
public EventRequest withScores(String... abuseTypes) {
this.abuseTypes = Arrays.asList(abuseTypes);
return this;
}
public EventRequest withWorkflowStatus() {
this.isWorkflowStatus = true;
return this;
}
public EventRequest withForceWorkflowRun() {
this.forceWorkflowRun = true;
return this;
}
public EventRequest withRouteInfo() {
this.isReturnRouteInfo = true;
return this;
}
public EventRequest withScorePercentiles() {
this.returnScorePercentiles = true;
return this;
}
public EventRequest withWarnings() {
this.returnWarnings = true;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy