hab_rs_api_client/apis/
inbox_api.rs

1/*
2 * openHAB REST API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 8
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{Error, configuration};
12use crate::apis::ContentType;
13use crate::{apis::ResponseContent, models};
14use async_trait::async_trait;
15#[cfg(feature = "mockall")]
16use mockall::automock;
17use reqwest;
18use serde::{Deserialize, Serialize, de::Error as _};
19use std::sync::Arc;
20
21#[cfg_attr(feature = "mockall", automock)]
22#[async_trait]
23pub trait InboxApi: Send + Sync {
24    /// POST /inbox/{thingUID}/approve
25    ///
26    ///
27    async fn approve_inbox_item_by_id<'thing_uid, 'accept_language, 'new_thing_id, 'body>(
28        &self,
29        thing_uid: &'thing_uid str,
30        accept_language: Option<&'accept_language str>,
31        new_thing_id: Option<&'new_thing_id str>,
32        body: Option<&'body str>,
33    ) -> Result<(), Error<ApproveInboxItemByIdError>>;
34
35    /// POST /inbox/{thingUID}/ignore
36    ///
37    ///
38    async fn flag_inbox_item_as_ignored<'thing_uid>(
39        &self,
40        thing_uid: &'thing_uid str,
41    ) -> Result<(), Error<FlagInboxItemAsIgnoredError>>;
42
43    /// GET /inbox
44    ///
45    ///
46    async fn get_discovered_inbox_items<'include_ignored>(
47        &self,
48        include_ignored: Option<bool>,
49    ) -> Result<Vec<models::DiscoveryResultDto>, Error<GetDiscoveredInboxItemsError>>;
50
51    /// POST /inbox/{thingUID}/unignore
52    ///
53    ///
54    async fn remove_ignore_flag_on_inbox_item<'thing_uid>(
55        &self,
56        thing_uid: &'thing_uid str,
57    ) -> Result<(), Error<RemoveIgnoreFlagOnInboxItemError>>;
58
59    /// DELETE /inbox/{thingUID}
60    ///
61    ///
62    async fn remove_item_from_inbox<'thing_uid>(
63        &self,
64        thing_uid: &'thing_uid str,
65    ) -> Result<(), Error<RemoveItemFromInboxError>>;
66}
67
68pub struct InboxApiClient {
69    configuration: Arc<configuration::Configuration>,
70}
71
72impl InboxApiClient {
73    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
74        Self { configuration }
75    }
76}
77
78#[async_trait]
79impl InboxApi for InboxApiClient {
80    async fn approve_inbox_item_by_id<'thing_uid, 'accept_language, 'new_thing_id, 'body>(
81        &self,
82        thing_uid: &'thing_uid str,
83        accept_language: Option<&'accept_language str>,
84        new_thing_id: Option<&'new_thing_id str>,
85        body: Option<&'body str>,
86    ) -> Result<(), Error<ApproveInboxItemByIdError>> {
87        let local_var_configuration = &self.configuration;
88
89        let local_var_client = &local_var_configuration.client;
90
91        let local_var_uri_str = format!(
92            "{}/inbox/{thingUID}/approve",
93            local_var_configuration.base_path,
94            thingUID = crate::apis::urlencode(thing_uid)
95        );
96        let mut local_var_req_builder =
97            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99        if let Some(ref local_var_str) = new_thing_id {
100            local_var_req_builder =
101                local_var_req_builder.query(&[("newThingId", &local_var_str.to_string())]);
102        }
103        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
104            local_var_req_builder = local_var_req_builder
105                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106        }
107        if let Some(local_var_param_value) = accept_language {
108            local_var_req_builder =
109                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
110        }
111        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
112            local_var_req_builder = local_var_req_builder.basic_auth(
113                local_var_auth_conf.0.to_owned(),
114                local_var_auth_conf.1.to_owned(),
115            );
116        };
117        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
118            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
119        };
120        if let Some(body) = body {
121            local_var_req_builder = local_var_req_builder.body(body.to_string());
122            local_var_req_builder = local_var_req_builder.header(
123                reqwest::header::CONTENT_TYPE,
124                reqwest::header::HeaderValue::from_static("text/plain"),
125            );
126        }
127
128        let local_var_req = local_var_req_builder.build()?;
129        let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131        let local_var_status = local_var_resp.status();
132        let local_var_content = local_var_resp.text().await?;
133
134        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135            Ok(())
136        } else {
137            let local_var_entity: Option<ApproveInboxItemByIdError> =
138                serde_json::from_str(&local_var_content).ok();
139            let local_var_error = ResponseContent {
140                status: local_var_status,
141                content: local_var_content,
142                entity: local_var_entity,
143            };
144            Err(Error::ResponseError(local_var_error))
145        }
146    }
147
148    async fn flag_inbox_item_as_ignored<'thing_uid>(
149        &self,
150        thing_uid: &'thing_uid str,
151    ) -> Result<(), Error<FlagInboxItemAsIgnoredError>> {
152        let local_var_configuration = &self.configuration;
153
154        let local_var_client = &local_var_configuration.client;
155
156        let local_var_uri_str = format!(
157            "{}/inbox/{thingUID}/ignore",
158            local_var_configuration.base_path,
159            thingUID = crate::apis::urlencode(thing_uid)
160        );
161        let mut local_var_req_builder =
162            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
163
164        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
165            local_var_req_builder = local_var_req_builder
166                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167        }
168        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
169            local_var_req_builder = local_var_req_builder.basic_auth(
170                local_var_auth_conf.0.to_owned(),
171                local_var_auth_conf.1.to_owned(),
172            );
173        };
174        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
175            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
176        };
177
178        let local_var_req = local_var_req_builder.build()?;
179        let local_var_resp = local_var_client.execute(local_var_req).await?;
180
181        let local_var_status = local_var_resp.status();
182        let local_var_content = local_var_resp.text().await?;
183
184        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
185            Ok(())
186        } else {
187            let local_var_entity: Option<FlagInboxItemAsIgnoredError> =
188                serde_json::from_str(&local_var_content).ok();
189            let local_var_error = ResponseContent {
190                status: local_var_status,
191                content: local_var_content,
192                entity: local_var_entity,
193            };
194            Err(Error::ResponseError(local_var_error))
195        }
196    }
197
198    async fn get_discovered_inbox_items<'include_ignored>(
199        &self,
200        include_ignored: Option<bool>,
201    ) -> Result<Vec<models::DiscoveryResultDto>, Error<GetDiscoveredInboxItemsError>> {
202        let local_var_configuration = &self.configuration;
203
204        let local_var_client = &local_var_configuration.client;
205
206        let local_var_uri_str = format!("{}/inbox", local_var_configuration.base_path);
207        let mut local_var_req_builder =
208            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
209
210        if let Some(ref local_var_str) = include_ignored {
211            local_var_req_builder =
212                local_var_req_builder.query(&[("includeIgnored", &local_var_str.to_string())]);
213        }
214        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215            local_var_req_builder = local_var_req_builder
216                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
217        }
218        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
219            local_var_req_builder = local_var_req_builder.basic_auth(
220                local_var_auth_conf.0.to_owned(),
221                local_var_auth_conf.1.to_owned(),
222            );
223        };
224        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
225            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226        };
227
228        let local_var_req = local_var_req_builder.build()?;
229        let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231        let local_var_status = local_var_resp.status();
232        let local_var_content_type = local_var_resp
233            .headers()
234            .get("content-type")
235            .and_then(|v| v.to_str().ok())
236            .unwrap_or("application/octet-stream");
237        let local_var_content_type = super::ContentType::from(local_var_content_type);
238        let local_var_content = local_var_resp.text().await?;
239
240        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241            match local_var_content_type {
242                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
243                ContentType::Text => {
244                    return Err(Error::from(serde_json::Error::custom(
245                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::DiscoveryResultDto&gt;`",
246                    )));
247                }
248                ContentType::Unsupported(local_var_unknown_type) => {
249                    return Err(Error::from(serde_json::Error::custom(format!(
250                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::DiscoveryResultDto&gt;`"
251                    ))));
252                }
253            }
254        } else {
255            let local_var_entity: Option<GetDiscoveredInboxItemsError> =
256                serde_json::from_str(&local_var_content).ok();
257            let local_var_error = ResponseContent {
258                status: local_var_status,
259                content: local_var_content,
260                entity: local_var_entity,
261            };
262            Err(Error::ResponseError(local_var_error))
263        }
264    }
265
266    async fn remove_ignore_flag_on_inbox_item<'thing_uid>(
267        &self,
268        thing_uid: &'thing_uid str,
269    ) -> Result<(), Error<RemoveIgnoreFlagOnInboxItemError>> {
270        let local_var_configuration = &self.configuration;
271
272        let local_var_client = &local_var_configuration.client;
273
274        let local_var_uri_str = format!(
275            "{}/inbox/{thingUID}/unignore",
276            local_var_configuration.base_path,
277            thingUID = crate::apis::urlencode(thing_uid)
278        );
279        let mut local_var_req_builder =
280            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
281
282        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283            local_var_req_builder = local_var_req_builder
284                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
285        }
286        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
287            local_var_req_builder = local_var_req_builder.basic_auth(
288                local_var_auth_conf.0.to_owned(),
289                local_var_auth_conf.1.to_owned(),
290            );
291        };
292        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
293            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
294        };
295
296        let local_var_req = local_var_req_builder.build()?;
297        let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299        let local_var_status = local_var_resp.status();
300        let local_var_content = local_var_resp.text().await?;
301
302        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303            Ok(())
304        } else {
305            let local_var_entity: Option<RemoveIgnoreFlagOnInboxItemError> =
306                serde_json::from_str(&local_var_content).ok();
307            let local_var_error = ResponseContent {
308                status: local_var_status,
309                content: local_var_content,
310                entity: local_var_entity,
311            };
312            Err(Error::ResponseError(local_var_error))
313        }
314    }
315
316    async fn remove_item_from_inbox<'thing_uid>(
317        &self,
318        thing_uid: &'thing_uid str,
319    ) -> Result<(), Error<RemoveItemFromInboxError>> {
320        let local_var_configuration = &self.configuration;
321
322        let local_var_client = &local_var_configuration.client;
323
324        let local_var_uri_str = format!(
325            "{}/inbox/{thingUID}",
326            local_var_configuration.base_path,
327            thingUID = crate::apis::urlencode(thing_uid)
328        );
329        let mut local_var_req_builder =
330            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
331
332        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
333            local_var_req_builder = local_var_req_builder
334                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
335        }
336        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
337            local_var_req_builder = local_var_req_builder.basic_auth(
338                local_var_auth_conf.0.to_owned(),
339                local_var_auth_conf.1.to_owned(),
340            );
341        };
342        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
343            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
344        };
345
346        let local_var_req = local_var_req_builder.build()?;
347        let local_var_resp = local_var_client.execute(local_var_req).await?;
348
349        let local_var_status = local_var_resp.status();
350        let local_var_content = local_var_resp.text().await?;
351
352        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
353            Ok(())
354        } else {
355            let local_var_entity: Option<RemoveItemFromInboxError> =
356                serde_json::from_str(&local_var_content).ok();
357            let local_var_error = ResponseContent {
358                status: local_var_status,
359                content: local_var_content,
360                entity: local_var_entity,
361            };
362            Err(Error::ResponseError(local_var_error))
363        }
364    }
365}
366
367/// struct for typed errors of method [InboxApi::approve_inbox_item_by_id]
368#[derive(Debug, Clone, Serialize, Deserialize)]
369#[serde(untagged)]
370pub enum ApproveInboxItemByIdError {
371    Status400(),
372    Status404(),
373    Status409(),
374    UnknownValue(serde_json::Value),
375}
376
377/// struct for typed errors of method [InboxApi::flag_inbox_item_as_ignored]
378#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum FlagInboxItemAsIgnoredError {
381    UnknownValue(serde_json::Value),
382}
383
384/// struct for typed errors of method [InboxApi::get_discovered_inbox_items]
385#[derive(Debug, Clone, Serialize, Deserialize)]
386#[serde(untagged)]
387pub enum GetDiscoveredInboxItemsError {
388    UnknownValue(serde_json::Value),
389}
390
391/// struct for typed errors of method [InboxApi::remove_ignore_flag_on_inbox_item]
392#[derive(Debug, Clone, Serialize, Deserialize)]
393#[serde(untagged)]
394pub enum RemoveIgnoreFlagOnInboxItemError {
395    UnknownValue(serde_json::Value),
396}
397
398/// struct for typed errors of method [InboxApi::remove_item_from_inbox]
399#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(untagged)]
401pub enum RemoveItemFromInboxError {
402    Status404(),
403    UnknownValue(serde_json::Value),
404}