@@ -17,8 +17,8 @@ implemented are `app`, `auth`, `graph`, `event-ws` and `action-ws` )
1717
1818You 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;
299299import co.arago.hiro.client.websocket.EventWebSocket ;
300300import co.arago.hiro.client.websocket.listener.EventWebSocketListener ;
301301import co.arago.util.json.JsonUtil ;
302+ import co.arago.hiro.client.model.token.DecodedToken ;
302303
303304import java.io.IOException ;
304305import 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)"
0 commit comments