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
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@
</profiles>

<dependencies>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.24</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/io/castle/client/api/CastleApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import io.castle.client.model.*;
import io.castle.client.model.generated.*;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -289,15 +290,15 @@ public interface CastleApi {

CastleResponse get(String path);

CastleResponse post(String path, ImmutableMap<Object, Object> payload);
CastleResponse post(String path, Object payload);

CastleResponse put(String path);

CastleResponse put(String path, ImmutableMap<Object, Object> payload);
CastleResponse put(String path, Object payload);

CastleResponse delete(String path);

CastleResponse delete(String path, ImmutableMap<Object, Object> payload);
CastleResponse delete(String path, Object payload);

/**
* Makes a sync POST request to the risk endpoint.
Expand All @@ -307,6 +308,14 @@ public interface CastleApi {
*/
CastleResponse risk(ImmutableMap<Object, Object> payload);

/**
* Makes a sync POST request to the risk endpoint.
*
* @param payload Event parameters
* @return
*/
RiskResponse risk(Risk payload);

/**
* Makes a sync POST request to the filter endpoint.
*
Expand All @@ -315,6 +324,14 @@ public interface CastleApi {
*/
CastleResponse filter(ImmutableMap<Object, Object> payload);

/**
* Makes a sync POST request to the filter endpoint.
*
* @param payload Event parameters
* @return
*/
FilterResponse filter(Filter payload);

/**
* Makes a sync POST request to the log endpoint.
*
Expand All @@ -323,6 +340,14 @@ public interface CastleApi {
*/
CastleResponse log(ImmutableMap<Object, Object> payload);

/**
* Makes a sync POST request to the log endpoint.
*
* @param payload Event parameters
* @return
*/
CastleResponse log(Log payload);

/**
* Makes a sync PUT request to the recover endpoint.
*
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/io/castle/client/internal/CastleApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.*;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -285,7 +286,7 @@ public CastleResponse get(String path) {
}

@Override
public CastleResponse post(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse post(String path, Object payload) {
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.post(path, payload);
}
Expand All @@ -297,7 +298,7 @@ public CastleResponse put(String path) {
}

@Override
public CastleResponse put(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse put(String path, Object payload) {
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.put(path, payload);
}
Expand All @@ -309,7 +310,7 @@ public CastleResponse delete(String path) {
}

@Override
public CastleResponse delete(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse delete(String path, Object payload) {
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.delete(path, payload);
}
Expand All @@ -320,20 +321,43 @@ public CastleResponse risk(ImmutableMap<Object, Object> payload) {
return restApi.post(Castle.URL_RISK, payload);
}

@Override
public RiskResponse risk(Risk payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(Castle.URL_RISK, payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), RiskResponse.class);
}

@Override
public CastleResponse filter(ImmutableMap<Object, Object> payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.post(Castle.URL_FILTER, payload);
}

@Override
public FilterResponse filter(Filter payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
CastleResponse castleResponse = restApi.post(Castle.URL_FILTER, payload);
return configuration.getModel().getGson().fromJson(castleResponse.json(), FilterResponse.class);
}

@Override
public CastleResponse log(ImmutableMap<Object, Object> payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.post(Castle.URL_LOG, payload);
}

@Override
public CastleResponse log(Log payload) {
Preconditions.checkNotNull(payload);
RestApi restApi = configuration.getRestApiFactory().buildBackend();
return restApi.post(Castle.URL_LOG, payload);
}

@Override
public CastleResponse recover(String userId) {
Preconditions.checkNotNull(userId, "UserId can not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public CastleResponse put(String path) {
}

@Override
public CastleResponse put(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse put(String path, Object payload) {
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_PUT);
}

Expand All @@ -264,12 +264,12 @@ public CastleResponse delete(String path) {
}

@Override
public CastleResponse delete(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse delete(String path, Object payload) {
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_DELETE);
}

@Override
public CastleResponse post(String path, ImmutableMap<Object, Object> payload) {
public CastleResponse post(String path, Object payload) {
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_POST);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/castle/client/internal/backend/RestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface RestApi {
* @param payload request payload
* @return a decoded json response
*/
CastleResponse post(String path, ImmutableMap<Object, Object> payload);
CastleResponse post(String path, Object payload);

/**
* Make a PUT request to a Castle API endpoint such as /v1/devices/{deviceToken}/report
Expand All @@ -120,7 +120,7 @@ public interface RestApi {
* @param payload request payload
* @return a decoded json response
*/
CastleResponse put(String path, ImmutableMap<Object, Object> payload);
CastleResponse put(String path, Object payload);

/**
* Make a DELETE request to a Castle API endpoint such as /v1/impersonate
Expand All @@ -137,5 +137,5 @@ public interface RestApi {
* @param payload request payload
* @return a decoded json response
*/
CastleResponse delete(String path, ImmutableMap<Object, Object> payload);
CastleResponse delete(String path, Object payload);
}
Loading