Skip to content

Commit 4d967f0

Browse files
authored
Merge pull request #3 from arago/development
Development
2 parents d28763f + 254aa65 commit 4d967f0

39 files changed

Lines changed: 522 additions & 315 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.2.0
2+
3+
* Add method to decode HIRO token data.
4+
* Documentation, fixes and refactorings.
5+
16
# v0.1.2
27

38
Make API classes extendable

README.md

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ implemented are `app`, `auth`, `graph`, `event-ws` and `action-ws` )
1717

1818
You need at least Java 11.
1919

20-
https://github.com/arago/java-project and the respective packages under https://github.com/orgs/arago/packages or
21-
the Maven Central Library.
20+
https://github.com/arago/java-project and the respective packages under https://github.com/orgs/arago/packages or the
21+
Maven Central Library.
2222

2323
## Quickstart
2424

@@ -299,6 +299,7 @@ import co.arago.hiro.client.rest.AuthAPI;
299299
import co.arago.hiro.client.websocket.EventWebSocket;
300300
import co.arago.hiro.client.websocket.listener.EventWebSocketListener;
301301
import co.arago.util.json.JsonUtil;
302+
import co.arago.hiro.client.model.token.DecodedToken;
302303

303304
import java.io.IOException;
304305
import java.nio.file.Paths;
@@ -313,13 +314,70 @@ class Example {
313314
.build()
314315
) {
315316

317+
try (EventWebSocket eventWebSocket = EventWebSocket.newBuilder(
318+
handler,
319+
new EventWebSocketListener() {
320+
@Override
321+
public void onCreate(EventsMessage eventsMessage) {
322+
// React when a vertex has been created
323+
}
324+
325+
@Override
326+
public void onUpdate(EventsMessage eventsMessage) {
327+
// React when a vertex has been updated
328+
}
329+
330+
@Override
331+
public void onDelete(EventsMessage eventsMessage) {
332+
// React when a vertex has been deleted
333+
}
334+
})
335+
.addEventsFilter(
336+
"default",
337+
"(element.ogit/_type = ogit/Automation/AutomationIssue)"
338+
)
339+
.build()
340+
) {
341+
342+
eventWebSocket.start();
343+
344+
// Listen for 1 second for incoming events.
345+
Thread.sleep(1000);
346+
}
347+
}
348+
}
349+
}
350+
```
351+
352+
If you do not set a scope via `.addScope(...)`, the default scope of your account will be used unless
353+
`setAllScopes(true)` is used. If you need to set a scope by hand, you can use the following:
354+
355+
```java
356+
import co.arago.hiro.client.Config;
357+
import co.arago.hiro.client.connection.token.PasswordAuthTokenAPIHandler;
358+
import co.arago.hiro.client.exceptions.HiroException;
359+
import co.arago.hiro.client.model.websocket.events.impl.EventsMessage;
360+
import co.arago.hiro.client.rest.AuthAPI;
361+
import co.arago.hiro.client.websocket.EventWebSocket;
362+
import co.arago.hiro.client.websocket.listener.EventWebSocketListener;
363+
import co.arago.util.json.JsonUtil;
364+
import co.arago.hiro.client.model.token.DecodedToken;
365+
366+
import java.io.IOException;
367+
import java.nio.file.Paths;
368+
369+
class Example {
370+
public static void main(String[] args) throws HiroException, IOException, InterruptedException {
371+
372+
// Build an API handler which takes care of API paths via /api/versions and security tokens.
373+
try (PasswordAuthTokenAPIHandler handler = PasswordAuthTokenAPIHandler.newBuilder()
374+
.setApiUrl(API_URL)
375+
.setCredentials(USERNAME, PASSWORD, CLIENT_ID, CLIENT_SECRET)
376+
.build()
377+
) {
316378

317-
// Obtain my default scope. THIS WILL MOST LIKELY CHANGE IN THE FUTURE.
318-
AuthAPI authAPI = AuthAPI.newBuilder(handler).build();
319-
String defaultScope = authAPI
320-
.getMeProfileCommand()
321-
.execute()
322-
.getAttributeAsString("ogit/Auth/Account/defaultScope");
379+
// Obtain information from decoded token
380+
DecodedToken decodedToken = handler.decodeToken();
323381

324382
try (EventWebSocket eventWebSocket = EventWebSocket.newBuilder(
325383
handler,
@@ -339,7 +397,8 @@ class Example {
339397
// React when a vertex has been deleted
340398
}
341399
})
342-
.addScope(defaultScope)
400+
// Set defaultScope by hand
401+
.addScope(decodedToken.data.defaultScope)
343402
.addEventsFilter(
344403
"default",
345404
"(element.ogit/_type = ogit/Automation/AutomationIssue)"

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.2
1+
0.2.0

0 commit comments

Comments
 (0)