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 GetInboxCountsError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ListInboxError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum MarkInboxItemReadError {
38 Status401(models::ApiError),
39 Status404(models::ApiError),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum WorkspaceGetInboxCountsError {
47 Status401(models::ApiError),
48 Status403(models::ApiError),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum WorkspaceListInboxError {
56 Status401(models::ApiError),
57 Status403(models::ApiError),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum WorkspaceMarkInboxItemReadError {
65 Status401(models::ApiError),
66 Status403(models::ApiError),
67 UnknownValue(serde_json::Value),
68}
69
70
71pub async fn get_inbox_counts(configuration: &configuration::Configuration, ) -> Result<models::InboxCounts, Error<GetInboxCountsError>> {
72
73 let uri_str = format!("{}/v1/inbox/counts", configuration.base_path);
74 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
75
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(ref token) = configuration.bearer_access_token {
80 req_builder = req_builder.bearer_auth(token.to_owned());
81 };
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InboxCounts`"))),
99 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::InboxCounts`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<GetInboxCountsError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107
108pub async fn list_inbox(configuration: &configuration::Configuration, category: Option<&str>, unread_only: Option<bool>, limit: Option<i32>) -> Result<models::InboxListResponse, Error<ListInboxError>> {
109 let p_query_category = category;
111 let p_query_unread_only = unread_only;
112 let p_query_limit = limit;
113
114 let uri_str = format!("{}/v1/inbox", configuration.base_path);
115 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
116
117 if let Some(ref param_value) = p_query_category {
118 req_builder = req_builder.query(&[("category", ¶m_value.to_string())]);
119 }
120 if let Some(ref param_value) = p_query_unread_only {
121 req_builder = req_builder.query(&[("unreadOnly", ¶m_value.to_string())]);
122 }
123 if let Some(ref param_value) = p_query_limit {
124 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
125 }
126 if let Some(ref user_agent) = configuration.user_agent {
127 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128 }
129 if let Some(ref token) = configuration.bearer_access_token {
130 req_builder = req_builder.bearer_auth(token.to_owned());
131 };
132
133 let req = req_builder.build()?;
134 let resp = configuration.client.execute(req).await?;
135
136 let status = resp.status();
137 let content_type = resp
138 .headers()
139 .get("content-type")
140 .and_then(|v| v.to_str().ok())
141 .unwrap_or("application/octet-stream");
142 let content_type = super::ContentType::from(content_type);
143
144 if !status.is_client_error() && !status.is_server_error() {
145 let content = resp.text().await?;
146 match content_type {
147 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InboxListResponse`"))),
149 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::InboxListResponse`")))),
150 }
151 } else {
152 let content = resp.text().await?;
153 let entity: Option<ListInboxError> = serde_json::from_str(&content).ok();
154 Err(Error::ResponseError(ResponseContent { status, content, entity }))
155 }
156}
157
158pub async fn mark_inbox_item_read(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<MarkInboxItemReadError>> {
159 let p_path_id = id;
161
162 let uri_str = format!("{}/v1/inbox/{id}/read", configuration.base_path, id=crate::apis::urlencode(p_path_id));
163 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
164
165 if let Some(ref user_agent) = configuration.user_agent {
166 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167 }
168 if let Some(ref token) = configuration.bearer_access_token {
169 req_builder = req_builder.bearer_auth(token.to_owned());
170 };
171
172 let req = req_builder.build()?;
173 let resp = configuration.client.execute(req).await?;
174
175 let status = resp.status();
176
177 if !status.is_client_error() && !status.is_server_error() {
178 Ok(())
179 } else {
180 let content = resp.text().await?;
181 let entity: Option<MarkInboxItemReadError> = serde_json::from_str(&content).ok();
182 Err(Error::ResponseError(ResponseContent { status, content, entity }))
183 }
184}
185
186pub async fn workspace_get_inbox_counts(configuration: &configuration::Configuration, org: &str, workspace: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceGetInboxCountsError>> {
187 let p_path_org = org;
189 let p_path_workspace = workspace;
190
191 let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/inbox/counts", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
192 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
193
194 if let Some(ref user_agent) = configuration.user_agent {
195 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196 }
197 if let Some(ref token) = configuration.bearer_access_token {
198 req_builder = req_builder.bearer_auth(token.to_owned());
199 };
200
201 let req = req_builder.build()?;
202 let resp = configuration.client.execute(req).await?;
203
204 let status = resp.status();
205 let content_type = resp
206 .headers()
207 .get("content-type")
208 .and_then(|v| v.to_str().ok())
209 .unwrap_or("application/octet-stream");
210 let content_type = super::ContentType::from(content_type);
211
212 if !status.is_client_error() && !status.is_server_error() {
213 let content = resp.text().await?;
214 match content_type {
215 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
216 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
217 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
218 }
219 } else {
220 let content = resp.text().await?;
221 let entity: Option<WorkspaceGetInboxCountsError> = serde_json::from_str(&content).ok();
222 Err(Error::ResponseError(ResponseContent { status, content, entity }))
223 }
224}
225
226pub async fn workspace_list_inbox(configuration: &configuration::Configuration, org: &str, workspace: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceListInboxError>> {
227 let p_path_org = org;
229 let p_path_workspace = workspace;
230
231 let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/inbox", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
232 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
233
234 if let Some(ref user_agent) = configuration.user_agent {
235 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236 }
237 if let Some(ref token) = configuration.bearer_access_token {
238 req_builder = req_builder.bearer_auth(token.to_owned());
239 };
240
241 let req = req_builder.build()?;
242 let resp = configuration.client.execute(req).await?;
243
244 let status = resp.status();
245 let content_type = resp
246 .headers()
247 .get("content-type")
248 .and_then(|v| v.to_str().ok())
249 .unwrap_or("application/octet-stream");
250 let content_type = super::ContentType::from(content_type);
251
252 if !status.is_client_error() && !status.is_server_error() {
253 let content = resp.text().await?;
254 match content_type {
255 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
257 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
258 }
259 } else {
260 let content = resp.text().await?;
261 let entity: Option<WorkspaceListInboxError> = serde_json::from_str(&content).ok();
262 Err(Error::ResponseError(ResponseContent { status, content, entity }))
263 }
264}
265
266pub async fn workspace_mark_inbox_item_read(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str) -> Result<(), Error<WorkspaceMarkInboxItemReadError>> {
267 let p_path_org = org;
269 let p_path_workspace = workspace;
270 let p_path_id = id;
271
272 let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/inbox/{id}/read", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
273 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
274
275 if let Some(ref user_agent) = configuration.user_agent {
276 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
277 }
278 if let Some(ref token) = configuration.bearer_access_token {
279 req_builder = req_builder.bearer_auth(token.to_owned());
280 };
281
282 let req = req_builder.build()?;
283 let resp = configuration.client.execute(req).await?;
284
285 let status = resp.status();
286
287 if !status.is_client_error() && !status.is_server_error() {
288 Ok(())
289 } else {
290 let content = resp.text().await?;
291 let entity: Option<WorkspaceMarkInboxItemReadError> = serde_json::from_str(&content).ok();
292 Err(Error::ResponseError(ResponseContent { status, content, entity }))
293 }
294}
295