From fc837b2866d6aad5a60ac7a238c43b968d4640fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kami=C5=84ski?= Date: Fri, 22 Sep 2023 14:30:27 +0200 Subject: [PATCH] Update documentation (#43) Co-authored-by: Igor Rodzik --- .gitignore | 1 + README.md | 27 +++++++++++++++---- examples/query-for-document/build.gradle.kts | 2 +- .../opa/client/QueryingForDocumentSpec.groovy | 5 ++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index ff733f4..848709a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ +out/ build .gradle /gradle/wrapper/gradle-wrapper.jar diff --git a/README.md b/README.md index 1d8f7a7..9fdb159 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,31 @@ Our library is using Jackson for (de)serialization so, objects that you are pass ### Query for document ```java - OpaQueryApi client = OpaClient.builder() - .opaConfiguration("http://localhost:8181") - .build(); +OpaQueryApi client = OpaClient.builder() + .opaConfiguration("http://localhost:8181") + .build(); - DesiredResponse response = client.queryForDocument(new QueryForDocumentRequest(yourDTO, "path/to/document"), DesiredResponse.class); +DesiredResponse response = client.queryForDocument(new QueryForDocumentRequest(yourDTO, "path/to/document"), DesiredResponse.class); + +// Do whatever you like with the response +``` + +### Query for a list of documents + +This requires [commons-lang3](https://mvnrepository.com/artifact/org.apache.commons/commons-lang3) to be present on your classpath. + +```java +OpaQueryApi client = OpaClient.builder() + .opaConfiguration("http://localhost:8181") + .build(); + +ParameterizedType type = TypeUtils.parameterize(List.class, DesiredResponse.class); - // Do whatever you like with the response +List response = client.queryForDocument(new QueryForDocumentRequest(yourDTO, "path/to/document"), type); + +// Do whatever you like with the response ``` + ####Example Example project is in `examples/query-for-document` directory. ### Create policy diff --git a/examples/query-for-document/build.gradle.kts b/examples/query-for-document/build.gradle.kts index 48ea277..a13d8e8 100644 --- a/examples/query-for-document/build.gradle.kts +++ b/examples/query-for-document/build.gradle.kts @@ -8,7 +8,7 @@ repositories { } dependencies { - implementation("com.bisnode.opa:opa-java-client:0.0.2") + implementation("com.bisnode.opa:opa-java-client:0.3.0") implementation("org.slf4j:slf4j-simple:1.7.30") testImplementation("org.codehaus.groovy:groovy-all:2.5.13") diff --git a/src/test/groovy/com/bisnode/opa/client/QueryingForDocumentSpec.groovy b/src/test/groovy/com/bisnode/opa/client/QueryingForDocumentSpec.groovy index e47bef9..2d35cf0 100644 --- a/src/test/groovy/com/bisnode/opa/client/QueryingForDocumentSpec.groovy +++ b/src/test/groovy/com/bisnode/opa/client/QueryingForDocumentSpec.groovy @@ -141,10 +141,9 @@ class QueryingForDocumentSpec extends Specification { when: def type = TypeUtils.parameterize(List.class,ValidationResult.class); - def result = client.queryForDocument(new QueryForDocumentRequest([shouldPass: true], path), type) + List result = client.queryForDocument(new QueryForDocumentRequest([shouldPass: true], path), type) then: - def element = result[0] - element.getClass() == ValidationResult.class + ValidationResult element = result[0] element.allow }