Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/main/java/io/castle/client/Castle.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public class Castle {

public static final String URL_RECOVER = "/v1/users/%s/recover";

public static final String URL_LISTS = "/v1/lists";
public static final String URL_LISTS_ID = "/v1/lists/%s";
public static final String URL_LISTS_SEARCH = "/v1/lists/query";

public static final String URL_LISTS_ITEMS = "/v1/lists/%s/items";
public static final String URL_LISTS_ITEMS_BATCH = "/v1/lists/%s/items/batch";
public static final String URL_LISTS_ITEMS_SEARCH = "/v1/lists/%s/items/query";
public static final String URL_LISTS_ITEMS_COUNT = "/v1/lists/%s/items/count";
public static final String URL_LISTS_ITEMS_UPDATE = "/v1/lists/%s/items/%s";
public static final String URL_LISTS_ITEMS_GET = "/v1/lists/%s/items/%s";
public static final String URL_LISTS_ITEMS_ARCHIVE = "/v1/lists/%s/items/%s/archive";
public static final String URL_LISTS_ITEMS_UNARCHIVE = "/v1/lists/%s/items/%s/unarchive";

public static final String KEY_EVENT = "event";
public static final String KEY_USER = "user";
public static final String KEY_STATUS = "status";
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/io/castle/client/api/CastleApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.castle.client.model.generated.*;

import javax.annotation.Nullable;
import java.util.List;

/**
* Contains methods for calling the Castle API and the settings needed to properly make such a request.
Expand Down Expand Up @@ -316,6 +317,109 @@ public interface CastleApi {
*/
FilterAndRiskResponse risk(Risk payload);

/**
* Makes a sync POST request to the list endpoint.
*
* @param payload Event parameters
* @return
*/
ListResponse createList(ListRequest payload);

/**
* Makes a sync GET request to the list endpoint.
* @return
*/
List<ListResponse> listAllLists();

/**
* Makes a sync GET request to the list endpoint.
*
* @param listId List ID
* @return
*/
ListResponse list(String listId);

/**
* Makes a sync PUT request to the list endpoint.
*
* @param listId List ID
* @param payload Event parameters
* @return
*/
ListResponse updateList(String listId, ListRequest payload);

/**
* Makes a sync DELETE request to the list endpoint.
*
* @param listId List ID
* @return
*/
CastleResponse deleteList(String listId);

/**
* Makes a sync POST request to the list endpoint.
*
* @param payload Search parameters
* @return
*/
List<ListResponse> searchLists(ListQuery payload);

/**
* Makes a sync POST request to the list item endpoint.
*
* @param listId List ID
* @param payload Event parameters
* @return
*/
ListItem createListItem(String listId, ListItemRequest payload);

/**
* Makes a sync POST request to the list item endpoint.
*
* @param id List ID
* @param payload Event parameters
* @return
*/
ListItemsBatchResponse createOrUpdateListItems(String id, ListItemsBatchRequest payload);

/**
* Makes a sync GET request to the list item endpoint.
*
* @return
*/
List<ListItem> searchListItems(String listId, ListItemQuery payload);

/**
* Makes a sync GET request to the list item endpoint.
*
* @param listId List ID
* @param payload Event parameters
* @return
*/
ListItemListCount countListItems(String listId, ListItemQuery payload);

/**
* Makes a sync GET request to the list item endpoint.
*
* @param listId List ID
* @param itemid Item ID
* @return
*/
ListItem updateListItem(String listId, String itemid, ListItemRequest payload);

/**
* Makes a sync GET request to the list item endpoint.
*
* @param listId List ID
* @param itemid Item ID
* @return
*/
ListItem getListItem(String listId, String itemid);

CastleResponse archiveListItem(String listId, String itemid);

CastleResponse unarchiveListItem(String listId, String itemid);

/**
* Makes a sync POST request to the filter endpoint.
*
Expand Down
129 changes: 125 additions & 4 deletions src/main/java/io/castle/client/internal/CastleApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import io.castle.client.Castle;
import io.castle.client.api.CastleApi;
import io.castle.client.internal.backend.RestApi;
Expand All @@ -13,13 +14,12 @@
import io.castle.client.internal.utils.Timestamp;
import io.castle.client.internal.utils.VerdictBuilder;
import io.castle.client.model.*;
import io.castle.client.model.generated.Filter;
import io.castle.client.model.generated.FilterAndRiskResponse;
import io.castle.client.model.generated.Log;
import io.castle.client.model.generated.Risk;
import io.castle.client.model.generated.*;
import jakarta.servlet.http.HttpServletRequest;

import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.List;

public class CastleApiImpl implements CastleApi {

Expand Down Expand Up @@ -332,6 +332,127 @@ public FilterAndRiskResponse risk(Risk payload) {
return configuration.getModel().getGson().fromJson(castleResponse.json(), FilterAndRiskResponse.class);
}

@Override
public ListResponse createList(ListRequest payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(Castle.URL_LISTS, payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListResponse.class);
}

@Override
public CastleResponse deleteList(String id) {
Preconditions.checkNotNull(id);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.delete(String.format(Castle.URL_LISTS_ID, id));
}

@Override
public List<ListResponse> searchLists(ListQuery payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(Castle.URL_LISTS_SEARCH, payload);
Type listType = new TypeToken<List<ListResponse>>(){}.getType();
return configuration.getModel().getGson().fromJson(castleResponse.json(), listType);
}

@Override
public List<ListResponse> listAllLists() {
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.get(Castle.URL_LISTS);
Type listType = new TypeToken<List<ListResponse>>(){}.getType();
return configuration.getModel().getGson().fromJson(castleResponse.json(), listType);
}

@Override
public ListResponse updateList(String id, ListRequest payload) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.put(String.format(Castle.URL_LISTS_ID, id), payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListResponse.class);
}

@Override
public ListResponse list(String id) {
Preconditions.checkNotNull(id);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.get(String.format(Castle.URL_LISTS_ID, id));
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListResponse.class);
}

@Override
public ListItem createListItem(String id, ListItemRequest payload) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(String.format(Castle.URL_LISTS_ITEMS, id), payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListItem.class);
}

@Override
public ListItemsBatchResponse createOrUpdateListItems(String id, ListItemsBatchRequest payload) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(String.format(Castle.URL_LISTS_ITEMS_BATCH, id), payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListItemsBatchResponse.class);
}

@Override
public List<ListItem> searchListItems(String id, ListItemQuery payload) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(String.format(Castle.URL_LISTS_ITEMS_SEARCH, id), payload);
Type listType = new TypeToken<List<ListItem>>(){}.getType();
return configuration.getModel().getGson().fromJson(castleResponse.json(), listType);
}

@Override
public ListItemListCount countListItems(String id, ListItemQuery payload) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(String.format(Castle.URL_LISTS_ITEMS_COUNT, id), payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListItemListCount.class);
}

@Override
public ListItem updateListItem(String listId, String itemId, ListItemRequest payload) {
Preconditions.checkNotNull(listId);
Preconditions.checkNotNull(itemId);
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(String.format(Castle.URL_LISTS_ITEMS_UPDATE, listId, itemId), payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListItem.class);
}

@Override
public ListItem getListItem(String listId, String itemId) {
Preconditions.checkNotNull(listId);
Preconditions.checkNotNull(itemId);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.get(String.format(Castle.URL_LISTS_ITEMS_GET, listId, itemId));
return configuration.getModel().getGson().fromJson(castleResponse.json(), ListItem.class);
}

@Override
public CastleResponse archiveListItem(String listId, String itemId) {
Preconditions.checkNotNull(listId);
Preconditions.checkNotNull(itemId);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.delete(String.format(Castle.URL_LISTS_ITEMS_ARCHIVE, listId, itemId));
}

@Override
public CastleResponse unarchiveListItem(String listId, String itemId) {
Preconditions.checkNotNull(listId);
Preconditions.checkNotNull(itemId);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.put(String.format(Castle.URL_LISTS_ITEMS_UNARCHIVE, listId, itemId));
}

@Override
public CastleResponse filter(ImmutableMap<Object, Object> payload) {
Preconditions.checkNotNull(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ public int hashCode() {
return Objects.hash(line1, line2, city, countryCode, regionCode, postalCode, fingerprint);
}


@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/io/castle/client/model/generated/AuthorType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Castle API
* ## Introduction **Just getting started? Check out our [quick start guide](https://docs.castle.io/docs/quickstart)** Castle APIs uses standard HTTP response codes, authentication and verbs. JSON is used as data exchange format, both for parsing incoming request bodies, and in the returned response. This means that the `Content-Type` header should to be set to `application/json` in requests with a body, such as `POST` or `PUT`. All API requests must be made over [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure). Non-HTTPS calls will fail and the **TLS version needs to be 1.1 or higher**. ## Supported types For a list of supported types, see our [Types Reference](https://docs.castle.io/docs/events). ## Rate limits Our APIs implement rate-limiting based on the number of requests made to them. Each request will return the following headers: - `X-RateLimit-Limit` - The maximum number of requests you're permitted to make in the current time window. - `X-RateLimit-Remaining` - The number of requests remaining in the current time window. - `X-RateLimit-Reset` - The remaining time in seconds until the current time window resets. Additionally, Our Risk, Filter (and the legacy Authenticate) APIs have a per-user-id rate limit of 6 requests per second and 10 requests per 5 seconds.
*
* OpenAPI spec version: 1
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/

package io.castle.client.model.generated;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

/**
* Gets or Sets AuthorType
*/
@JsonAdapter(AuthorType.Adapter.class)
public enum AuthorType {
@SerializedName("$analyst_email")
ANALYST_EMAIL("$analyst_email"),
@SerializedName("$castle_dashboard_user")
CASTLE_DASHBOARD_USER("$castle_dashboard_user"),
@SerializedName("$castle_policy")
CASTLE_POLICY("$castle_policy"),
@SerializedName("$user")
USER("$user"),
@SerializedName("$user_email")
USER_EMAIL("$user_email"),
@SerializedName("$other")
OTHER("$other");

private String value;

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

public String getValue() {
return value;
}

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

public static AuthorType fromValue(String input) {
for (AuthorType b : AuthorType.values()) {
if (b.value.equals(input)) {
return b;
}
}
return null;
}

public static class Adapter extends TypeAdapter<AuthorType> {
@Override
public void write(final JsonWriter jsonWriter, final AuthorType enumeration) throws IOException {
jsonWriter.value(String.valueOf(enumeration.getValue()));
}

@Override
public AuthorType read(final JsonReader jsonReader) throws IOException {
Object value = jsonReader.nextString();
return AuthorType.fromValue((String)(value));
}
}
}
Loading