hanzo_client/apis/
taxonomy_api.rs1use 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 DeleteTaxonomyCategoriesByIdError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteTaxonomyTaxaByIdError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetTaxonomyError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PutTaxonomyCategoriesByIdError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutTaxonomyTaxaByIdError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn delete_taxonomy_categories_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Deleted, Error<DeleteTaxonomyCategoriesByIdError>> {
56 let p_id = id;
58
59 let uri_str = format!("{}/v1/taxonomy/categories/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
60 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
61
62 if let Some(ref user_agent) = configuration.user_agent {
63 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64 }
65 if let Some(ref token) = configuration.bearer_access_token {
66 req_builder = req_builder.bearer_auth(token.to_owned());
67 };
68
69 let req = req_builder.build()?;
70 let resp = configuration.client.execute(req).await?;
71
72 let status = resp.status();
73 let content_type = resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let content_type = super::ContentType::from(content_type);
79
80 if !status.is_client_error() && !status.is_server_error() {
81 let content = resp.text().await?;
82 match content_type {
83 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Deleted`"))),
85 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::Deleted`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<DeleteTaxonomyCategoriesByIdError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent { status, content, entity }))
91 }
92}
93
94pub async fn delete_taxonomy_taxa_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Deleted, Error<DeleteTaxonomyTaxaByIdError>> {
96 let p_id = id;
98
99 let uri_str = format!("{}/v1/taxonomy/taxa/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
100 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
101
102 if let Some(ref user_agent) = configuration.user_agent {
103 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104 }
105 if let Some(ref token) = configuration.bearer_access_token {
106 req_builder = req_builder.bearer_auth(token.to_owned());
107 };
108
109 let req = req_builder.build()?;
110 let resp = configuration.client.execute(req).await?;
111
112 let status = resp.status();
113 let content_type = resp
114 .headers()
115 .get("content-type")
116 .and_then(|v| v.to_str().ok())
117 .unwrap_or("application/octet-stream");
118 let content_type = super::ContentType::from(content_type);
119
120 if !status.is_client_error() && !status.is_server_error() {
121 let content = resp.text().await?;
122 match content_type {
123 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
124 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Deleted`"))),
125 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::Deleted`")))),
126 }
127 } else {
128 let content = resp.text().await?;
129 let entity: Option<DeleteTaxonomyTaxaByIdError> = serde_json::from_str(&content).ok();
130 Err(Error::ResponseError(ResponseContent { status, content, entity }))
131 }
132}
133
134pub async fn get_taxonomy(configuration: &configuration::Configuration, brand: Option<&str>) -> Result<models::Taxonomy, Error<GetTaxonomyError>> {
136 let p_brand = brand;
138
139 let uri_str = format!("{}/v1/taxonomy", configuration.base_path);
140 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
141
142 if let Some(ref param_value) = p_brand {
143 req_builder = req_builder.query(&[("brand", ¶m_value.to_string())]);
144 }
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref token) = configuration.bearer_access_token {
149 req_builder = req_builder.bearer_auth(token.to_owned());
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::Taxonomy`"))),
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::Taxonomy`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<GetTaxonomyError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176
177pub async fn put_taxonomy_categories_by_id(configuration: &configuration::Configuration, id: &str, category_in: models::CategoryIn) -> Result<models::Category, Error<PutTaxonomyCategoriesByIdError>> {
179 let p_id = id;
181 let p_category_in = category_in;
182
183 let uri_str = format!("{}/v1/taxonomy/categories/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
184 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
185
186 if let Some(ref user_agent) = configuration.user_agent {
187 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188 }
189 if let Some(ref token) = configuration.bearer_access_token {
190 req_builder = req_builder.bearer_auth(token.to_owned());
191 };
192 req_builder = req_builder.json(&p_category_in);
193
194 let req = req_builder.build()?;
195 let resp = configuration.client.execute(req).await?;
196
197 let status = resp.status();
198 let content_type = resp
199 .headers()
200 .get("content-type")
201 .and_then(|v| v.to_str().ok())
202 .unwrap_or("application/octet-stream");
203 let content_type = super::ContentType::from(content_type);
204
205 if !status.is_client_error() && !status.is_server_error() {
206 let content = resp.text().await?;
207 match content_type {
208 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Category`"))),
210 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::Category`")))),
211 }
212 } else {
213 let content = resp.text().await?;
214 let entity: Option<PutTaxonomyCategoriesByIdError> = serde_json::from_str(&content).ok();
215 Err(Error::ResponseError(ResponseContent { status, content, entity }))
216 }
217}
218
219pub async fn put_taxonomy_taxa_by_id(configuration: &configuration::Configuration, id: &str, taxon_in: models::TaxonIn) -> Result<models::Taxon, Error<PutTaxonomyTaxaByIdError>> {
221 let p_id = id;
223 let p_taxon_in = taxon_in;
224
225 let uri_str = format!("{}/v1/taxonomy/taxa/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
226 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
227
228 if let Some(ref user_agent) = configuration.user_agent {
229 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
230 }
231 if let Some(ref token) = configuration.bearer_access_token {
232 req_builder = req_builder.bearer_auth(token.to_owned());
233 };
234 req_builder = req_builder.json(&p_taxon_in);
235
236 let req = req_builder.build()?;
237 let resp = configuration.client.execute(req).await?;
238
239 let status = resp.status();
240 let content_type = resp
241 .headers()
242 .get("content-type")
243 .and_then(|v| v.to_str().ok())
244 .unwrap_or("application/octet-stream");
245 let content_type = super::ContentType::from(content_type);
246
247 if !status.is_client_error() && !status.is_server_error() {
248 let content = resp.text().await?;
249 match content_type {
250 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
251 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Taxon`"))),
252 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::Taxon`")))),
253 }
254 } else {
255 let content = resp.text().await?;
256 let entity: Option<PutTaxonomyTaxaByIdError> = serde_json::from_str(&content).ok();
257 Err(Error::ResponseError(ResponseContent { status, content, entity }))
258 }
259}
260