diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6f2407..f910db9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,22 @@ modify the contents of the `arcade-java/lib/` and `arcade-java-examples/` direct ## Adding and running examples -TODO +Set the following environment variables: + +| ENV Var | Description | +|-------------------|-------------------------------------------------------------------------| +| `ARCADE_USER_ID` | Arcade user Id or email address | +| `ARCADE_API_KEY` | [Arcade API key](https://docs.arcade.dev/en/get-started/setup/api-keys) | +| `ARCADE_BASE_URL` | Arcade URL, defaults to: `https://api.arcade.dev` | + +Use `./gradlew :arcade-java-example:run -Pexample=` to run `Example` + +For example, if you have the `potify.ResumePlayback` tool configured, you can run: +```shell +export ARCADE_API_KEY='your-api-key' +export ARCADE_USER_ID='your-arcade-user' +./gradlew :arcade-java-example:run -Pexample=PlaySpotify +``` ## Building the repository from source diff --git a/arcade-java-example/src/main/java/dev/arcade/example/PlaySpotifyExample.java b/arcade-java-example/src/main/java/dev/arcade/example/PlaySpotifyExample.java new file mode 100644 index 0000000..1568965 --- /dev/null +++ b/arcade-java-example/src/main/java/dev/arcade/example/PlaySpotifyExample.java @@ -0,0 +1,43 @@ +package dev.arcade.example; + +import dev.arcade.client.ArcadeClient; +import dev.arcade.client.okhttp.ArcadeOkHttpClient; +import dev.arcade.models.tools.ExecuteToolRequest; +import dev.arcade.models.tools.ExecuteToolResponse; +import dev.arcade.models.tools.ToolExecuteParams; + +/** + * Example of calling a tool using the Arcade Java SDK. + */ +public class PlaySpotifyExample { + + /** + * Executes the Spotify.ResumePlayback, both the ARCADE_USER_ID and ARCADE_API_KEY environment variables must be set. + * See the Getting Your API Key guide to create an API Key. + * Your username can be found in the lower left corner of your Arcade console. + * @param args Not used. + */ + public static void main(String[] args) { + + String userId = System.getenv("ARCADE_USER_ID"); // the Spotify tool requires a userId + if (userId == null) { + throw new IllegalArgumentException("ARCADE_USER_ID and ARCADE_API_KEY environment variables must be set"); + } + + // Configures using the `ARCADE_API_KEY` environment variable + ArcadeClient client = ArcadeOkHttpClient.fromEnv(); + + ToolExecuteParams params = ToolExecuteParams.builder() + .executeToolRequest(ExecuteToolRequest.builder() + .toolName("Spotify.ResumePlayback@1.0.2") + .userId(userId) + .build()) + .build(); + ExecuteToolResponse executeToolResponse = client.tools().execute(params); + executeToolResponse + .output() + .ifPresentOrElse( + output -> System.out.println("Tool output: " + output._value()), + () -> System.out.println("No output for this tool")); + } +}