hab_rs_api_client/apis/
transformations_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 TransformationsApi: Send + Sync {
24    /// DELETE /transformations/{uid}
25    ///
26    ///
27    async fn delete_transformation<'uid>(
28        &self,
29        uid: &'uid str,
30    ) -> Result<(), Error<DeleteTransformationError>>;
31
32    /// GET /transformations/{uid}
33    ///
34    ///
35    async fn get_transformation<'uid>(
36        &self,
37        uid: &'uid str,
38    ) -> Result<models::Transformation, Error<GetTransformationError>>;
39
40    /// GET /transformations/services
41    ///
42    ///
43    async fn get_transformation_services(
44        &self,
45    ) -> Result<Vec<String>, Error<GetTransformationServicesError>>;
46
47    /// GET /transformations
48    ///
49    ///
50    async fn get_transformations(
51        &self,
52    ) -> Result<Vec<models::TransformationDto>, Error<GetTransformationsError>>;
53
54    /// PUT /transformations/{uid}
55    ///
56    ///
57    async fn put_transformation<'uid, 'transformation_dto>(
58        &self,
59        uid: &'uid str,
60        transformation_dto: models::TransformationDto,
61    ) -> Result<(), Error<PutTransformationError>>;
62}
63
64pub struct TransformationsApiClient {
65    configuration: Arc<configuration::Configuration>,
66}
67
68impl TransformationsApiClient {
69    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
70        Self { configuration }
71    }
72}
73
74#[async_trait]
75impl TransformationsApi for TransformationsApiClient {
76    async fn delete_transformation<'uid>(
77        &self,
78        uid: &'uid str,
79    ) -> Result<(), Error<DeleteTransformationError>> {
80        let local_var_configuration = &self.configuration;
81
82        let local_var_client = &local_var_configuration.client;
83
84        let local_var_uri_str = format!(
85            "{}/transformations/{uid}",
86            local_var_configuration.base_path,
87            uid = crate::apis::urlencode(uid)
88        );
89        let mut local_var_req_builder =
90            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
91
92        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
93            local_var_req_builder = local_var_req_builder
94                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
95        }
96        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
97            local_var_req_builder = local_var_req_builder.basic_auth(
98                local_var_auth_conf.0.to_owned(),
99                local_var_auth_conf.1.to_owned(),
100            );
101        };
102        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
103            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
104        };
105
106        let local_var_req = local_var_req_builder.build()?;
107        let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109        let local_var_status = local_var_resp.status();
110        let local_var_content = local_var_resp.text().await?;
111
112        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113            Ok(())
114        } else {
115            let local_var_entity: Option<DeleteTransformationError> =
116                serde_json::from_str(&local_var_content).ok();
117            let local_var_error = ResponseContent {
118                status: local_var_status,
119                content: local_var_content,
120                entity: local_var_entity,
121            };
122            Err(Error::ResponseError(local_var_error))
123        }
124    }
125
126    async fn get_transformation<'uid>(
127        &self,
128        uid: &'uid str,
129    ) -> Result<models::Transformation, Error<GetTransformationError>> {
130        let local_var_configuration = &self.configuration;
131
132        let local_var_client = &local_var_configuration.client;
133
134        let local_var_uri_str = format!(
135            "{}/transformations/{uid}",
136            local_var_configuration.base_path,
137            uid = crate::apis::urlencode(uid)
138        );
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_user_agent) = local_var_configuration.user_agent {
143            local_var_req_builder = local_var_req_builder
144                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
145        }
146        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
147            local_var_req_builder = local_var_req_builder.basic_auth(
148                local_var_auth_conf.0.to_owned(),
149                local_var_auth_conf.1.to_owned(),
150            );
151        };
152        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
153            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
154        };
155
156        let local_var_req = local_var_req_builder.build()?;
157        let local_var_resp = local_var_client.execute(local_var_req).await?;
158
159        let local_var_status = local_var_resp.status();
160        let local_var_content_type = local_var_resp
161            .headers()
162            .get("content-type")
163            .and_then(|v| v.to_str().ok())
164            .unwrap_or("application/octet-stream");
165        let local_var_content_type = super::ContentType::from(local_var_content_type);
166        let local_var_content = local_var_resp.text().await?;
167
168        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
169            match local_var_content_type {
170                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
171                ContentType::Text => {
172                    return Err(Error::from(serde_json::Error::custom(
173                        "Received `text/plain` content type response that cannot be converted to `models::Transformation`",
174                    )));
175                }
176                ContentType::Unsupported(local_var_unknown_type) => {
177                    return Err(Error::from(serde_json::Error::custom(format!(
178                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Transformation`"
179                    ))));
180                }
181            }
182        } else {
183            let local_var_entity: Option<GetTransformationError> =
184                serde_json::from_str(&local_var_content).ok();
185            let local_var_error = ResponseContent {
186                status: local_var_status,
187                content: local_var_content,
188                entity: local_var_entity,
189            };
190            Err(Error::ResponseError(local_var_error))
191        }
192    }
193
194    async fn get_transformation_services(
195        &self,
196    ) -> Result<Vec<String>, Error<GetTransformationServicesError>> {
197        let local_var_configuration = &self.configuration;
198
199        let local_var_client = &local_var_configuration.client;
200
201        let local_var_uri_str = format!(
202            "{}/transformations/services",
203            local_var_configuration.base_path
204        );
205        let mut local_var_req_builder =
206            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
207
208        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
209            local_var_req_builder = local_var_req_builder
210                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
211        }
212        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
213            local_var_req_builder = local_var_req_builder.basic_auth(
214                local_var_auth_conf.0.to_owned(),
215                local_var_auth_conf.1.to_owned(),
216            );
217        };
218        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
219            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
220        };
221
222        let local_var_req = local_var_req_builder.build()?;
223        let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225        let local_var_status = local_var_resp.status();
226        let local_var_content_type = local_var_resp
227            .headers()
228            .get("content-type")
229            .and_then(|v| v.to_str().ok())
230            .unwrap_or("application/octet-stream");
231        let local_var_content_type = super::ContentType::from(local_var_content_type);
232        let local_var_content = local_var_resp.text().await?;
233
234        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235            match local_var_content_type {
236                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
237                ContentType::Text => {
238                    return Err(Error::from(serde_json::Error::custom(
239                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;String&gt;`",
240                    )));
241                }
242                ContentType::Unsupported(local_var_unknown_type) => {
243                    return Err(Error::from(serde_json::Error::custom(format!(
244                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;String&gt;`"
245                    ))));
246                }
247            }
248        } else {
249            let local_var_entity: Option<GetTransformationServicesError> =
250                serde_json::from_str(&local_var_content).ok();
251            let local_var_error = ResponseContent {
252                status: local_var_status,
253                content: local_var_content,
254                entity: local_var_entity,
255            };
256            Err(Error::ResponseError(local_var_error))
257        }
258    }
259
260    async fn get_transformations(
261        &self,
262    ) -> Result<Vec<models::TransformationDto>, Error<GetTransformationsError>> {
263        let local_var_configuration = &self.configuration;
264
265        let local_var_client = &local_var_configuration.client;
266
267        let local_var_uri_str = format!("{}/transformations", local_var_configuration.base_path);
268        let mut local_var_req_builder =
269            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
270
271        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
272            local_var_req_builder = local_var_req_builder
273                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274        }
275        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
276            local_var_req_builder = local_var_req_builder.basic_auth(
277                local_var_auth_conf.0.to_owned(),
278                local_var_auth_conf.1.to_owned(),
279            );
280        };
281        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
282            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283        };
284
285        let local_var_req = local_var_req_builder.build()?;
286        let local_var_resp = local_var_client.execute(local_var_req).await?;
287
288        let local_var_status = local_var_resp.status();
289        let local_var_content_type = local_var_resp
290            .headers()
291            .get("content-type")
292            .and_then(|v| v.to_str().ok())
293            .unwrap_or("application/octet-stream");
294        let local_var_content_type = super::ContentType::from(local_var_content_type);
295        let local_var_content = local_var_resp.text().await?;
296
297        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
298            match local_var_content_type {
299                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
300                ContentType::Text => {
301                    return Err(Error::from(serde_json::Error::custom(
302                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TransformationDto&gt;`",
303                    )));
304                }
305                ContentType::Unsupported(local_var_unknown_type) => {
306                    return Err(Error::from(serde_json::Error::custom(format!(
307                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::TransformationDto&gt;`"
308                    ))));
309                }
310            }
311        } else {
312            let local_var_entity: Option<GetTransformationsError> =
313                serde_json::from_str(&local_var_content).ok();
314            let local_var_error = ResponseContent {
315                status: local_var_status,
316                content: local_var_content,
317                entity: local_var_entity,
318            };
319            Err(Error::ResponseError(local_var_error))
320        }
321    }
322
323    async fn put_transformation<'uid, 'transformation_dto>(
324        &self,
325        uid: &'uid str,
326        transformation_dto: models::TransformationDto,
327    ) -> Result<(), Error<PutTransformationError>> {
328        let local_var_configuration = &self.configuration;
329
330        let local_var_client = &local_var_configuration.client;
331
332        let local_var_uri_str = format!(
333            "{}/transformations/{uid}",
334            local_var_configuration.base_path,
335            uid = crate::apis::urlencode(uid)
336        );
337        let mut local_var_req_builder =
338            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
339
340        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
341            local_var_req_builder = local_var_req_builder
342                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
343        }
344        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
345            local_var_req_builder = local_var_req_builder.basic_auth(
346                local_var_auth_conf.0.to_owned(),
347                local_var_auth_conf.1.to_owned(),
348            );
349        };
350        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
351            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
352        };
353        local_var_req_builder = local_var_req_builder.json(&transformation_dto);
354
355        let local_var_req = local_var_req_builder.build()?;
356        let local_var_resp = local_var_client.execute(local_var_req).await?;
357
358        let local_var_status = local_var_resp.status();
359        let local_var_content = local_var_resp.text().await?;
360
361        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
362            Ok(())
363        } else {
364            let local_var_entity: Option<PutTransformationError> =
365                serde_json::from_str(&local_var_content).ok();
366            let local_var_error = ResponseContent {
367                status: local_var_status,
368                content: local_var_content,
369                entity: local_var_entity,
370            };
371            Err(Error::ResponseError(local_var_error))
372        }
373    }
374}
375
376/// struct for typed errors of method [TransformationsApi::delete_transformation]
377#[derive(Debug, Clone, Serialize, Deserialize)]
378#[serde(untagged)]
379pub enum DeleteTransformationError {
380    Status404(),
381    Status405(),
382    UnknownValue(serde_json::Value),
383}
384
385/// struct for typed errors of method [TransformationsApi::get_transformation]
386#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum GetTransformationError {
389    Status404(),
390    UnknownValue(serde_json::Value),
391}
392
393/// struct for typed errors of method [TransformationsApi::get_transformation_services]
394#[derive(Debug, Clone, Serialize, Deserialize)]
395#[serde(untagged)]
396pub enum GetTransformationServicesError {
397    UnknownValue(serde_json::Value),
398}
399
400/// struct for typed errors of method [TransformationsApi::get_transformations]
401#[derive(Debug, Clone, Serialize, Deserialize)]
402#[serde(untagged)]
403pub enum GetTransformationsError {
404    UnknownValue(serde_json::Value),
405}
406
407/// struct for typed errors of method [TransformationsApi::put_transformation]
408#[derive(Debug, Clone, Serialize, Deserialize)]
409#[serde(untagged)]
410pub enum PutTransformationError {
411    Status400(),
412    Status405(),
413    UnknownValue(serde_json::Value),
414}