Skip to content

Commit ce68b74

Browse files
Add generated model classes and new api methods (#117)
* Add generated model classes and new api methods * Add custom type adapters * Fix changeset functionality * update enum names and cleanup imports * Expand tests * update tests * update filter test
1 parent c79bf9b commit ce68b74

34 files changed

Lines changed: 6340 additions & 16 deletions

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@
8686
</profiles>
8787

8888
<dependencies>
89+
<dependency>
90+
<groupId>org.openapitools</groupId>
91+
<artifactId>jackson-databind-nullable</artifactId>
92+
<version>0.2.1</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>javax.annotation</groupId>
96+
<artifactId>javax.annotation-api</artifactId>
97+
<version>1.3.2</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.threeten</groupId>
101+
<artifactId>threetenbp</artifactId>
102+
<version>1.4.3</version>
103+
</dependency>
104+
<dependency>
105+
<groupId>io.swagger</groupId>
106+
<artifactId>swagger-annotations</artifactId>
107+
<version>1.5.24</version>
108+
</dependency>
89109
<dependency>
90110
<groupId>javax.servlet</groupId>
91111
<artifactId>javax.servlet-api</artifactId>

src/main/java/io/castle/client/api/CastleApi.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.ImmutableMap;
44
import com.google.gson.JsonElement;
55
import io.castle.client.model.*;
6+
import io.castle.client.model.generated.*;
67

78
import javax.annotation.Nullable;
89

@@ -289,15 +290,15 @@ public interface CastleApi {
289290

290291
CastleResponse get(String path);
291292

292-
CastleResponse post(String path, ImmutableMap<Object, Object> payload);
293+
CastleResponse post(String path, Object payload);
293294

294295
CastleResponse put(String path);
295296

296-
CastleResponse put(String path, ImmutableMap<Object, Object> payload);
297+
CastleResponse put(String path, Object payload);
297298

298299
CastleResponse delete(String path);
299300

300-
CastleResponse delete(String path, ImmutableMap<Object, Object> payload);
301+
CastleResponse delete(String path, Object payload);
301302

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

311+
/**
312+
* Makes a sync POST request to the risk endpoint.
313+
*
314+
* @param payload Event parameters
315+
* @return
316+
*/
317+
RiskResponse risk(Risk payload);
318+
310319
/**
311320
* Makes a sync POST request to the filter endpoint.
312321
*
@@ -315,6 +324,14 @@ public interface CastleApi {
315324
*/
316325
CastleResponse filter(ImmutableMap<Object, Object> payload);
317326

327+
/**
328+
* Makes a sync POST request to the filter endpoint.
329+
*
330+
* @param payload Event parameters
331+
* @return
332+
*/
333+
FilterResponse filter(Filter payload);
334+
318335
/**
319336
* Makes a sync POST request to the log endpoint.
320337
*
@@ -323,6 +340,14 @@ public interface CastleApi {
323340
*/
324341
CastleResponse log(ImmutableMap<Object, Object> payload);
325342

343+
/**
344+
* Makes a sync POST request to the log endpoint.
345+
*
346+
* @param payload Event parameters
347+
* @return
348+
*/
349+
CastleResponse log(Log payload);
350+
326351
/**
327352
* Makes a sync PUT request to the recover endpoint.
328353
*

src/main/java/io/castle/client/internal/CastleApiImpl.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.castle.client.internal.utils.Timestamp;
1414
import io.castle.client.internal.utils.VerdictBuilder;
1515
import io.castle.client.model.*;
16+
import io.castle.client.model.generated.*;
1617

1718
import javax.annotation.Nullable;
1819
import javax.servlet.http.HttpServletRequest;
@@ -285,7 +286,7 @@ public CastleResponse get(String path) {
285286
}
286287

287288
@Override
288-
public CastleResponse post(String path, ImmutableMap<Object, Object> payload) {
289+
public CastleResponse post(String path, Object payload) {
289290
RestApi restApi = configuration.getRestApiFactory().buildBackend();
290291
return restApi.post(path, payload);
291292
}
@@ -297,7 +298,7 @@ public CastleResponse put(String path) {
297298
}
298299

299300
@Override
300-
public CastleResponse put(String path, ImmutableMap<Object, Object> payload) {
301+
public CastleResponse put(String path, Object payload) {
301302
RestApi restApi = configuration.getRestApiFactory().buildBackend();
302303
return restApi.put(path, payload);
303304
}
@@ -309,7 +310,7 @@ public CastleResponse delete(String path) {
309310
}
310311

311312
@Override
312-
public CastleResponse delete(String path, ImmutableMap<Object, Object> payload) {
313+
public CastleResponse delete(String path, Object payload) {
313314
RestApi restApi = configuration.getRestApiFactory().buildBackend();
314315
return restApi.delete(path, payload);
315316
}
@@ -320,20 +321,43 @@ public CastleResponse risk(ImmutableMap<Object, Object> payload) {
320321
return restApi.post(Castle.URL_RISK, payload);
321322
}
322323

324+
@Override
325+
public RiskResponse risk(Risk payload) {
326+
Preconditions.checkNotNull(payload);
327+
RestApi restApi = configuration.getRestApiFactory().buildBackend();
328+
CastleResponse castleResponse = restApi.post(Castle.URL_RISK, payload);
329+
return configuration.getModel().getGson().fromJson(castleResponse.json(), RiskResponse.class);
330+
}
331+
323332
@Override
324333
public CastleResponse filter(ImmutableMap<Object, Object> payload) {
325334
Preconditions.checkNotNull(payload);
326335
RestApi restApi = configuration.getRestApiFactory().buildBackend();
327336
return restApi.post(Castle.URL_FILTER, payload);
328337
}
329338

339+
@Override
340+
public FilterResponse filter(Filter payload) {
341+
Preconditions.checkNotNull(payload);
342+
RestApi restApi = configuration.getRestApiFactory().buildBackend();
343+
CastleResponse castleResponse = restApi.post(Castle.URL_FILTER, payload);
344+
return configuration.getModel().getGson().fromJson(castleResponse.json(), FilterResponse.class);
345+
}
346+
330347
@Override
331348
public CastleResponse log(ImmutableMap<Object, Object> payload) {
332349
Preconditions.checkNotNull(payload);
333350
RestApi restApi = configuration.getRestApiFactory().buildBackend();
334351
return restApi.post(Castle.URL_LOG, payload);
335352
}
336353

354+
@Override
355+
public CastleResponse log(Log payload) {
356+
Preconditions.checkNotNull(payload);
357+
RestApi restApi = configuration.getRestApiFactory().buildBackend();
358+
return restApi.post(Castle.URL_LOG, payload);
359+
}
360+
337361
@Override
338362
public CastleResponse recover(String userId) {
339363
Preconditions.checkNotNull(userId, "UserId can not be null");

src/main/java/io/castle/client/internal/backend/OkRestApiBackend.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public CastleResponse put(String path) {
254254
}
255255

256256
@Override
257-
public CastleResponse put(String path, ImmutableMap<Object, Object> payload) {
257+
public CastleResponse put(String path, Object payload) {
258258
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_PUT);
259259
}
260260

@@ -264,12 +264,12 @@ public CastleResponse delete(String path) {
264264
}
265265

266266
@Override
267-
public CastleResponse delete(String path, ImmutableMap<Object, Object> payload) {
267+
public CastleResponse delete(String path, Object payload) {
268268
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_DELETE);
269269
}
270270

271271
@Override
272-
public CastleResponse post(String path, ImmutableMap<Object, Object> payload) {
272+
public CastleResponse post(String path, Object payload) {
273273
return makeRequest(path, model.getGson().toJsonTree(payload), METHOD_POST);
274274
}
275275

src/main/java/io/castle/client/internal/backend/RestApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public interface RestApi {
103103
* @param payload request payload
104104
* @return a decoded json response
105105
*/
106-
CastleResponse post(String path, ImmutableMap<Object, Object> payload);
106+
CastleResponse post(String path, Object payload);
107107

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

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

0 commit comments

Comments
 (0)