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 CreateRobotV1Params {
20 pub project_name_or_id: String,
22 pub robot: models::RobotCreateV1,
24 pub x_request_id: Option<String>,
26 pub x_is_resource_name: Option<bool>
28}
29
30#[derive(Clone, Debug)]
32pub struct DeleteRobotV1Params {
33 pub project_name_or_id: String,
35 pub robot_id: i32,
37 pub x_request_id: Option<String>,
39 pub x_is_resource_name: Option<bool>
41}
42
43#[derive(Clone, Debug)]
45pub struct GetRobotByIdv1Params {
46 pub project_name_or_id: String,
48 pub robot_id: i32,
50 pub x_request_id: Option<String>,
52 pub x_is_resource_name: Option<bool>
54}
55
56#[derive(Clone, Debug)]
58pub struct ListRobotV1Params {
59 pub project_name_or_id: String,
61 pub x_request_id: Option<String>,
63 pub x_is_resource_name: Option<bool>,
65 pub page: Option<i64>,
67 pub page_size: Option<i64>,
69 pub q: Option<String>,
71 pub sort: Option<String>
73}
74
75#[derive(Clone, Debug)]
77pub struct UpdateRobotV1Params {
78 pub project_name_or_id: String,
80 pub robot_id: i32,
82 pub robot: models::Robot,
84 pub x_request_id: Option<String>,
86 pub x_is_resource_name: Option<bool>
88}
89
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum CreateRobotV1Error {
95 Status400(models::Errors),
96 Status401(models::Errors),
97 Status403(models::Errors),
98 Status404(models::Errors),
99 Status500(models::Errors),
100 UnknownValue(serde_json::Value),
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum DeleteRobotV1Error {
107 Status400(models::Errors),
108 Status401(models::Errors),
109 Status403(models::Errors),
110 Status404(models::Errors),
111 Status500(models::Errors),
112 UnknownValue(serde_json::Value),
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum GetRobotByIdv1Error {
119 Status401(models::Errors),
120 Status403(models::Errors),
121 Status404(models::Errors),
122 Status500(models::Errors),
123 UnknownValue(serde_json::Value),
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum ListRobotV1Error {
130 Status400(models::Errors),
131 Status404(models::Errors),
132 Status500(models::Errors),
133 UnknownValue(serde_json::Value),
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(untagged)]
139pub enum UpdateRobotV1Error {
140 Status400(models::Errors),
141 Status401(models::Errors),
142 Status403(models::Errors),
143 Status404(models::Errors),
144 Status409(models::Errors),
145 Status500(models::Errors),
146 UnknownValue(serde_json::Value),
147}
148
149
150pub async fn create_robot_v1(configuration: &configuration::Configuration, params: CreateRobotV1Params) -> Result<models::RobotCreated, Error<CreateRobotV1Error>> {
152
153 let uri_str = format!("{}/projects/{project_name_or_id}/robots", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
154 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
155
156 if let Some(ref user_agent) = configuration.user_agent {
157 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158 }
159 if let Some(param_value) = params.x_request_id {
160 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
161 }
162 if let Some(param_value) = params.x_is_resource_name {
163 req_builder = req_builder.header("X-Is-Resource-Name", 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<CreateRobotV1Error> = serde_json::from_str(&content).ok();
191 Err(Error::ResponseError(ResponseContent { status, content, entity }))
192 }
193}
194
195pub async fn delete_robot_v1(configuration: &configuration::Configuration, params: DeleteRobotV1Params) -> Result<(), Error<DeleteRobotV1Error>> {
197
198 let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), 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(param_value) = params.x_is_resource_name {
208 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
209 }
210 if let Some(ref auth_conf) = configuration.basic_auth {
211 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
212 };
213
214 let req = req_builder.build()?;
215 let resp = configuration.client.execute(req).await?;
216
217 let status = resp.status();
218
219 if !status.is_client_error() && !status.is_server_error() {
220 Ok(())
221 } else {
222 let content = resp.text().await?;
223 let entity: Option<DeleteRobotV1Error> = serde_json::from_str(&content).ok();
224 Err(Error::ResponseError(ResponseContent { status, content, entity }))
225 }
226}
227
228pub async fn get_robot_by_idv1(configuration: &configuration::Configuration, params: GetRobotByIdv1Params) -> Result<models::Robot, Error<GetRobotByIdv1Error>> {
230
231 let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), robot_id=params.robot_id);
232 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
233
234 if let Some(ref user_agent) = configuration.user_agent {
235 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236 }
237 if let Some(param_value) = params.x_request_id {
238 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
239 }
240 if let Some(param_value) = params.x_is_resource_name {
241 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
242 }
243 if let Some(ref auth_conf) = configuration.basic_auth {
244 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
245 };
246
247 let req = req_builder.build()?;
248 let resp = configuration.client.execute(req).await?;
249
250 let status = resp.status();
251 let content_type = resp
252 .headers()
253 .get("content-type")
254 .and_then(|v| v.to_str().ok())
255 .unwrap_or("application/octet-stream");
256 let content_type = super::ContentType::from(content_type);
257
258 if !status.is_client_error() && !status.is_server_error() {
259 let content = resp.text().await?;
260 match content_type {
261 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
262 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Robot`"))),
263 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`")))),
264 }
265 } else {
266 let content = resp.text().await?;
267 let entity: Option<GetRobotByIdv1Error> = serde_json::from_str(&content).ok();
268 Err(Error::ResponseError(ResponseContent { status, content, entity }))
269 }
270}
271
272pub async fn list_robot_v1(configuration: &configuration::Configuration, params: ListRobotV1Params) -> Result<Vec<models::Robot>, Error<ListRobotV1Error>> {
274
275 let uri_str = format!("{}/projects/{project_name_or_id}/robots", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
276 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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 param_value) = params.q {
285 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
286 }
287 if let Some(ref param_value) = params.sort {
288 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
289 }
290 if let Some(ref user_agent) = configuration.user_agent {
291 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
292 }
293 if let Some(param_value) = params.x_request_id {
294 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
295 }
296 if let Some(param_value) = params.x_is_resource_name {
297 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
298 }
299 if let Some(ref auth_conf) = configuration.basic_auth {
300 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
301 };
302
303 let req = req_builder.build()?;
304 let resp = configuration.client.execute(req).await?;
305
306 let status = resp.status();
307 let content_type = resp
308 .headers()
309 .get("content-type")
310 .and_then(|v| v.to_str().ok())
311 .unwrap_or("application/octet-stream");
312 let content_type = super::ContentType::from(content_type);
313
314 if !status.is_client_error() && !status.is_server_error() {
315 let content = resp.text().await?;
316 match content_type {
317 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
318 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Robot>`"))),
319 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>`")))),
320 }
321 } else {
322 let content = resp.text().await?;
323 let entity: Option<ListRobotV1Error> = serde_json::from_str(&content).ok();
324 Err(Error::ResponseError(ResponseContent { status, content, entity }))
325 }
326}
327
328pub async fn update_robot_v1(configuration: &configuration::Configuration, params: UpdateRobotV1Params) -> Result<(), Error<UpdateRobotV1Error>> {
330
331 let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), robot_id=params.robot_id);
332 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
333
334 if let Some(ref user_agent) = configuration.user_agent {
335 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336 }
337 if let Some(param_value) = params.x_request_id {
338 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
339 }
340 if let Some(param_value) = params.x_is_resource_name {
341 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
342 }
343 if let Some(ref auth_conf) = configuration.basic_auth {
344 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345 };
346 req_builder = req_builder.json(¶ms.robot);
347
348 let req = req_builder.build()?;
349 let resp = configuration.client.execute(req).await?;
350
351 let status = resp.status();
352
353 if !status.is_client_error() && !status.is_server_error() {
354 Ok(())
355 } else {
356 let content = resp.text().await?;
357 let entity: Option<UpdateRobotV1Error> = serde_json::from_str(&content).ok();
358 Err(Error::ResponseError(ResponseContent { status, content, entity }))
359 }
360}
361