1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DisableTaxonomyError {
22 Status403(models::UnauthorizedApiError),
23 Status404(models::NotFoundApiError),
24 DefaultResponse(models::ApiError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum EnableTaxonomyError {
32 Status403(models::UnauthorizedApiError),
33 Status404(models::NotFoundApiError),
34 DefaultResponse(models::ApiError),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ExportTaxonomyError {
42 Status403(models::UnauthorizedApiError),
43 Status404(models::NotFoundApiError),
44 DefaultResponse(models::ApiError),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetTaxonomiesError {
52 Status403(models::UnauthorizedApiError),
53 Status404(models::NotFoundApiError),
54 DefaultResponse(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetTaxonomyByIdError {
62 Status403(models::UnauthorizedApiError),
63 Status404(models::NotFoundApiError),
64 DefaultResponse(models::ApiError),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum GetTaxonomyTagsError {
72 Status403(models::UnauthorizedApiError),
73 Status404(models::NotFoundApiError),
74 DefaultResponse(models::ApiError),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum UpdateTaxonomiesError {
82 Status403(models::UnauthorizedApiError),
83 Status404(models::NotFoundApiError),
84 DefaultResponse(models::ApiError),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn disable_taxonomy(configuration: &configuration::Configuration, taxonomy_id: &str) -> Result<models::DisableTaxonomy200Response, Error<DisableTaxonomyError>> {
90 let p_taxonomy_id = taxonomy_id;
92
93 let uri_str = format!("{}/taxonomies/disable/{taxonomyId}", configuration.base_path, taxonomyId=crate::apis::urlencode(p_taxonomy_id));
94 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
95
96 if let Some(ref user_agent) = configuration.user_agent {
97 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
98 }
99 if let Some(ref apikey) = configuration.api_key {
100 let key = apikey.key.clone();
101 let value = match apikey.prefix {
102 Some(ref prefix) => format!("{} {}", prefix, key),
103 None => key,
104 };
105 req_builder = req_builder.header("Authorization", value);
106 };
107
108 let req = req_builder.build()?;
109 let resp = configuration.client.execute(req).await?;
110
111 let status = resp.status();
112 let content_type = resp
113 .headers()
114 .get("content-type")
115 .and_then(|v| v.to_str().ok())
116 .unwrap_or("application/octet-stream");
117 let content_type = super::ContentType::from(content_type);
118
119 if !status.is_client_error() && !status.is_server_error() {
120 let content = resp.text().await?;
121 match content_type {
122 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
123 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DisableTaxonomy200Response`"))),
124 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::DisableTaxonomy200Response`")))),
125 }
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<DisableTaxonomyError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent { status, content, entity }))
130 }
131}
132
133pub async fn enable_taxonomy(configuration: &configuration::Configuration, taxonomy_id: &str) -> Result<models::EnableTaxonomy200Response, Error<EnableTaxonomyError>> {
134 let p_taxonomy_id = taxonomy_id;
136
137 let uri_str = format!("{}/taxonomies/enable/{taxonomyId}", configuration.base_path, taxonomyId=crate::apis::urlencode(p_taxonomy_id));
138 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 if let Some(ref apikey) = configuration.api_key {
144 let key = apikey.key.clone();
145 let value = match apikey.prefix {
146 Some(ref prefix) => format!("{} {}", prefix, key),
147 None => key,
148 };
149 req_builder = req_builder.header("Authorization", value);
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EnableTaxonomy200Response`"))),
168 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::EnableTaxonomy200Response`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<EnableTaxonomyError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176
177pub async fn export_taxonomy(configuration: &configuration::Configuration, taxonomy_id: &str) -> Result<models::ExportTaxonomy200Response, Error<ExportTaxonomyError>> {
178 let p_taxonomy_id = taxonomy_id;
180
181 let uri_str = format!("{}/taxonomies/export/{taxonomyId}", configuration.base_path, taxonomyId=crate::apis::urlencode(p_taxonomy_id));
182 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184 if let Some(ref user_agent) = configuration.user_agent {
185 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186 }
187 if let Some(ref apikey) = configuration.api_key {
188 let key = apikey.key.clone();
189 let value = match apikey.prefix {
190 Some(ref prefix) => format!("{} {}", prefix, key),
191 None => key,
192 };
193 req_builder = req_builder.header("Authorization", value);
194 };
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExportTaxonomy200Response`"))),
212 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::ExportTaxonomy200Response`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<ExportTaxonomyError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent { status, content, entity }))
218 }
219}
220
221pub async fn get_taxonomies(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetTaxonomies200ResponseInner>, Error<GetTaxonomiesError>> {
222
223 let uri_str = format!("{}/taxonomies", configuration.base_path);
224 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226 if let Some(ref user_agent) = configuration.user_agent {
227 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228 }
229 if let Some(ref apikey) = configuration.api_key {
230 let key = apikey.key.clone();
231 let value = match apikey.prefix {
232 Some(ref prefix) => format!("{} {}", prefix, key),
233 None => key,
234 };
235 req_builder = req_builder.header("Authorization", value);
236 };
237
238 let req = req_builder.build()?;
239 let resp = configuration.client.execute(req).await?;
240
241 let status = resp.status();
242 let content_type = resp
243 .headers()
244 .get("content-type")
245 .and_then(|v| v.to_str().ok())
246 .unwrap_or("application/octet-stream");
247 let content_type = super::ContentType::from(content_type);
248
249 if !status.is_client_error() && !status.is_server_error() {
250 let content = resp.text().await?;
251 match content_type {
252 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GetTaxonomies200ResponseInner>`"))),
254 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::GetTaxonomies200ResponseInner>`")))),
255 }
256 } else {
257 let content = resp.text().await?;
258 let entity: Option<GetTaxonomiesError> = serde_json::from_str(&content).ok();
259 Err(Error::ResponseError(ResponseContent { status, content, entity }))
260 }
261}
262
263pub async fn get_taxonomy_by_id(configuration: &configuration::Configuration, taxonomy_id: &str) -> Result<models::GetTaxonomyById200Response, Error<GetTaxonomyByIdError>> {
264 let p_taxonomy_id = taxonomy_id;
266
267 let uri_str = format!("{}/taxonomies/view/{taxonomyId}", configuration.base_path, taxonomyId=crate::apis::urlencode(p_taxonomy_id));
268 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
269
270 if let Some(ref user_agent) = configuration.user_agent {
271 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272 }
273 if let Some(ref apikey) = configuration.api_key {
274 let key = apikey.key.clone();
275 let value = match apikey.prefix {
276 Some(ref prefix) => format!("{} {}", prefix, key),
277 None => key,
278 };
279 req_builder = req_builder.header("Authorization", value);
280 };
281
282 let req = req_builder.build()?;
283 let resp = configuration.client.execute(req).await?;
284
285 let status = resp.status();
286 let content_type = resp
287 .headers()
288 .get("content-type")
289 .and_then(|v| v.to_str().ok())
290 .unwrap_or("application/octet-stream");
291 let content_type = super::ContentType::from(content_type);
292
293 if !status.is_client_error() && !status.is_server_error() {
294 let content = resp.text().await?;
295 match content_type {
296 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
297 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTaxonomyById200Response`"))),
298 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::GetTaxonomyById200Response`")))),
299 }
300 } else {
301 let content = resp.text().await?;
302 let entity: Option<GetTaxonomyByIdError> = serde_json::from_str(&content).ok();
303 Err(Error::ResponseError(ResponseContent { status, content, entity }))
304 }
305}
306
307pub async fn get_taxonomy_tags(configuration: &configuration::Configuration, taxonomy_id: &str) -> Result<models::GetTaxonomyTags200Response, Error<GetTaxonomyTagsError>> {
308 let p_taxonomy_id = taxonomy_id;
310
311 let uri_str = format!("{}/taxonomies/taxonomy_tags/{taxonomyId}", configuration.base_path, taxonomyId=crate::apis::urlencode(p_taxonomy_id));
312 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
313
314 if let Some(ref user_agent) = configuration.user_agent {
315 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316 }
317 if let Some(ref apikey) = configuration.api_key {
318 let key = apikey.key.clone();
319 let value = match apikey.prefix {
320 Some(ref prefix) => format!("{} {}", prefix, key),
321 None => key,
322 };
323 req_builder = req_builder.header("Authorization", value);
324 };
325
326 let req = req_builder.build()?;
327 let resp = configuration.client.execute(req).await?;
328
329 let status = resp.status();
330 let content_type = resp
331 .headers()
332 .get("content-type")
333 .and_then(|v| v.to_str().ok())
334 .unwrap_or("application/octet-stream");
335 let content_type = super::ContentType::from(content_type);
336
337 if !status.is_client_error() && !status.is_server_error() {
338 let content = resp.text().await?;
339 match content_type {
340 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
341 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTaxonomyTags200Response`"))),
342 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::GetTaxonomyTags200Response`")))),
343 }
344 } else {
345 let content = resp.text().await?;
346 let entity: Option<GetTaxonomyTagsError> = serde_json::from_str(&content).ok();
347 Err(Error::ResponseError(ResponseContent { status, content, entity }))
348 }
349}
350
351pub async fn update_taxonomies(configuration: &configuration::Configuration, ) -> Result<models::UpdateTaxonomies200Response, Error<UpdateTaxonomiesError>> {
352
353 let uri_str = format!("{}/taxonomies/update", configuration.base_path);
354 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
355
356 if let Some(ref user_agent) = configuration.user_agent {
357 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
358 }
359 if let Some(ref apikey) = configuration.api_key {
360 let key = apikey.key.clone();
361 let value = match apikey.prefix {
362 Some(ref prefix) => format!("{} {}", prefix, key),
363 None => key,
364 };
365 req_builder = req_builder.header("Authorization", value);
366 };
367
368 let req = req_builder.build()?;
369 let resp = configuration.client.execute(req).await?;
370
371 let status = resp.status();
372 let content_type = resp
373 .headers()
374 .get("content-type")
375 .and_then(|v| v.to_str().ok())
376 .unwrap_or("application/octet-stream");
377 let content_type = super::ContentType::from(content_type);
378
379 if !status.is_client_error() && !status.is_server_error() {
380 let content = resp.text().await?;
381 match content_type {
382 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
383 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateTaxonomies200Response`"))),
384 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::UpdateTaxonomies200Response`")))),
385 }
386 } else {
387 let content = resp.text().await?;
388 let entity: Option<UpdateTaxonomiesError> = serde_json::from_str(&content).ok();
389 Err(Error::ResponseError(ResponseContent { status, content, entity }))
390 }
391}
392