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 CreateLabelParams {
20 pub label: models::Label,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct DeleteLabelParams {
29 pub label_id: i64,
31 pub x_request_id: Option<String>
33}
34
35#[derive(Clone, Debug)]
37pub struct GetLabelByIdParams {
38 pub label_id: i64,
40 pub x_request_id: Option<String>
42}
43
44#[derive(Clone, Debug)]
46pub struct ListLabelsParams {
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 pub name: Option<String>,
59 pub scope: Option<String>,
61 pub project_id: Option<i64>
63}
64
65#[derive(Clone, Debug)]
67pub struct UpdateLabelParams {
68 pub label_id: i64,
70 pub label: models::Label,
72 pub x_request_id: Option<String>
74}
75
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum CreateLabelError {
81 Status400(models::Errors),
82 Status401(models::Errors),
83 Status409(models::Errors),
84 Status415(models::Errors),
85 Status500(models::Errors),
86 UnknownValue(serde_json::Value),
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum DeleteLabelError {
93 Status400(models::Errors),
94 Status401(models::Errors),
95 Status404(models::Errors),
96 Status500(models::Errors),
97 UnknownValue(serde_json::Value),
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum GetLabelByIdError {
104 Status401(models::Errors),
105 Status404(models::Errors),
106 Status500(models::Errors),
107 UnknownValue(serde_json::Value),
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum ListLabelsError {
114 Status400(models::Errors),
115 Status401(models::Errors),
116 Status500(models::Errors),
117 UnknownValue(serde_json::Value),
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum UpdateLabelError {
124 Status400(models::Errors),
125 Status401(models::Errors),
126 Status404(models::Errors),
127 Status409(models::Errors),
128 Status500(models::Errors),
129 UnknownValue(serde_json::Value),
130}
131
132
133pub async fn create_label(configuration: &configuration::Configuration, params: CreateLabelParams) -> Result<(), Error<CreateLabelError>> {
135
136 let uri_str = format!("{}/labels", configuration.base_path);
137 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139 if let Some(ref user_agent) = configuration.user_agent {
140 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141 }
142 if let Some(param_value) = params.x_request_id {
143 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
144 }
145 if let Some(ref auth_conf) = configuration.basic_auth {
146 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
147 };
148 req_builder = req_builder.json(¶ms.label);
149
150 let req = req_builder.build()?;
151 let resp = configuration.client.execute(req).await?;
152
153 let status = resp.status();
154
155 if !status.is_client_error() && !status.is_server_error() {
156 Ok(())
157 } else {
158 let content = resp.text().await?;
159 let entity: Option<CreateLabelError> = serde_json::from_str(&content).ok();
160 Err(Error::ResponseError(ResponseContent { status, content, entity }))
161 }
162}
163
164pub async fn delete_label(configuration: &configuration::Configuration, params: DeleteLabelParams) -> Result<(), Error<DeleteLabelError>> {
166
167 let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_id);
168 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
169
170 if let Some(ref user_agent) = configuration.user_agent {
171 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172 }
173 if let Some(param_value) = params.x_request_id {
174 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
175 }
176 if let Some(ref auth_conf) = configuration.basic_auth {
177 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
178 };
179
180 let req = req_builder.build()?;
181 let resp = configuration.client.execute(req).await?;
182
183 let status = resp.status();
184
185 if !status.is_client_error() && !status.is_server_error() {
186 Ok(())
187 } else {
188 let content = resp.text().await?;
189 let entity: Option<DeleteLabelError> = serde_json::from_str(&content).ok();
190 Err(Error::ResponseError(ResponseContent { status, content, entity }))
191 }
192}
193
194pub async fn get_label_by_id(configuration: &configuration::Configuration, params: GetLabelByIdParams) -> Result<models::Label, Error<GetLabelByIdError>> {
196
197 let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_id);
198 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
199
200 if let Some(ref user_agent) = configuration.user_agent {
201 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202 }
203 if let Some(param_value) = params.x_request_id {
204 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
205 }
206 if let Some(ref auth_conf) = configuration.basic_auth {
207 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
208 };
209
210 let req = req_builder.build()?;
211 let resp = configuration.client.execute(req).await?;
212
213 let status = resp.status();
214 let content_type = resp
215 .headers()
216 .get("content-type")
217 .and_then(|v| v.to_str().ok())
218 .unwrap_or("application/octet-stream");
219 let content_type = super::ContentType::from(content_type);
220
221 if !status.is_client_error() && !status.is_server_error() {
222 let content = resp.text().await?;
223 match content_type {
224 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Label`"))),
226 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::Label`")))),
227 }
228 } else {
229 let content = resp.text().await?;
230 let entity: Option<GetLabelByIdError> = serde_json::from_str(&content).ok();
231 Err(Error::ResponseError(ResponseContent { status, content, entity }))
232 }
233}
234
235pub async fn list_labels(configuration: &configuration::Configuration, params: ListLabelsParams) -> Result<Vec<models::Label>, Error<ListLabelsError>> {
237
238 let uri_str = format!("{}/labels", configuration.base_path);
239 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
240
241 if let Some(ref param_value) = params.q {
242 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
243 }
244 if let Some(ref param_value) = params.sort {
245 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
246 }
247 if let Some(ref param_value) = params.page {
248 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
249 }
250 if let Some(ref param_value) = params.page_size {
251 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
252 }
253 if let Some(ref param_value) = params.name {
254 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
255 }
256 if let Some(ref param_value) = params.scope {
257 req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
258 }
259 if let Some(ref param_value) = params.project_id {
260 req_builder = req_builder.query(&[("project_id", ¶m_value.to_string())]);
261 }
262 if let Some(ref user_agent) = configuration.user_agent {
263 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264 }
265 if let Some(param_value) = params.x_request_id {
266 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
267 }
268 if let Some(ref auth_conf) = configuration.basic_auth {
269 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
270 };
271
272 let req = req_builder.build()?;
273 let resp = configuration.client.execute(req).await?;
274
275 let status = resp.status();
276 let content_type = resp
277 .headers()
278 .get("content-type")
279 .and_then(|v| v.to_str().ok())
280 .unwrap_or("application/octet-stream");
281 let content_type = super::ContentType::from(content_type);
282
283 if !status.is_client_error() && !status.is_server_error() {
284 let content = resp.text().await?;
285 match content_type {
286 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
287 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Label>`"))),
288 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::Label>`")))),
289 }
290 } else {
291 let content = resp.text().await?;
292 let entity: Option<ListLabelsError> = serde_json::from_str(&content).ok();
293 Err(Error::ResponseError(ResponseContent { status, content, entity }))
294 }
295}
296
297pub async fn update_label(configuration: &configuration::Configuration, params: UpdateLabelParams) -> Result<(), Error<UpdateLabelError>> {
299
300 let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_id);
301 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
302
303 if let Some(ref user_agent) = configuration.user_agent {
304 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305 }
306 if let Some(param_value) = params.x_request_id {
307 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
308 }
309 if let Some(ref auth_conf) = configuration.basic_auth {
310 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
311 };
312 req_builder = req_builder.json(¶ms.label);
313
314 let req = req_builder.build()?;
315 let resp = configuration.client.execute(req).await?;
316
317 let status = resp.status();
318
319 if !status.is_client_error() && !status.is_server_error() {
320 Ok(())
321 } else {
322 let content = resp.text().await?;
323 let entity: Option<UpdateLabelError> = serde_json::from_str(&content).ok();
324 Err(Error::ResponseError(ResponseContent { status, content, entity }))
325 }
326}
327