hab_rs_api_client/apis/
systeminfo_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 SysteminfoApi: Send + Sync {
24    /// GET /systeminfo
25    ///
26    ///
27    async fn get_system_information(
28        &self,
29    ) -> Result<models::SystemInfoBean, Error<GetSystemInformationError>>;
30
31    /// GET /systeminfo/uom
32    ///
33    ///
34    async fn get_uo_m_information(
35        &self,
36    ) -> Result<models::UoMInfoBean, Error<GetUoMInformationError>>;
37}
38
39pub struct SysteminfoApiClient {
40    configuration: Arc<configuration::Configuration>,
41}
42
43impl SysteminfoApiClient {
44    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
45        Self { configuration }
46    }
47}
48
49#[async_trait]
50impl SysteminfoApi for SysteminfoApiClient {
51    async fn get_system_information(
52        &self,
53    ) -> Result<models::SystemInfoBean, Error<GetSystemInformationError>> {
54        let local_var_configuration = &self.configuration;
55
56        let local_var_client = &local_var_configuration.client;
57
58        let local_var_uri_str = format!("{}/systeminfo", local_var_configuration.base_path);
59        let mut local_var_req_builder =
60            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
61
62        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
63            local_var_req_builder = local_var_req_builder
64                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
65        }
66        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
67            local_var_req_builder = local_var_req_builder.basic_auth(
68                local_var_auth_conf.0.to_owned(),
69                local_var_auth_conf.1.to_owned(),
70            );
71        };
72        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
73            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
74        };
75
76        let local_var_req = local_var_req_builder.build()?;
77        let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79        let local_var_status = local_var_resp.status();
80        let local_var_content_type = local_var_resp
81            .headers()
82            .get("content-type")
83            .and_then(|v| v.to_str().ok())
84            .unwrap_or("application/octet-stream");
85        let local_var_content_type = super::ContentType::from(local_var_content_type);
86        let local_var_content = local_var_resp.text().await?;
87
88        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89            match local_var_content_type {
90                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
91                ContentType::Text => {
92                    return Err(Error::from(serde_json::Error::custom(
93                        "Received `text/plain` content type response that cannot be converted to `models::SystemInfoBean`",
94                    )));
95                }
96                ContentType::Unsupported(local_var_unknown_type) => {
97                    return Err(Error::from(serde_json::Error::custom(format!(
98                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SystemInfoBean`"
99                    ))));
100                }
101            }
102        } else {
103            let local_var_entity: Option<GetSystemInformationError> =
104                serde_json::from_str(&local_var_content).ok();
105            let local_var_error = ResponseContent {
106                status: local_var_status,
107                content: local_var_content,
108                entity: local_var_entity,
109            };
110            Err(Error::ResponseError(local_var_error))
111        }
112    }
113
114    async fn get_uo_m_information(
115        &self,
116    ) -> Result<models::UoMInfoBean, Error<GetUoMInformationError>> {
117        let local_var_configuration = &self.configuration;
118
119        let local_var_client = &local_var_configuration.client;
120
121        let local_var_uri_str = format!("{}/systeminfo/uom", local_var_configuration.base_path);
122        let mut local_var_req_builder =
123            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
124
125        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
126            local_var_req_builder = local_var_req_builder
127                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
128        }
129        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
130            local_var_req_builder = local_var_req_builder.basic_auth(
131                local_var_auth_conf.0.to_owned(),
132                local_var_auth_conf.1.to_owned(),
133            );
134        };
135        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
136            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
137        };
138
139        let local_var_req = local_var_req_builder.build()?;
140        let local_var_resp = local_var_client.execute(local_var_req).await?;
141
142        let local_var_status = local_var_resp.status();
143        let local_var_content_type = local_var_resp
144            .headers()
145            .get("content-type")
146            .and_then(|v| v.to_str().ok())
147            .unwrap_or("application/octet-stream");
148        let local_var_content_type = super::ContentType::from(local_var_content_type);
149        let local_var_content = local_var_resp.text().await?;
150
151        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
152            match local_var_content_type {
153                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
154                ContentType::Text => {
155                    return Err(Error::from(serde_json::Error::custom(
156                        "Received `text/plain` content type response that cannot be converted to `models::UoMInfoBean`",
157                    )));
158                }
159                ContentType::Unsupported(local_var_unknown_type) => {
160                    return Err(Error::from(serde_json::Error::custom(format!(
161                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::UoMInfoBean`"
162                    ))));
163                }
164            }
165        } else {
166            let local_var_entity: Option<GetUoMInformationError> =
167                serde_json::from_str(&local_var_content).ok();
168            let local_var_error = ResponseContent {
169                status: local_var_status,
170                content: local_var_content,
171                entity: local_var_entity,
172            };
173            Err(Error::ResponseError(local_var_error))
174        }
175    }
176}
177
178/// struct for typed errors of method [SysteminfoApi::get_system_information]
179#[derive(Debug, Clone, Serialize, Deserialize)]
180#[serde(untagged)]
181pub enum GetSystemInformationError {
182    UnknownValue(serde_json::Value),
183}
184
185/// struct for typed errors of method [SysteminfoApi::get_uo_m_information]
186#[derive(Debug, Clone, Serialize, Deserialize)]
187#[serde(untagged)]
188pub enum GetUoMInformationError {
189    UnknownValue(serde_json::Value),
190}