hab_rs_api_client/apis/
ui_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 UiApi: Send + Sync {
24    /// POST /ui/components/{namespace}
25    ///
26    ///
27    async fn add_ui_component_to_namespace<'namespace, 'root_ui_component>(
28        &self,
29        namespace: &'namespace str,
30        root_ui_component: Option<models::RootUiComponent>,
31    ) -> Result<models::RootUiComponent, Error<AddUiComponentToNamespaceError>>;
32
33    /// GET /ui/components/{namespace}
34    ///
35    ///
36    async fn get_registered_ui_components_in_namespace<'namespace, 'summary>(
37        &self,
38        namespace: &'namespace str,
39        summary: Option<bool>,
40    ) -> Result<Vec<models::RootUiComponent>, Error<GetRegisteredUiComponentsInNamespaceError>>;
41
42    /// GET /ui/components/{namespace}/{componentUID}
43    ///
44    ///
45    async fn get_ui_component_in_namespace<'namespace, 'component_uid>(
46        &self,
47        namespace: &'namespace str,
48        component_uid: &'component_uid str,
49    ) -> Result<models::RootUiComponent, Error<GetUiComponentInNamespaceError>>;
50
51    /// GET /ui/tiles
52    ///
53    ///
54    async fn get_ui_tiles(&self) -> Result<Vec<models::TileDto>, Error<GetUiTilesError>>;
55
56    /// DELETE /ui/components/{namespace}/{componentUID}
57    ///
58    ///
59    async fn remove_ui_component_from_namespace<'namespace, 'component_uid>(
60        &self,
61        namespace: &'namespace str,
62        component_uid: &'component_uid str,
63    ) -> Result<(), Error<RemoveUiComponentFromNamespaceError>>;
64
65    /// PUT /ui/components/{namespace}/{componentUID}
66    ///
67    ///
68    async fn update_ui_component_in_namespace<'namespace, 'component_uid, 'root_ui_component>(
69        &self,
70        namespace: &'namespace str,
71        component_uid: &'component_uid str,
72        root_ui_component: Option<models::RootUiComponent>,
73    ) -> Result<models::RootUiComponent, Error<UpdateUiComponentInNamespaceError>>;
74}
75
76pub struct UiApiClient {
77    configuration: Arc<configuration::Configuration>,
78}
79
80impl UiApiClient {
81    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
82        Self { configuration }
83    }
84}
85
86#[async_trait]
87impl UiApi for UiApiClient {
88    async fn add_ui_component_to_namespace<'namespace, 'root_ui_component>(
89        &self,
90        namespace: &'namespace str,
91        root_ui_component: Option<models::RootUiComponent>,
92    ) -> Result<models::RootUiComponent, Error<AddUiComponentToNamespaceError>> {
93        let local_var_configuration = &self.configuration;
94
95        let local_var_client = &local_var_configuration.client;
96
97        let local_var_uri_str = format!(
98            "{}/ui/components/{namespace}",
99            local_var_configuration.base_path,
100            namespace = crate::apis::urlencode(namespace)
101        );
102        let mut local_var_req_builder =
103            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
104
105        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106            local_var_req_builder = local_var_req_builder
107                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
108        }
109        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
110            local_var_req_builder = local_var_req_builder.basic_auth(
111                local_var_auth_conf.0.to_owned(),
112                local_var_auth_conf.1.to_owned(),
113            );
114        };
115        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
116            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
117        };
118        local_var_req_builder = local_var_req_builder.json(&root_ui_component);
119
120        let local_var_req = local_var_req_builder.build()?;
121        let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123        let local_var_status = local_var_resp.status();
124        let local_var_content_type = local_var_resp
125            .headers()
126            .get("content-type")
127            .and_then(|v| v.to_str().ok())
128            .unwrap_or("application/octet-stream");
129        let local_var_content_type = super::ContentType::from(local_var_content_type);
130        let local_var_content = local_var_resp.text().await?;
131
132        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133            match local_var_content_type {
134                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
135                ContentType::Text => {
136                    return Err(Error::from(serde_json::Error::custom(
137                        "Received `text/plain` content type response that cannot be converted to `models::RootUiComponent`",
138                    )));
139                }
140                ContentType::Unsupported(local_var_unknown_type) => {
141                    return Err(Error::from(serde_json::Error::custom(format!(
142                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RootUiComponent`"
143                    ))));
144                }
145            }
146        } else {
147            let local_var_entity: Option<AddUiComponentToNamespaceError> =
148                serde_json::from_str(&local_var_content).ok();
149            let local_var_error = ResponseContent {
150                status: local_var_status,
151                content: local_var_content,
152                entity: local_var_entity,
153            };
154            Err(Error::ResponseError(local_var_error))
155        }
156    }
157
158    async fn get_registered_ui_components_in_namespace<'namespace, 'summary>(
159        &self,
160        namespace: &'namespace str,
161        summary: Option<bool>,
162    ) -> Result<Vec<models::RootUiComponent>, Error<GetRegisteredUiComponentsInNamespaceError>>
163    {
164        let local_var_configuration = &self.configuration;
165
166        let local_var_client = &local_var_configuration.client;
167
168        let local_var_uri_str = format!(
169            "{}/ui/components/{namespace}",
170            local_var_configuration.base_path,
171            namespace = crate::apis::urlencode(namespace)
172        );
173        let mut local_var_req_builder =
174            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
175
176        if let Some(ref local_var_str) = summary {
177            local_var_req_builder =
178                local_var_req_builder.query(&[("summary", &local_var_str.to_string())]);
179        }
180        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
181            local_var_req_builder = local_var_req_builder
182                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
183        }
184
185        let local_var_req = local_var_req_builder.build()?;
186        let local_var_resp = local_var_client.execute(local_var_req).await?;
187
188        let local_var_status = local_var_resp.status();
189        let local_var_content_type = local_var_resp
190            .headers()
191            .get("content-type")
192            .and_then(|v| v.to_str().ok())
193            .unwrap_or("application/octet-stream");
194        let local_var_content_type = super::ContentType::from(local_var_content_type);
195        let local_var_content = local_var_resp.text().await?;
196
197        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198            match local_var_content_type {
199                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
200                ContentType::Text => {
201                    return Err(Error::from(serde_json::Error::custom(
202                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::RootUiComponent&gt;`",
203                    )));
204                }
205                ContentType::Unsupported(local_var_unknown_type) => {
206                    return Err(Error::from(serde_json::Error::custom(format!(
207                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::RootUiComponent&gt;`"
208                    ))));
209                }
210            }
211        } else {
212            let local_var_entity: Option<GetRegisteredUiComponentsInNamespaceError> =
213                serde_json::from_str(&local_var_content).ok();
214            let local_var_error = ResponseContent {
215                status: local_var_status,
216                content: local_var_content,
217                entity: local_var_entity,
218            };
219            Err(Error::ResponseError(local_var_error))
220        }
221    }
222
223    async fn get_ui_component_in_namespace<'namespace, 'component_uid>(
224        &self,
225        namespace: &'namespace str,
226        component_uid: &'component_uid str,
227    ) -> Result<models::RootUiComponent, Error<GetUiComponentInNamespaceError>> {
228        let local_var_configuration = &self.configuration;
229
230        let local_var_client = &local_var_configuration.client;
231
232        let local_var_uri_str = format!(
233            "{}/ui/components/{namespace}/{componentUID}",
234            local_var_configuration.base_path,
235            namespace = crate::apis::urlencode(namespace),
236            componentUID = crate::apis::urlencode(component_uid)
237        );
238        let mut local_var_req_builder =
239            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
240
241        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
242            local_var_req_builder = local_var_req_builder
243                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244        }
245
246        let local_var_req = local_var_req_builder.build()?;
247        let local_var_resp = local_var_client.execute(local_var_req).await?;
248
249        let local_var_status = local_var_resp.status();
250        let local_var_content_type = local_var_resp
251            .headers()
252            .get("content-type")
253            .and_then(|v| v.to_str().ok())
254            .unwrap_or("application/octet-stream");
255        let local_var_content_type = super::ContentType::from(local_var_content_type);
256        let local_var_content = local_var_resp.text().await?;
257
258        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259            match local_var_content_type {
260                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
261                ContentType::Text => {
262                    return Err(Error::from(serde_json::Error::custom(
263                        "Received `text/plain` content type response that cannot be converted to `models::RootUiComponent`",
264                    )));
265                }
266                ContentType::Unsupported(local_var_unknown_type) => {
267                    return Err(Error::from(serde_json::Error::custom(format!(
268                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RootUiComponent`"
269                    ))));
270                }
271            }
272        } else {
273            let local_var_entity: Option<GetUiComponentInNamespaceError> =
274                serde_json::from_str(&local_var_content).ok();
275            let local_var_error = ResponseContent {
276                status: local_var_status,
277                content: local_var_content,
278                entity: local_var_entity,
279            };
280            Err(Error::ResponseError(local_var_error))
281        }
282    }
283
284    async fn get_ui_tiles(&self) -> Result<Vec<models::TileDto>, Error<GetUiTilesError>> {
285        let local_var_configuration = &self.configuration;
286
287        let local_var_client = &local_var_configuration.client;
288
289        let local_var_uri_str = format!("{}/ui/tiles", local_var_configuration.base_path);
290        let mut local_var_req_builder =
291            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
292
293        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
294            local_var_req_builder = local_var_req_builder
295                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
296        }
297
298        let local_var_req = local_var_req_builder.build()?;
299        let local_var_resp = local_var_client.execute(local_var_req).await?;
300
301        let local_var_status = local_var_resp.status();
302        let local_var_content_type = local_var_resp
303            .headers()
304            .get("content-type")
305            .and_then(|v| v.to_str().ok())
306            .unwrap_or("application/octet-stream");
307        let local_var_content_type = super::ContentType::from(local_var_content_type);
308        let local_var_content = local_var_resp.text().await?;
309
310        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
311            match local_var_content_type {
312                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
313                ContentType::Text => {
314                    return Err(Error::from(serde_json::Error::custom(
315                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TileDto&gt;`",
316                    )));
317                }
318                ContentType::Unsupported(local_var_unknown_type) => {
319                    return Err(Error::from(serde_json::Error::custom(format!(
320                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::TileDto&gt;`"
321                    ))));
322                }
323            }
324        } else {
325            let local_var_entity: Option<GetUiTilesError> =
326                serde_json::from_str(&local_var_content).ok();
327            let local_var_error = ResponseContent {
328                status: local_var_status,
329                content: local_var_content,
330                entity: local_var_entity,
331            };
332            Err(Error::ResponseError(local_var_error))
333        }
334    }
335
336    async fn remove_ui_component_from_namespace<'namespace, 'component_uid>(
337        &self,
338        namespace: &'namespace str,
339        component_uid: &'component_uid str,
340    ) -> Result<(), Error<RemoveUiComponentFromNamespaceError>> {
341        let local_var_configuration = &self.configuration;
342
343        let local_var_client = &local_var_configuration.client;
344
345        let local_var_uri_str = format!(
346            "{}/ui/components/{namespace}/{componentUID}",
347            local_var_configuration.base_path,
348            namespace = crate::apis::urlencode(namespace),
349            componentUID = crate::apis::urlencode(component_uid)
350        );
351        let mut local_var_req_builder =
352            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
353
354        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
355            local_var_req_builder = local_var_req_builder
356                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
357        }
358        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
359            local_var_req_builder = local_var_req_builder.basic_auth(
360                local_var_auth_conf.0.to_owned(),
361                local_var_auth_conf.1.to_owned(),
362            );
363        };
364        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
365            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
366        };
367
368        let local_var_req = local_var_req_builder.build()?;
369        let local_var_resp = local_var_client.execute(local_var_req).await?;
370
371        let local_var_status = local_var_resp.status();
372        let local_var_content = local_var_resp.text().await?;
373
374        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
375            Ok(())
376        } else {
377            let local_var_entity: Option<RemoveUiComponentFromNamespaceError> =
378                serde_json::from_str(&local_var_content).ok();
379            let local_var_error = ResponseContent {
380                status: local_var_status,
381                content: local_var_content,
382                entity: local_var_entity,
383            };
384            Err(Error::ResponseError(local_var_error))
385        }
386    }
387
388    async fn update_ui_component_in_namespace<'namespace, 'component_uid, 'root_ui_component>(
389        &self,
390        namespace: &'namespace str,
391        component_uid: &'component_uid str,
392        root_ui_component: Option<models::RootUiComponent>,
393    ) -> Result<models::RootUiComponent, Error<UpdateUiComponentInNamespaceError>> {
394        let local_var_configuration = &self.configuration;
395
396        let local_var_client = &local_var_configuration.client;
397
398        let local_var_uri_str = format!(
399            "{}/ui/components/{namespace}/{componentUID}",
400            local_var_configuration.base_path,
401            namespace = crate::apis::urlencode(namespace),
402            componentUID = crate::apis::urlencode(component_uid)
403        );
404        let mut local_var_req_builder =
405            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
406
407        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
408            local_var_req_builder = local_var_req_builder
409                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
410        }
411        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
412            local_var_req_builder = local_var_req_builder.basic_auth(
413                local_var_auth_conf.0.to_owned(),
414                local_var_auth_conf.1.to_owned(),
415            );
416        };
417        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
418            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
419        };
420        local_var_req_builder = local_var_req_builder.json(&root_ui_component);
421
422        let local_var_req = local_var_req_builder.build()?;
423        let local_var_resp = local_var_client.execute(local_var_req).await?;
424
425        let local_var_status = local_var_resp.status();
426        let local_var_content_type = local_var_resp
427            .headers()
428            .get("content-type")
429            .and_then(|v| v.to_str().ok())
430            .unwrap_or("application/octet-stream");
431        let local_var_content_type = super::ContentType::from(local_var_content_type);
432        let local_var_content = local_var_resp.text().await?;
433
434        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
435            match local_var_content_type {
436                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
437                ContentType::Text => {
438                    return Err(Error::from(serde_json::Error::custom(
439                        "Received `text/plain` content type response that cannot be converted to `models::RootUiComponent`",
440                    )));
441                }
442                ContentType::Unsupported(local_var_unknown_type) => {
443                    return Err(Error::from(serde_json::Error::custom(format!(
444                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RootUiComponent`"
445                    ))));
446                }
447            }
448        } else {
449            let local_var_entity: Option<UpdateUiComponentInNamespaceError> =
450                serde_json::from_str(&local_var_content).ok();
451            let local_var_error = ResponseContent {
452                status: local_var_status,
453                content: local_var_content,
454                entity: local_var_entity,
455            };
456            Err(Error::ResponseError(local_var_error))
457        }
458    }
459}
460
461/// struct for typed errors of method [UiApi::add_ui_component_to_namespace]
462#[derive(Debug, Clone, Serialize, Deserialize)]
463#[serde(untagged)]
464pub enum AddUiComponentToNamespaceError {
465    UnknownValue(serde_json::Value),
466}
467
468/// struct for typed errors of method [UiApi::get_registered_ui_components_in_namespace]
469#[derive(Debug, Clone, Serialize, Deserialize)]
470#[serde(untagged)]
471pub enum GetRegisteredUiComponentsInNamespaceError {
472    UnknownValue(serde_json::Value),
473}
474
475/// struct for typed errors of method [UiApi::get_ui_component_in_namespace]
476#[derive(Debug, Clone, Serialize, Deserialize)]
477#[serde(untagged)]
478pub enum GetUiComponentInNamespaceError {
479    Status404(),
480    UnknownValue(serde_json::Value),
481}
482
483/// struct for typed errors of method [UiApi::get_ui_tiles]
484#[derive(Debug, Clone, Serialize, Deserialize)]
485#[serde(untagged)]
486pub enum GetUiTilesError {
487    UnknownValue(serde_json::Value),
488}
489
490/// struct for typed errors of method [UiApi::remove_ui_component_from_namespace]
491#[derive(Debug, Clone, Serialize, Deserialize)]
492#[serde(untagged)]
493pub enum RemoveUiComponentFromNamespaceError {
494    Status404(),
495    UnknownValue(serde_json::Value),
496}
497
498/// struct for typed errors of method [UiApi::update_ui_component_in_namespace]
499#[derive(Debug, Clone, Serialize, Deserialize)]
500#[serde(untagged)]
501pub enum UpdateUiComponentInNamespaceError {
502    Status404(),
503    UnknownValue(serde_json::Value),
504}