Skip to main content

hanzo_client/apis/
taxonomy_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`delete_taxonomy_categories_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteTaxonomyCategoriesByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_taxonomy_taxa_by_id`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteTaxonomyTaxaByIdError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_taxonomy`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetTaxonomyError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`put_taxonomy_categories_by_id`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PutTaxonomyCategoriesByIdError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`put_taxonomy_taxa_by_id`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutTaxonomyTaxaByIdError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Removes one empty category. A category that still has taxa filed under it is refused with 409 and a count: deleting the label off a group must never silently take the products wearing it, and the alternative — orphan rows naming a category that no longer exists — is a catalogue that cannot be rendered. Move or delete its taxa first. An id no category holds is a 404.
55pub async fn delete_taxonomy_categories_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Deleted, Error<DeleteTaxonomyCategoriesByIdError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    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
94/// Removes one product from the catalogue. An id no taxon holds is a 404. To take a product out of view without losing what was written about it, set `published` to false instead.
95pub async fn delete_taxonomy_taxa_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Deleted, Error<DeleteTaxonomyTaxaByIdError>> {
96    // add a prefix to parameters to efficiently prevent name collisions
97    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
134/// Read returns the product catalogue as this caller sees it: the PLATFORM catalogue — Hanzo's own products, the part that is true for everyone — plus the caller's own org's rows, every category in display order and each carrying the products filed under it in theirs. Another customer's rows are never in it. It is readable signed out, and a signed-out visitor gets the platform catalogue alone, which is what the marketing landing renders from.  Where the caller's org and the platform hold the same id, the caller's own row is the one served. That rule exists because ids are unique per ORG and not globally — two customers may each have a \"crm\", and refusing the second would tell one of them the other exists — so a collision with the platform is possible by construction and something has to win deterministically. Yours does: your own catalogue is the one you edited.  `?brand=` narrows it the way a brand's own console does: only the categories that brand admits, and within them only the taxa scoped to it. An unpublished row is served only to whoever may edit it — a SuperAdmin for the platform's, an org admin for their own — so a product can be staged before anyone sees it without becoming invisible to the person staging it.
135pub async fn get_taxonomy(configuration: &configuration::Configuration, brand: Option<&str>) -> Result<models::Taxonomy, Error<GetTaxonomyError>> {
136    // add a prefix to parameters to efficiently prevent name collisions
137    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", &param_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
177/// Creates or replaces one category and returns it as stored. The id in the URL is the one it is filed under whatever the body says, so a category can never be written under a name it was not addressed by — which also makes create and replace the same act, and is why there is no POST beside this.  Platform SuperAdmin only: one catalogue serves every tenant, so an org admin who could rename a category would rename it for all of them.
178pub async fn put_taxonomy_categories_by_id(configuration: &configuration::Configuration, id: &str, category_in: models::CategoryIn) -> Result<models::Category, Error<PutTaxonomyCategoriesByIdError>> {
179    // add a prefix to parameters to efficiently prevent name collisions
180    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
219/// Creates or replaces one product and returns it as stored. The id in the URL is the one it is filed under whatever the body says. The category must already exist — a taxon naming a category that does not is refused with 400 rather than stored where nothing can render it.  A taxon opens exactly one way: `route` for a product the console renders itself, or `href` for one that genuinely lives at its own domain. Giving both, or neither, is refused.  Platform SuperAdmin only.
220pub async fn put_taxonomy_taxa_by_id(configuration: &configuration::Configuration, id: &str, taxon_in: models::TaxonIn) -> Result<models::Taxon, Error<PutTaxonomyTaxaByIdError>> {
221    // add a prefix to parameters to efficiently prevent name collisions
222    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