1use reqwest::StatusCode;
8
9use super::{configuration, Error};
10use crate::apis::ResponseContent;
11
12#[derive(Debug, Clone)]
14pub enum GetAgentSuccess {
15 Status200(crate::models::GetMyAgent200Response),
17}
18
19impl GetAgentSuccess {
20 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
21 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#[derive(Debug, Clone)]
34pub enum GetAgentsSuccess {
35 Status200(crate::models::GetAgents200Response),
37}
38
39impl GetAgentsSuccess {
40 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
41 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#[derive(Debug, Clone)]
54pub enum GetMyAgentSuccess {
55 Status200(crate::models::GetMyAgent200Response),
57}
58
59impl GetMyAgentSuccess {
60 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
61 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#[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 match status.as_u16() {
81 _ => None,
82 }
83 }
84}
85
86#[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 match status.as_u16() {
95 _ => None,
96 }
97 }
98}
99
100#[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 match status.as_u16() {
109 _ => None,
110 }
111 }
112}
113
114pub 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 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 if let Some(user_agent) = &configuration.user_agent {
134 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135 }
136
137 if let Some(token) = &configuration.bearer_access_token {
140 req_builder = req_builder.bearer_auth(token.to_owned());
141 };
142
143 let req = req_builder.build()?;
147 let resp = client.execute(req).await?;
148
149 let status = resp.status();
151 let response_body = resp.text().await?;
152
153 if !status.is_client_error() && !status.is_server_error() {
154 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 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
186pub 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 let uri_str = format!("{}/agents", configuration.base_path);
197 let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
198
199 if let Some(s) = &page {
202 req_builder = req_builder.query(&[("page", &s.to_string())]);
203 }
204 if let Some(s) = &limit {
207 req_builder = req_builder.query(&[("limit", &s.to_string())]);
208 }
209
210 if let Some(user_agent) = &configuration.user_agent {
214 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215 }
216
217 if let Some(token) = &configuration.bearer_access_token {
220 req_builder = req_builder.bearer_auth(token.to_owned());
221 };
222
223 let req = req_builder.build()?;
227 let resp = client.execute(req).await?;
228
229 let status = resp.status();
231 let response_body = resp.text().await?;
232
233 if !status.is_client_error() && !status.is_server_error() {
234 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 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
266pub async fn get_my_agent(
268 configuration: &configuration::Configuration,
269) -> Result<ResponseContent<GetMyAgentSuccess>, Error<GetMyAgentError>> {
270 let client = &configuration.client;
271
272 let uri_str = format!("{}/my/agent", configuration.base_path);
275 let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
276
277 if let Some(user_agent) = &configuration.user_agent {
281 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
282 }
283
284 if let Some(token) = &configuration.bearer_access_token {
287 req_builder = req_builder.bearer_auth(token.to_owned());
288 };
289
290 let req = req_builder.build()?;
294 let resp = client.execute(req).await?;
295
296 let status = resp.status();
298 let response_body = resp.text().await?;
299
300 if !status.is_client_error() && !status.is_server_error() {
301 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 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}