Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<Name>` to run `<Name>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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <code>ARCADE_USER_ID</code> and <code>ARCADE_API_KEY</code> environment variables must be set.
* See the <a href="https://docs.arcade.dev/en/get-started/setup/api-keys">Getting Your API Key</a> guide to create an API Key.
* Your username can be found in the lower left corner of your <a href="https://app.arcade.dev/home">Arcade console</a>.
* @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"));
}
}