Skip to content

Commit

Permalink
Update documentation (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Rodzik <[email protected]>
  • Loading branch information
lukasz-kaminski and irodzik authored Sep 22, 2023
1 parent b59e878 commit fc837b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
out/
build
.gradle
/gradle/wrapper/gradle-wrapper.jar
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<DesiredResponse> 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
Expand Down
2 changes: 1 addition & 1 deletion examples/query-for-document/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationResult> result = client.queryForDocument(new QueryForDocumentRequest([shouldPass: true], path), type)
then:
def element = result[0]
element.getClass() == ValidationResult.class
ValidationResult element = result[0]
element.allow
}

Expand Down

0 comments on commit fc837b2

Please sign in to comment.