hanzo_client/apis/
help_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 GetHelpArticlesError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetHelpArticlesBySlugError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetHelpCategoriesError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostHelpTicketsError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn get_help_articles(configuration: &configuration::Configuration, category: Option<&str>, limit: Option<i32>) -> Result<models::HelpArticleList, Error<GetHelpArticlesError>> {
49 let p_category = category;
51 let p_limit = limit;
52
53 let uri_str = format!("{}/v1/help/articles", configuration.base_path);
54 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
55
56 if let Some(ref param_value) = p_category {
57 req_builder = req_builder.query(&[("category", ¶m_value.to_string())]);
58 }
59 if let Some(ref param_value) = p_limit {
60 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
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::HelpArticleList`"))),
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::HelpArticleList`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<GetHelpArticlesError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent { status, content, entity }))
91 }
92}
93
94pub async fn get_help_articles_by_slug(configuration: &configuration::Configuration, slug: &str) -> Result<models::HelpArticle, Error<GetHelpArticlesBySlugError>> {
96 let p_slug = slug;
98
99 let uri_str = format!("{}/v1/help/articles/{slug}", configuration.base_path, slug=crate::apis::urlencode(p_slug));
100 let mut req_builder = configuration.client.request(reqwest::Method::GET, &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::HelpArticle`"))),
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::HelpArticle`")))),
126 }
127 } else {
128 let content = resp.text().await?;
129 let entity: Option<GetHelpArticlesBySlugError> = serde_json::from_str(&content).ok();
130 Err(Error::ResponseError(ResponseContent { status, content, entity }))
131 }
132}
133
134pub async fn get_help_categories(configuration: &configuration::Configuration, ) -> Result<models::HelpCategoryList, Error<GetHelpCategoriesError>> {
136
137 let uri_str = format!("{}/v1/help/categories", configuration.base_path);
138 let mut req_builder = configuration.client.request(reqwest::Method::GET, &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 token) = configuration.bearer_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::HelpCategoryList`"))),
163 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::HelpCategoryList`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<GetHelpCategoriesError> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent { status, content, entity }))
169 }
170}
171
172pub async fn post_help_tickets(configuration: &configuration::Configuration, help_ticket_intake: models::HelpTicketIntake) -> Result<models::HelpTicketFiled, Error<PostHelpTicketsError>> {
174 let p_help_ticket_intake = help_ticket_intake;
176
177 let uri_str = format!("{}/v1/help/tickets", configuration.base_path);
178 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
179
180 if let Some(ref user_agent) = configuration.user_agent {
181 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182 }
183 if let Some(ref token) = configuration.bearer_access_token {
184 req_builder = req_builder.bearer_auth(token.to_owned());
185 };
186 req_builder = req_builder.json(&p_help_ticket_intake);
187
188 let req = req_builder.build()?;
189 let resp = configuration.client.execute(req).await?;
190
191 let status = resp.status();
192 let content_type = resp
193 .headers()
194 .get("content-type")
195 .and_then(|v| v.to_str().ok())
196 .unwrap_or("application/octet-stream");
197 let content_type = super::ContentType::from(content_type);
198
199 if !status.is_client_error() && !status.is_server_error() {
200 let content = resp.text().await?;
201 match content_type {
202 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
203 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::HelpTicketFiled`"))),
204 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::HelpTicketFiled`")))),
205 }
206 } else {
207 let content = resp.text().await?;
208 let entity: Option<PostHelpTicketsError> = serde_json::from_str(&content).ok();
209 Err(Error::ResponseError(ResponseContent { status, content, entity }))
210 }
211}
212