hab_rs_api_client/apis/
root_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 RootApi: Send + Sync {
24    /// GET /
25    ///
26    ///
27    async fn get_root(&self) -> Result<models::RootBean, Error<GetRootError>>;
28}
29
30pub struct RootApiClient {
31    configuration: Arc<configuration::Configuration>,
32}
33
34impl RootApiClient {
35    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
36        Self { configuration }
37    }
38}
39
40#[async_trait]
41impl RootApi for RootApiClient {
42    async fn get_root(&self) -> Result<models::RootBean, Error<GetRootError>> {
43        let local_var_configuration = &self.configuration;
44
45        let local_var_client = &local_var_configuration.client;
46
47        let local_var_uri_str = format!("{}/", local_var_configuration.base_path);
48        let mut local_var_req_builder =
49            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
50
51        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
52            local_var_req_builder = local_var_req_builder
53                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54        }
55
56        let local_var_req = local_var_req_builder.build()?;
57        let local_var_resp = local_var_client.execute(local_var_req).await?;
58
59        let local_var_status = local_var_resp.status();
60        let local_var_content_type = local_var_resp
61            .headers()
62            .get("content-type")
63            .and_then(|v| v.to_str().ok())
64            .unwrap_or("application/octet-stream");
65        let local_var_content_type = super::ContentType::from(local_var_content_type);
66        let local_var_content = local_var_resp.text().await?;
67
68        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69            match local_var_content_type {
70                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
71                ContentType::Text => {
72                    return Err(Error::from(serde_json::Error::custom(
73                        "Received `text/plain` content type response that cannot be converted to `models::RootBean`",
74                    )));
75                }
76                ContentType::Unsupported(local_var_unknown_type) => {
77                    return Err(Error::from(serde_json::Error::custom(format!(
78                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RootBean`"
79                    ))));
80                }
81            }
82        } else {
83            let local_var_entity: Option<GetRootError> =
84                serde_json::from_str(&local_var_content).ok();
85            let local_var_error = ResponseContent {
86                status: local_var_status,
87                content: local_var_content,
88                entity: local_var_entity,
89            };
90            Err(Error::ResponseError(local_var_error))
91        }
92    }
93}
94
95/// struct for typed errors of method [RootApi::get_root]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum GetRootError {
99    UnknownValue(serde_json::Value),
100}