hanzo_client/apis/
catalog_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 GetCatalogError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn get_catalog(configuration: &configuration::Configuration, q: Option<&str>, org: Option<&str>, kind: Option<&str>, origin: Option<&str>, archetype: Option<&str>, language: Option<&str>, template: Option<&str>, forkable: Option<&str>, limit: Option<&str>, offset: Option<&str>) -> Result<models::CatalogPage, Error<GetCatalogError>> {
28 let p_q = q;
30 let p_org = org;
31 let p_kind = kind;
32 let p_origin = origin;
33 let p_archetype = archetype;
34 let p_language = language;
35 let p_template = template;
36 let p_forkable = forkable;
37 let p_limit = limit;
38 let p_offset = offset;
39
40 let uri_str = format!("{}/v1/catalog", configuration.base_path);
41 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
42
43 if let Some(ref param_value) = p_q {
44 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
45 }
46 if let Some(ref param_value) = p_org {
47 req_builder = req_builder.query(&[("org", ¶m_value.to_string())]);
48 }
49 if let Some(ref param_value) = p_kind {
50 req_builder = req_builder.query(&[("kind", ¶m_value.to_string())]);
51 }
52 if let Some(ref param_value) = p_origin {
53 req_builder = req_builder.query(&[("origin", ¶m_value.to_string())]);
54 }
55 if let Some(ref param_value) = p_archetype {
56 req_builder = req_builder.query(&[("archetype", ¶m_value.to_string())]);
57 }
58 if let Some(ref param_value) = p_language {
59 req_builder = req_builder.query(&[("language", ¶m_value.to_string())]);
60 }
61 if let Some(ref param_value) = p_template {
62 req_builder = req_builder.query(&[("template", ¶m_value.to_string())]);
63 }
64 if let Some(ref param_value) = p_forkable {
65 req_builder = req_builder.query(&[("forkable", ¶m_value.to_string())]);
66 }
67 if let Some(ref param_value) = p_limit {
68 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
69 }
70 if let Some(ref param_value) = p_offset {
71 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
72 }
73 if let Some(ref user_agent) = configuration.user_agent {
74 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75 }
76 if let Some(ref token) = configuration.bearer_access_token {
77 req_builder = req_builder.bearer_auth(token.to_owned());
78 };
79
80 let req = req_builder.build()?;
81 let resp = configuration.client.execute(req).await?;
82
83 let status = resp.status();
84 let content_type = resp
85 .headers()
86 .get("content-type")
87 .and_then(|v| v.to_str().ok())
88 .unwrap_or("application/octet-stream");
89 let content_type = super::ContentType::from(content_type);
90
91 if !status.is_client_error() && !status.is_server_error() {
92 let content = resp.text().await?;
93 match content_type {
94 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
95 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CatalogPage`"))),
96 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::CatalogPage`")))),
97 }
98 } else {
99 let content = resp.text().await?;
100 let entity: Option<GetCatalogError> = serde_json::from_str(&content).ok();
101 Err(Error::ResponseError(ResponseContent { status, content, entity }))
102 }
103}
104