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