spacetraders_client/endpoints/agents/
mod.rs1mod factions;
2
3use std::num::NonZeroU64;
4
5use crate::client::StClient;
6use crate::client::{ClientError, RequestPriority};
7use crate::types;
8
9impl StClient {
10 pub async fn register(
11 &self,
12 symbol: &str,
13 faction: types::FactionSymbol,
14 ) -> Result<types::RegisterResponse, ClientError> {
15 self.register_with_priority(symbol, faction, RequestPriority::Normal)
16 .await
17 }
18
19 pub async fn register_with_priority(
20 &self,
21 symbol: &str,
22 faction: types::FactionSymbol,
23 priority: RequestPriority,
24 ) -> Result<types::RegisterResponse, ClientError> {
25 let body = types::RegisterBody {
26 symbol: symbol
27 .parse()
28 .map_err(|e| ClientError::Api(format!("invalid symbol: {e:?}")))?,
29 faction,
30 };
31 self.send_mutating("register", priority, || self.inner.register(&body))
32 .await
33 }
34
35 pub async fn my_agent(&self) -> Result<types::GetMyAgentResponse, ClientError> {
36 self.my_agent_with_priority(RequestPriority::Normal).await
37 }
38
39 pub async fn my_agent_with_priority(
40 &self,
41 priority: RequestPriority,
42 ) -> Result<types::GetMyAgentResponse, ClientError> {
43 self.send("get_my_agent", priority, || self.inner.get_my_agent())
44 .await
45 }
46
47 pub async fn get_agents(
48 &self,
49 limit: Option<NonZeroU64>,
50 page: Option<NonZeroU64>,
51 ) -> Result<types::GetAgentsResponse, ClientError> {
52 self.get_agents_with_priority(limit, page, RequestPriority::Normal)
53 .await
54 }
55
56 pub async fn get_agents_with_priority(
57 &self,
58 limit: Option<NonZeroU64>,
59 page: Option<NonZeroU64>,
60 priority: RequestPriority,
61 ) -> Result<types::GetAgentsResponse, ClientError> {
62 self.send("get_agents", priority, || {
63 self.inner.get_agents(limit, page)
64 })
65 .await
66 }
67
68 pub async fn get_agent(
69 &self,
70 agent_symbol: &str,
71 ) -> Result<types::GetAgentResponse, ClientError> {
72 self.get_agent_with_priority(agent_symbol, RequestPriority::Normal)
73 .await
74 }
75
76 pub async fn get_agent_with_priority(
77 &self,
78 agent_symbol: &str,
79 priority: RequestPriority,
80 ) -> Result<types::GetAgentResponse, ClientError> {
81 self.send("get_agent", priority, || self.inner.get_agent(agent_symbol))
82 .await
83 }
84
85 pub async fn get_my_agent_events(
86 &self,
87 ) -> Result<types::GetMyAgentEventsResponse, ClientError> {
88 self.get_my_agent_events_with_priority(RequestPriority::Normal)
89 .await
90 }
91
92 pub async fn get_my_agent_events_with_priority(
93 &self,
94 priority: RequestPriority,
95 ) -> Result<types::GetMyAgentEventsResponse, ClientError> {
96 self.send("get_my_agent_events", priority, || {
97 self.inner.get_my_agent_events()
98 })
99 .await
100 }
101
102 pub async fn get_my_account(&self) -> Result<types::GetMyAccountResponse, ClientError> {
103 self.get_my_account_with_priority(RequestPriority::Normal)
104 .await
105 }
106
107 pub async fn get_my_account_with_priority(
108 &self,
109 priority: RequestPriority,
110 ) -> Result<types::GetMyAccountResponse, ClientError> {
111 self.send("get_my_account", priority, || self.inner.get_my_account())
112 .await
113 }
114}