space_traders/apis/
agents_api.rs

1//!
2//!
3//! Generated by: <https://openapi-generator.tech>
4//!
5//! Version of specification: `2.0.0`
6
7use reqwest::StatusCode;
8
9use super::{configuration, Error};
10use crate::apis::ResponseContent;
11
12/// Enum for successes of method [`get_agent`].
13#[derive(Debug, Clone)]
14pub enum GetAgentSuccess {
15    /// Response for status code 200.
16    Status200(crate::models::GetMyAgent200Response),
17}
18
19impl GetAgentSuccess {
20    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
21        // Attempt to deserialize the response for the given status code.
22        match status.as_u16() {
23            200 => Some(match serde_json::from_str(body) {
24                Ok(data) => Ok(Self::Status200(data)),
25                Err(err) => Err(err),
26            }),
27            _ => None,
28        }
29    }
30}
31
32/// Enum for successes of method [`get_agents`].
33#[derive(Debug, Clone)]
34pub enum GetAgentsSuccess {
35    /// Response for status code 200.
36    Status200(crate::models::GetAgents200Response),
37}
38
39impl GetAgentsSuccess {
40    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
41        // Attempt to deserialize the response for the given status code.
42        match status.as_u16() {
43            200 => Some(match serde_json::from_str(body) {
44                Ok(data) => Ok(Self::Status200(data)),
45                Err(err) => Err(err),
46            }),
47            _ => None,
48        }
49    }
50}
51
52/// Enum for successes of method [`get_my_agent`].
53#[derive(Debug, Clone)]
54pub enum GetMyAgentSuccess {
55    /// Response for status code 200.
56    Status200(crate::models::GetMyAgent200Response),
57}
58
59impl GetMyAgentSuccess {
60    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
61        // Attempt to deserialize the response for the given status code.
62        match status.as_u16() {
63            200 => Some(match serde_json::from_str(body) {
64                Ok(data) => Ok(Self::Status200(data)),
65                Err(err) => Err(err),
66            }),
67            _ => None,
68        }
69    }
70}
71
72/// Enum for known errors of method [`get_agent`].
73#[derive(Debug, Clone)]
74pub enum GetAgentError {}
75
76impl GetAgentError {
77    #[allow(unused_variables, clippy::match_single_binding)]
78    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
79        // Attempt to deserialize the response for the given status code.
80        match status.as_u16() {
81            _ => None,
82        }
83    }
84}
85
86/// Enum for known errors of method [`get_agents`].
87#[derive(Debug, Clone)]
88pub enum GetAgentsError {}
89
90impl GetAgentsError {
91    #[allow(unused_variables, clippy::match_single_binding)]
92    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
93        // Attempt to deserialize the response for the given status code.
94        match status.as_u16() {
95            _ => None,
96        }
97    }
98}
99
100/// Enum for known errors of method [`get_my_agent`].
101#[derive(Debug, Clone)]
102pub enum GetMyAgentError {}
103
104impl GetMyAgentError {
105    #[allow(unused_variables, clippy::match_single_binding)]
106    fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
107        // Attempt to deserialize the response for the given status code.
108        match status.as_u16() {
109            _ => None,
110        }
111    }
112}
113
114/// Fetch agent details.
115pub async fn get_agent(
116    configuration: &configuration::Configuration,
117    agent_symbol: &str,
118) -> Result<ResponseContent<GetAgentSuccess>, Error<GetAgentError>> {
119    let client = &configuration.client;
120
121    // Create the request from a path.
122    // Make sure to url encode any user given text.
123    let uri_str = format!(
124        "{}/agents/{agentSymbol}",
125        configuration.base_path,
126        agentSymbol = crate::apis::urlencode(agent_symbol)
127    );
128    let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
129
130    // === Add headers to request ===
131
132    // Set the user agent string if given.
133    if let Some(user_agent) = &configuration.user_agent {
134        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135    }
136
137    // === Add auth to request ===
138
139    if let Some(token) = &configuration.bearer_access_token {
140        req_builder = req_builder.bearer_auth(token.to_owned());
141    };
142
143    // === Request is built.
144
145    // Execute the request.
146    let req = req_builder.build()?;
147    let resp = client.execute(req).await?;
148
149    // Get the response.
150    let status = resp.status();
151    let response_body = resp.text().await?;
152
153    if !status.is_client_error() && !status.is_server_error() {
154        // Try to parse the OK response.
155        match GetAgentSuccess::from_body(status, &response_body) {
156            Some(Ok(content)) => Ok(ResponseContent {
157                status,
158                response_body,
159                content,
160            }),
161            Some(Err(err)) => Err(err.into()),
162            None => Err(Error::UnknownResponse {
163                status,
164                is_error: false,
165                response_body,
166            }),
167        }
168    } else {
169        // Try to parse the Err response.
170        match GetAgentError::from_body(status, &response_body) {
171            Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
172                status,
173                response_body,
174                content,
175            })),
176            Some(Err(err)) => Err(err.into()),
177            None => Err(Error::UnknownResponse {
178                status,
179                is_error: true,
180                response_body,
181            }),
182        }
183    }
184}
185
186/// Fetch agents details.
187pub async fn get_agents(
188    configuration: &configuration::Configuration,
189    page: Option<u32>,
190    limit: Option<u32>,
191) -> Result<ResponseContent<GetAgentsSuccess>, Error<GetAgentsError>> {
192    let client = &configuration.client;
193
194    // Create the request from a path.
195    // Make sure to url encode any user given text.
196    let uri_str = format!("{}/agents", configuration.base_path);
197    let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
198
199    // === Add queries to request ===
200
201    if let Some(s) = &page {
202        req_builder = req_builder.query(&[("page", &s.to_string())]);
203    }
204    // === Add queries to request ===
205
206    if let Some(s) = &limit {
207        req_builder = req_builder.query(&[("limit", &s.to_string())]);
208    }
209
210    // === Add headers to request ===
211
212    // Set the user agent string if given.
213    if let Some(user_agent) = &configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216
217    // === Add auth to request ===
218
219    if let Some(token) = &configuration.bearer_access_token {
220        req_builder = req_builder.bearer_auth(token.to_owned());
221    };
222
223    // === Request is built.
224
225    // Execute the request.
226    let req = req_builder.build()?;
227    let resp = client.execute(req).await?;
228
229    // Get the response.
230    let status = resp.status();
231    let response_body = resp.text().await?;
232
233    if !status.is_client_error() && !status.is_server_error() {
234        // Try to parse the OK response.
235        match GetAgentsSuccess::from_body(status, &response_body) {
236            Some(Ok(content)) => Ok(ResponseContent {
237                status,
238                response_body,
239                content,
240            }),
241            Some(Err(err)) => Err(err.into()),
242            None => Err(Error::UnknownResponse {
243                status,
244                is_error: false,
245                response_body,
246            }),
247        }
248    } else {
249        // Try to parse the Err response.
250        match GetAgentsError::from_body(status, &response_body) {
251            Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
252                status,
253                response_body,
254                content,
255            })),
256            Some(Err(err)) => Err(err.into()),
257            None => Err(Error::UnknownResponse {
258                status,
259                is_error: true,
260                response_body,
261            }),
262        }
263    }
264}
265
266/// Fetch your agent's details.
267pub async fn get_my_agent(
268    configuration: &configuration::Configuration,
269) -> Result<ResponseContent<GetMyAgentSuccess>, Error<GetMyAgentError>> {
270    let client = &configuration.client;
271
272    // Create the request from a path.
273    // Make sure to url encode any user given text.
274    let uri_str = format!("{}/my/agent", configuration.base_path);
275    let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
276
277    // === Add headers to request ===
278
279    // Set the user agent string if given.
280    if let Some(user_agent) = &configuration.user_agent {
281        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
282    }
283
284    // === Add auth to request ===
285
286    if let Some(token) = &configuration.bearer_access_token {
287        req_builder = req_builder.bearer_auth(token.to_owned());
288    };
289
290    // === Request is built.
291
292    // Execute the request.
293    let req = req_builder.build()?;
294    let resp = client.execute(req).await?;
295
296    // Get the response.
297    let status = resp.status();
298    let response_body = resp.text().await?;
299
300    if !status.is_client_error() && !status.is_server_error() {
301        // Try to parse the OK response.
302        match GetMyAgentSuccess::from_body(status, &response_body) {
303            Some(Ok(content)) => Ok(ResponseContent {
304                status,
305                response_body,
306                content,
307            }),
308            Some(Err(err)) => Err(err.into()),
309            None => Err(Error::UnknownResponse {
310                status,
311                is_error: false,
312                response_body,
313            }),
314        }
315    } else {
316        // Try to parse the Err response.
317        match GetMyAgentError::from_body(status, &response_body) {
318            Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
319                status,
320                response_body,
321                content,
322            })),
323            Some(Err(err)) => Err(err.into()),
324            None => Err(Error::UnknownResponse {
325                status,
326                is_error: true,
327                response_body,
328            }),
329        }
330    }
331}