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