1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct CreateRobotParams {
20 pub robot: models::RobotCreate,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct DeleteRobotParams {
29 pub robot_id: i32,
31 pub x_request_id: Option<String>
33}
34
35#[derive(Clone, Debug)]
37pub struct GetRobotByIdParams {
38 pub robot_id: i32,
40 pub x_request_id: Option<String>
42}
43
44#[derive(Clone, Debug)]
46pub struct ListRobotParams {
47 pub x_request_id: Option<String>,
49 pub q: Option<String>,
51 pub sort: Option<String>,
53 pub page: Option<i64>,
55 pub page_size: Option<i64>
57}
58
59#[derive(Clone, Debug)]
61pub struct RefreshSecParams {
62 pub robot_id: i32,
64 pub robot_sec: models::RobotSec,
66 pub x_request_id: Option<String>
68}
69
70#[derive(Clone, Debug)]
72pub struct UpdateRobotParams {
73 pub robot_id: i32,
75 pub robot: models::Robot,
77 pub x_request_id: Option<String>
79}
80
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateRobotError {
86 Status400(models::Errors),
87 Status401(models::Errors),
88 Status403(models::Errors),
89 Status404(models::Errors),
90 Status500(models::Errors),
91 UnknownValue(serde_json::Value),
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum DeleteRobotError {
98 Status400(models::Errors),
99 Status401(models::Errors),
100 Status403(models::Errors),
101 Status404(models::Errors),
102 Status500(models::Errors),
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetRobotByIdError {
110 Status401(models::Errors),
111 Status403(models::Errors),
112 Status404(models::Errors),
113 Status500(models::Errors),
114 UnknownValue(serde_json::Value),
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum ListRobotError {
121 Status400(models::Errors),
122 Status404(models::Errors),
123 Status500(models::Errors),
124 UnknownValue(serde_json::Value),
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum RefreshSecError {
131 Status400(models::Errors),
132 Status401(models::Errors),
133 Status403(models::Errors),
134 Status404(models::Errors),
135 Status500(models::Errors),
136 UnknownValue(serde_json::Value),
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum UpdateRobotError {
143 Status400(models::Errors),
144 Status401(models::Errors),
145 Status403(models::Errors),
146 Status404(models::Errors),
147 Status409(models::Errors),
148 Status500(models::Errors),
149 UnknownValue(serde_json::Value),
150}
151
152
153pub async fn create_robot(configuration: &configuration::Configuration, params: CreateRobotParams) -> Result<models::RobotCreated, Error<CreateRobotError>> {
155
156 let uri_str = format!("{}/robots", configuration.base_path);
157 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
158
159 if let Some(ref user_agent) = configuration.user_agent {
160 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161 }
162 if let Some(param_value) = params.x_request_id {
163 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
164 }
165 if let Some(ref auth_conf) = configuration.basic_auth {
166 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
167 };
168 req_builder = req_builder.json(¶ms.robot);
169
170 let req = req_builder.build()?;
171 let resp = configuration.client.execute(req).await?;
172
173 let status = resp.status();
174 let content_type = resp
175 .headers()
176 .get("content-type")
177 .and_then(|v| v.to_str().ok())
178 .unwrap_or("application/octet-stream");
179 let content_type = super::ContentType::from(content_type);
180
181 if !status.is_client_error() && !status.is_server_error() {
182 let content = resp.text().await?;
183 match content_type {
184 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
185 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RobotCreated`"))),
186 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RobotCreated`")))),
187 }
188 } else {
189 let content = resp.text().await?;
190 let entity: Option<CreateRobotError> = serde_json::from_str(&content).ok();
191 Err(Error::ResponseError(ResponseContent { status, content, entity }))
192 }
193}
194
195pub async fn delete_robot(configuration: &configuration::Configuration, params: DeleteRobotParams) -> Result<(), Error<DeleteRobotError>> {
197
198 let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
199 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
200
201 if let Some(ref user_agent) = configuration.user_agent {
202 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
203 }
204 if let Some(param_value) = params.x_request_id {
205 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
206 }
207 if let Some(ref auth_conf) = configuration.basic_auth {
208 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
209 };
210
211 let req = req_builder.build()?;
212 let resp = configuration.client.execute(req).await?;
213
214 let status = resp.status();
215
216 if !status.is_client_error() && !status.is_server_error() {
217 Ok(())
218 } else {
219 let content = resp.text().await?;
220 let entity: Option<DeleteRobotError> = serde_json::from_str(&content).ok();
221 Err(Error::ResponseError(ResponseContent { status, content, entity }))
222 }
223}
224
225pub async fn get_robot_by_id(configuration: &configuration::Configuration, params: GetRobotByIdParams) -> Result<models::Robot, Error<GetRobotByIdError>> {
227
228 let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
229 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231 if let Some(ref user_agent) = configuration.user_agent {
232 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233 }
234 if let Some(param_value) = params.x_request_id {
235 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
236 }
237 if let Some(ref auth_conf) = configuration.basic_auth {
238 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
239 };
240
241 let req = req_builder.build()?;
242 let resp = configuration.client.execute(req).await?;
243
244 let status = resp.status();
245 let content_type = resp
246 .headers()
247 .get("content-type")
248 .and_then(|v| v.to_str().ok())
249 .unwrap_or("application/octet-stream");
250 let content_type = super::ContentType::from(content_type);
251
252 if !status.is_client_error() && !status.is_server_error() {
253 let content = resp.text().await?;
254 match content_type {
255 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Robot`"))),
257 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Robot`")))),
258 }
259 } else {
260 let content = resp.text().await?;
261 let entity: Option<GetRobotByIdError> = serde_json::from_str(&content).ok();
262 Err(Error::ResponseError(ResponseContent { status, content, entity }))
263 }
264}
265
266pub async fn list_robot(configuration: &configuration::Configuration, params: ListRobotParams) -> Result<Vec<models::Robot>, Error<ListRobotError>> {
268
269 let uri_str = format!("{}/robots", configuration.base_path);
270 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
271
272 if let Some(ref param_value) = params.q {
273 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
274 }
275 if let Some(ref param_value) = params.sort {
276 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
277 }
278 if let Some(ref param_value) = params.page {
279 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
280 }
281 if let Some(ref param_value) = params.page_size {
282 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
283 }
284 if let Some(ref user_agent) = configuration.user_agent {
285 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
286 }
287 if let Some(param_value) = params.x_request_id {
288 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
289 }
290 if let Some(ref auth_conf) = configuration.basic_auth {
291 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
292 };
293
294 let req = req_builder.build()?;
295 let resp = configuration.client.execute(req).await?;
296
297 let status = resp.status();
298 let content_type = resp
299 .headers()
300 .get("content-type")
301 .and_then(|v| v.to_str().ok())
302 .unwrap_or("application/octet-stream");
303 let content_type = super::ContentType::from(content_type);
304
305 if !status.is_client_error() && !status.is_server_error() {
306 let content = resp.text().await?;
307 match content_type {
308 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
309 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Robot>`"))),
310 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Robot>`")))),
311 }
312 } else {
313 let content = resp.text().await?;
314 let entity: Option<ListRobotError> = serde_json::from_str(&content).ok();
315 Err(Error::ResponseError(ResponseContent { status, content, entity }))
316 }
317}
318
319pub async fn refresh_sec(configuration: &configuration::Configuration, params: RefreshSecParams) -> Result<models::RobotSec, Error<RefreshSecError>> {
321
322 let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
323 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
324
325 if let Some(ref user_agent) = configuration.user_agent {
326 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
327 }
328 if let Some(param_value) = params.x_request_id {
329 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
330 }
331 if let Some(ref auth_conf) = configuration.basic_auth {
332 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
333 };
334 req_builder = req_builder.json(¶ms.robot_sec);
335
336 let req = req_builder.build()?;
337 let resp = configuration.client.execute(req).await?;
338
339 let status = resp.status();
340 let content_type = resp
341 .headers()
342 .get("content-type")
343 .and_then(|v| v.to_str().ok())
344 .unwrap_or("application/octet-stream");
345 let content_type = super::ContentType::from(content_type);
346
347 if !status.is_client_error() && !status.is_server_error() {
348 let content = resp.text().await?;
349 match content_type {
350 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
351 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RobotSec`"))),
352 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RobotSec`")))),
353 }
354 } else {
355 let content = resp.text().await?;
356 let entity: Option<RefreshSecError> = serde_json::from_str(&content).ok();
357 Err(Error::ResponseError(ResponseContent { status, content, entity }))
358 }
359}
360
361pub async fn update_robot(configuration: &configuration::Configuration, params: UpdateRobotParams) -> Result<(), Error<UpdateRobotError>> {
363
364 let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
365 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
366
367 if let Some(ref user_agent) = configuration.user_agent {
368 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
369 }
370 if let Some(param_value) = params.x_request_id {
371 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
372 }
373 if let Some(ref auth_conf) = configuration.basic_auth {
374 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
375 };
376 req_builder = req_builder.json(¶ms.robot);
377
378 let req = req_builder.build()?;
379 let resp = configuration.client.execute(req).await?;
380
381 let status = resp.status();
382
383 if !status.is_client_error() && !status.is_server_error() {
384 Ok(())
385 } else {
386 let content = resp.text().await?;
387 let entity: Option<UpdateRobotError> = serde_json::from_str(&content).ok();
388 Err(Error::ResponseError(ResponseContent { status, content, entity }))
389 }
390}
391