-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaySpotify.java
More file actions
41 lines (35 loc) · 1.45 KB
/
PlaySpotify.java
File metadata and controls
41 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dev.arcade.example.simple;
import dev.arcade.client.ArcadeClient;
import dev.arcade.client.okhttp.ArcadeOkHttpClient;
import dev.arcade.models.ExecuteToolRequest;
import dev.arcade.models.ExecuteToolResponse;
import dev.arcade.models.ToolExecuteParams;
/**
* Example of calling a tool using the Arcade Java SDK.
*/
public class PlaySpotify {
/**
* Simple main method example.
* @param args Not used.
*/
public static void main(String[] args) {
// Configures using the `ARCADE_API_KEY` environment variable
ArcadeClient client = ArcadeOkHttpClient.fromEnv();
String userId = System.getenv("ARCADE_USER_ID"); // the Spotify tool require a userId
if (userId == null) {
throw new IllegalArgumentException("Missing ARCADE_USER_ID environment variable");
}
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"));
}
}