-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpringBootExample.java
More file actions
53 lines (48 loc) · 2.07 KB
/
SpringBootExample.java
File metadata and controls
53 lines (48 loc) · 2.07 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
42
43
44
45
46
47
48
49
50
51
52
53
package dev.arcade.example;
import dev.arcade.client.ArcadeClient;
import dev.arcade.models.tools.ExecuteToolRequest;
import dev.arcade.models.tools.ExecuteToolResponse;
import dev.arcade.models.tools.ToolExecuteParams;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
/**
* Example of calling a tool using the Arcade Java SDK.
*/
@SpringBootApplication
public class SpringBootExample {
/**
* Starts the Spring Boot application.
* @param args All args are passed into the SpringApplication
*/
public static void main(String[] args) {
SpringApplication.run(SpringBootExample.class, args);
}
/**
* Injects an <code>ArcadeClient</code>, and returns an ApplicationRunner that makes a tool call.
* @param client Arcade Client is autoinjected if ARCADE_API_KEY, or equivalent application.properties var is set.
* @return Runs code on application start.
*/
@Bean
ApplicationRunner appRunner(ArcadeClient client) {
return args -> {
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"));
};
}
}