hab_rs_api_client/apis/
addons_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 AddonsApi: Send + Sync {
24    /// GET /addons/{addonId}
25    ///
26    ///
27    async fn get_addon_by_id<'addon_id, 'accept_language, 'service_id>(
28        &self,
29        addon_id: &'addon_id str,
30        accept_language: Option<&'accept_language str>,
31        service_id: Option<&'service_id str>,
32    ) -> Result<models::Addon, Error<GetAddonByIdError>>;
33
34    /// GET /addons/{addonId}/config
35    ///
36    ///
37    async fn get_addon_configuration<'addon_id, 'service_id>(
38        &self,
39        addon_id: &'addon_id str,
40        service_id: Option<&'service_id str>,
41    ) -> Result<String, Error<GetAddonConfigurationError>>;
42
43    /// GET /addons/types
44    ///
45    ///
46    async fn get_addon_services<'accept_language, 'service_id>(
47        &self,
48        accept_language: Option<&'accept_language str>,
49        service_id: Option<&'service_id str>,
50    ) -> Result<Vec<models::AddonType>, Error<GetAddonServicesError>>;
51
52    /// GET /addons/services
53    ///
54    ///
55    async fn get_addon_types<'accept_language>(
56        &self,
57        accept_language: Option<&'accept_language str>,
58    ) -> Result<Vec<models::AddonType>, Error<GetAddonTypesError>>;
59
60    /// GET /addons
61    ///
62    ///
63    async fn get_addons<'accept_language, 'service_id>(
64        &self,
65        accept_language: Option<&'accept_language str>,
66        service_id: Option<&'service_id str>,
67    ) -> Result<Vec<models::Addon>, Error<GetAddonsError>>;
68
69    /// GET /addons/suggestions
70    ///
71    ///
72    async fn get_suggested_addons<'accept_language>(
73        &self,
74        accept_language: Option<&'accept_language str>,
75    ) -> Result<Vec<models::Addon>, Error<GetSuggestedAddonsError>>;
76
77    /// POST /addons/{addonId}/install
78    ///
79    ///
80    async fn install_addon_by_id<'addon_id, 'service_id>(
81        &self,
82        addon_id: &'addon_id str,
83        service_id: Option<&'service_id str>,
84    ) -> Result<(), Error<InstallAddonByIdError>>;
85
86    /// POST /addons/url/{url}/install
87    ///
88    ///
89    async fn install_addon_from_url<'url>(
90        &self,
91        url: &'url str,
92    ) -> Result<(), Error<InstallAddonFromUrlError>>;
93
94    /// POST /addons/{addonId}/uninstall
95    ///
96    ///
97    async fn uninstall_addon<'addon_id, 'service_id>(
98        &self,
99        addon_id: &'addon_id str,
100        service_id: Option<&'service_id str>,
101    ) -> Result<(), Error<UninstallAddonError>>;
102
103    /// PUT /addons/{addonId}/config
104    ///
105    ///
106    async fn update_addon_configuration<'addon_id, 'service_id, 'request_body>(
107        &self,
108        addon_id: &'addon_id str,
109        service_id: Option<&'service_id str>,
110        request_body: Option<std::collections::HashMap<String, serde_json::Value>>,
111    ) -> Result<String, Error<UpdateAddonConfigurationError>>;
112}
113
114pub struct AddonsApiClient {
115    configuration: Arc<configuration::Configuration>,
116}
117
118impl AddonsApiClient {
119    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
120        Self { configuration }
121    }
122}
123
124#[async_trait]
125impl AddonsApi for AddonsApiClient {
126    async fn get_addon_by_id<'addon_id, 'accept_language, 'service_id>(
127        &self,
128        addon_id: &'addon_id str,
129        accept_language: Option<&'accept_language str>,
130        service_id: Option<&'service_id str>,
131    ) -> Result<models::Addon, Error<GetAddonByIdError>> {
132        let local_var_configuration = &self.configuration;
133
134        let local_var_client = &local_var_configuration.client;
135
136        let local_var_uri_str = format!(
137            "{}/addons/{addonId}",
138            local_var_configuration.base_path,
139            addonId = crate::apis::urlencode(addon_id)
140        );
141        let mut local_var_req_builder =
142            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
143
144        if let Some(ref local_var_str) = service_id {
145            local_var_req_builder =
146                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
147        }
148        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
149            local_var_req_builder = local_var_req_builder
150                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
151        }
152        if let Some(local_var_param_value) = accept_language {
153            local_var_req_builder =
154                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
155        }
156        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
157            local_var_req_builder = local_var_req_builder.basic_auth(
158                local_var_auth_conf.0.to_owned(),
159                local_var_auth_conf.1.to_owned(),
160            );
161        };
162        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
163            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
164        };
165
166        let local_var_req = local_var_req_builder.build()?;
167        let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169        let local_var_status = local_var_resp.status();
170        let local_var_content_type = local_var_resp
171            .headers()
172            .get("content-type")
173            .and_then(|v| v.to_str().ok())
174            .unwrap_or("application/octet-stream");
175        let local_var_content_type = super::ContentType::from(local_var_content_type);
176        let local_var_content = local_var_resp.text().await?;
177
178        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179            match local_var_content_type {
180                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
181                ContentType::Text => {
182                    return Err(Error::from(serde_json::Error::custom(
183                        "Received `text/plain` content type response that cannot be converted to `models::Addon`",
184                    )));
185                }
186                ContentType::Unsupported(local_var_unknown_type) => {
187                    return Err(Error::from(serde_json::Error::custom(format!(
188                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Addon`"
189                    ))));
190                }
191            }
192        } else {
193            let local_var_entity: Option<GetAddonByIdError> =
194                serde_json::from_str(&local_var_content).ok();
195            let local_var_error = ResponseContent {
196                status: local_var_status,
197                content: local_var_content,
198                entity: local_var_entity,
199            };
200            Err(Error::ResponseError(local_var_error))
201        }
202    }
203
204    async fn get_addon_configuration<'addon_id, 'service_id>(
205        &self,
206        addon_id: &'addon_id str,
207        service_id: Option<&'service_id str>,
208    ) -> Result<String, Error<GetAddonConfigurationError>> {
209        let local_var_configuration = &self.configuration;
210
211        let local_var_client = &local_var_configuration.client;
212
213        let local_var_uri_str = format!(
214            "{}/addons/{addonId}/config",
215            local_var_configuration.base_path,
216            addonId = crate::apis::urlencode(addon_id)
217        );
218        let mut local_var_req_builder =
219            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
220
221        if let Some(ref local_var_str) = service_id {
222            local_var_req_builder =
223                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
224        }
225        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
226            local_var_req_builder = local_var_req_builder
227                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228        }
229        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
230            local_var_req_builder = local_var_req_builder.basic_auth(
231                local_var_auth_conf.0.to_owned(),
232                local_var_auth_conf.1.to_owned(),
233            );
234        };
235        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
236            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
237        };
238
239        let local_var_req = local_var_req_builder.build()?;
240        let local_var_resp = local_var_client.execute(local_var_req).await?;
241
242        let local_var_status = local_var_resp.status();
243        let local_var_content_type = local_var_resp
244            .headers()
245            .get("content-type")
246            .and_then(|v| v.to_str().ok())
247            .unwrap_or("application/octet-stream");
248        let local_var_content_type = super::ContentType::from(local_var_content_type);
249        let local_var_content = local_var_resp.text().await?;
250
251        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
252            match local_var_content_type {
253                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
254                ContentType::Text => {
255                    return Err(Error::from(serde_json::Error::custom(
256                        "Received `text/plain` content type response that cannot be converted to `String`",
257                    )));
258                }
259                ContentType::Unsupported(local_var_unknown_type) => {
260                    return Err(Error::from(serde_json::Error::custom(format!(
261                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
262                    ))));
263                }
264            }
265        } else {
266            let local_var_entity: Option<GetAddonConfigurationError> =
267                serde_json::from_str(&local_var_content).ok();
268            let local_var_error = ResponseContent {
269                status: local_var_status,
270                content: local_var_content,
271                entity: local_var_entity,
272            };
273            Err(Error::ResponseError(local_var_error))
274        }
275    }
276
277    async fn get_addon_services<'accept_language, 'service_id>(
278        &self,
279        accept_language: Option<&'accept_language str>,
280        service_id: Option<&'service_id str>,
281    ) -> Result<Vec<models::AddonType>, Error<GetAddonServicesError>> {
282        let local_var_configuration = &self.configuration;
283
284        let local_var_client = &local_var_configuration.client;
285
286        let local_var_uri_str = format!("{}/addons/types", local_var_configuration.base_path);
287        let mut local_var_req_builder =
288            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
289
290        if let Some(ref local_var_str) = service_id {
291            local_var_req_builder =
292                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
293        }
294        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
295            local_var_req_builder = local_var_req_builder
296                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
297        }
298        if let Some(local_var_param_value) = accept_language {
299            local_var_req_builder =
300                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
301        }
302        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
303            local_var_req_builder = local_var_req_builder.basic_auth(
304                local_var_auth_conf.0.to_owned(),
305                local_var_auth_conf.1.to_owned(),
306            );
307        };
308        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
309            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
310        };
311
312        let local_var_req = local_var_req_builder.build()?;
313        let local_var_resp = local_var_client.execute(local_var_req).await?;
314
315        let local_var_status = local_var_resp.status();
316        let local_var_content_type = local_var_resp
317            .headers()
318            .get("content-type")
319            .and_then(|v| v.to_str().ok())
320            .unwrap_or("application/octet-stream");
321        let local_var_content_type = super::ContentType::from(local_var_content_type);
322        let local_var_content = local_var_resp.text().await?;
323
324        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
325            match local_var_content_type {
326                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
327                ContentType::Text => {
328                    return Err(Error::from(serde_json::Error::custom(
329                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::AddonType&gt;`",
330                    )));
331                }
332                ContentType::Unsupported(local_var_unknown_type) => {
333                    return Err(Error::from(serde_json::Error::custom(format!(
334                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::AddonType&gt;`"
335                    ))));
336                }
337            }
338        } else {
339            let local_var_entity: Option<GetAddonServicesError> =
340                serde_json::from_str(&local_var_content).ok();
341            let local_var_error = ResponseContent {
342                status: local_var_status,
343                content: local_var_content,
344                entity: local_var_entity,
345            };
346            Err(Error::ResponseError(local_var_error))
347        }
348    }
349
350    async fn get_addon_types<'accept_language>(
351        &self,
352        accept_language: Option<&'accept_language str>,
353    ) -> Result<Vec<models::AddonType>, Error<GetAddonTypesError>> {
354        let local_var_configuration = &self.configuration;
355
356        let local_var_client = &local_var_configuration.client;
357
358        let local_var_uri_str = format!("{}/addons/services", local_var_configuration.base_path);
359        let mut local_var_req_builder =
360            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
361
362        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
363            local_var_req_builder = local_var_req_builder
364                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
365        }
366        if let Some(local_var_param_value) = accept_language {
367            local_var_req_builder =
368                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
369        }
370        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
371            local_var_req_builder = local_var_req_builder.basic_auth(
372                local_var_auth_conf.0.to_owned(),
373                local_var_auth_conf.1.to_owned(),
374            );
375        };
376        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
377            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
378        };
379
380        let local_var_req = local_var_req_builder.build()?;
381        let local_var_resp = local_var_client.execute(local_var_req).await?;
382
383        let local_var_status = local_var_resp.status();
384        let local_var_content_type = local_var_resp
385            .headers()
386            .get("content-type")
387            .and_then(|v| v.to_str().ok())
388            .unwrap_or("application/octet-stream");
389        let local_var_content_type = super::ContentType::from(local_var_content_type);
390        let local_var_content = local_var_resp.text().await?;
391
392        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
393            match local_var_content_type {
394                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
395                ContentType::Text => {
396                    return Err(Error::from(serde_json::Error::custom(
397                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::AddonType&gt;`",
398                    )));
399                }
400                ContentType::Unsupported(local_var_unknown_type) => {
401                    return Err(Error::from(serde_json::Error::custom(format!(
402                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::AddonType&gt;`"
403                    ))));
404                }
405            }
406        } else {
407            let local_var_entity: Option<GetAddonTypesError> =
408                serde_json::from_str(&local_var_content).ok();
409            let local_var_error = ResponseContent {
410                status: local_var_status,
411                content: local_var_content,
412                entity: local_var_entity,
413            };
414            Err(Error::ResponseError(local_var_error))
415        }
416    }
417
418    async fn get_addons<'accept_language, 'service_id>(
419        &self,
420        accept_language: Option<&'accept_language str>,
421        service_id: Option<&'service_id str>,
422    ) -> Result<Vec<models::Addon>, Error<GetAddonsError>> {
423        let local_var_configuration = &self.configuration;
424
425        let local_var_client = &local_var_configuration.client;
426
427        let local_var_uri_str = format!("{}/addons", local_var_configuration.base_path);
428        let mut local_var_req_builder =
429            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
430
431        if let Some(ref local_var_str) = service_id {
432            local_var_req_builder =
433                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
434        }
435        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
436            local_var_req_builder = local_var_req_builder
437                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
438        }
439        if let Some(local_var_param_value) = accept_language {
440            local_var_req_builder =
441                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
442        }
443        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
444            local_var_req_builder = local_var_req_builder.basic_auth(
445                local_var_auth_conf.0.to_owned(),
446                local_var_auth_conf.1.to_owned(),
447            );
448        };
449        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
450            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
451        };
452
453        let local_var_req = local_var_req_builder.build()?;
454        let local_var_resp = local_var_client.execute(local_var_req).await?;
455
456        let local_var_status = local_var_resp.status();
457        let local_var_content_type = local_var_resp
458            .headers()
459            .get("content-type")
460            .and_then(|v| v.to_str().ok())
461            .unwrap_or("application/octet-stream");
462        let local_var_content_type = super::ContentType::from(local_var_content_type);
463        let local_var_content = local_var_resp.text().await?;
464
465        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
466            match local_var_content_type {
467                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
468                ContentType::Text => {
469                    return Err(Error::from(serde_json::Error::custom(
470                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Addon&gt;`",
471                    )));
472                }
473                ContentType::Unsupported(local_var_unknown_type) => {
474                    return Err(Error::from(serde_json::Error::custom(format!(
475                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::Addon&gt;`"
476                    ))));
477                }
478            }
479        } else {
480            let local_var_entity: Option<GetAddonsError> =
481                serde_json::from_str(&local_var_content).ok();
482            let local_var_error = ResponseContent {
483                status: local_var_status,
484                content: local_var_content,
485                entity: local_var_entity,
486            };
487            Err(Error::ResponseError(local_var_error))
488        }
489    }
490
491    async fn get_suggested_addons<'accept_language>(
492        &self,
493        accept_language: Option<&'accept_language str>,
494    ) -> Result<Vec<models::Addon>, Error<GetSuggestedAddonsError>> {
495        let local_var_configuration = &self.configuration;
496
497        let local_var_client = &local_var_configuration.client;
498
499        let local_var_uri_str = format!("{}/addons/suggestions", local_var_configuration.base_path);
500        let mut local_var_req_builder =
501            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
502
503        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
504            local_var_req_builder = local_var_req_builder
505                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
506        }
507        if let Some(local_var_param_value) = accept_language {
508            local_var_req_builder =
509                local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
510        }
511        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
512            local_var_req_builder = local_var_req_builder.basic_auth(
513                local_var_auth_conf.0.to_owned(),
514                local_var_auth_conf.1.to_owned(),
515            );
516        };
517        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
518            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
519        };
520
521        let local_var_req = local_var_req_builder.build()?;
522        let local_var_resp = local_var_client.execute(local_var_req).await?;
523
524        let local_var_status = local_var_resp.status();
525        let local_var_content_type = local_var_resp
526            .headers()
527            .get("content-type")
528            .and_then(|v| v.to_str().ok())
529            .unwrap_or("application/octet-stream");
530        let local_var_content_type = super::ContentType::from(local_var_content_type);
531        let local_var_content = local_var_resp.text().await?;
532
533        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
534            match local_var_content_type {
535                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
536                ContentType::Text => {
537                    return Err(Error::from(serde_json::Error::custom(
538                        "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Addon&gt;`",
539                    )));
540                }
541                ContentType::Unsupported(local_var_unknown_type) => {
542                    return Err(Error::from(serde_json::Error::custom(format!(
543                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec&lt;models::Addon&gt;`"
544                    ))));
545                }
546            }
547        } else {
548            let local_var_entity: Option<GetSuggestedAddonsError> =
549                serde_json::from_str(&local_var_content).ok();
550            let local_var_error = ResponseContent {
551                status: local_var_status,
552                content: local_var_content,
553                entity: local_var_entity,
554            };
555            Err(Error::ResponseError(local_var_error))
556        }
557    }
558
559    async fn install_addon_by_id<'addon_id, 'service_id>(
560        &self,
561        addon_id: &'addon_id str,
562        service_id: Option<&'service_id str>,
563    ) -> Result<(), Error<InstallAddonByIdError>> {
564        let local_var_configuration = &self.configuration;
565
566        let local_var_client = &local_var_configuration.client;
567
568        let local_var_uri_str = format!(
569            "{}/addons/{addonId}/install",
570            local_var_configuration.base_path,
571            addonId = crate::apis::urlencode(addon_id)
572        );
573        let mut local_var_req_builder =
574            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
575
576        if let Some(ref local_var_str) = service_id {
577            local_var_req_builder =
578                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
579        }
580        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
581            local_var_req_builder = local_var_req_builder
582                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
583        }
584        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
585            local_var_req_builder = local_var_req_builder.basic_auth(
586                local_var_auth_conf.0.to_owned(),
587                local_var_auth_conf.1.to_owned(),
588            );
589        };
590        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
591            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
592        };
593
594        let local_var_req = local_var_req_builder.build()?;
595        let local_var_resp = local_var_client.execute(local_var_req).await?;
596
597        let local_var_status = local_var_resp.status();
598        let local_var_content = local_var_resp.text().await?;
599
600        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
601            Ok(())
602        } else {
603            let local_var_entity: Option<InstallAddonByIdError> =
604                serde_json::from_str(&local_var_content).ok();
605            let local_var_error = ResponseContent {
606                status: local_var_status,
607                content: local_var_content,
608                entity: local_var_entity,
609            };
610            Err(Error::ResponseError(local_var_error))
611        }
612    }
613
614    async fn install_addon_from_url<'url>(
615        &self,
616        url: &'url str,
617    ) -> Result<(), Error<InstallAddonFromUrlError>> {
618        let local_var_configuration = &self.configuration;
619
620        let local_var_client = &local_var_configuration.client;
621
622        let local_var_uri_str = format!(
623            "{}/addons/url/{url}/install",
624            local_var_configuration.base_path,
625            url = crate::apis::urlencode(url)
626        );
627        let mut local_var_req_builder =
628            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
629
630        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
631            local_var_req_builder = local_var_req_builder
632                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
633        }
634        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
635            local_var_req_builder = local_var_req_builder.basic_auth(
636                local_var_auth_conf.0.to_owned(),
637                local_var_auth_conf.1.to_owned(),
638            );
639        };
640        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
641            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
642        };
643
644        let local_var_req = local_var_req_builder.build()?;
645        let local_var_resp = local_var_client.execute(local_var_req).await?;
646
647        let local_var_status = local_var_resp.status();
648        let local_var_content = local_var_resp.text().await?;
649
650        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
651            Ok(())
652        } else {
653            let local_var_entity: Option<InstallAddonFromUrlError> =
654                serde_json::from_str(&local_var_content).ok();
655            let local_var_error = ResponseContent {
656                status: local_var_status,
657                content: local_var_content,
658                entity: local_var_entity,
659            };
660            Err(Error::ResponseError(local_var_error))
661        }
662    }
663
664    async fn uninstall_addon<'addon_id, 'service_id>(
665        &self,
666        addon_id: &'addon_id str,
667        service_id: Option<&'service_id str>,
668    ) -> Result<(), Error<UninstallAddonError>> {
669        let local_var_configuration = &self.configuration;
670
671        let local_var_client = &local_var_configuration.client;
672
673        let local_var_uri_str = format!(
674            "{}/addons/{addonId}/uninstall",
675            local_var_configuration.base_path,
676            addonId = crate::apis::urlencode(addon_id)
677        );
678        let mut local_var_req_builder =
679            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
680
681        if let Some(ref local_var_str) = service_id {
682            local_var_req_builder =
683                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
684        }
685        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
686            local_var_req_builder = local_var_req_builder
687                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
688        }
689        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
690            local_var_req_builder = local_var_req_builder.basic_auth(
691                local_var_auth_conf.0.to_owned(),
692                local_var_auth_conf.1.to_owned(),
693            );
694        };
695        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
696            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
697        };
698
699        let local_var_req = local_var_req_builder.build()?;
700        let local_var_resp = local_var_client.execute(local_var_req).await?;
701
702        let local_var_status = local_var_resp.status();
703        let local_var_content = local_var_resp.text().await?;
704
705        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
706            Ok(())
707        } else {
708            let local_var_entity: Option<UninstallAddonError> =
709                serde_json::from_str(&local_var_content).ok();
710            let local_var_error = ResponseContent {
711                status: local_var_status,
712                content: local_var_content,
713                entity: local_var_entity,
714            };
715            Err(Error::ResponseError(local_var_error))
716        }
717    }
718
719    async fn update_addon_configuration<'addon_id, 'service_id, 'request_body>(
720        &self,
721        addon_id: &'addon_id str,
722        service_id: Option<&'service_id str>,
723        request_body: Option<std::collections::HashMap<String, serde_json::Value>>,
724    ) -> Result<String, Error<UpdateAddonConfigurationError>> {
725        let local_var_configuration = &self.configuration;
726
727        let local_var_client = &local_var_configuration.client;
728
729        let local_var_uri_str = format!(
730            "{}/addons/{addonId}/config",
731            local_var_configuration.base_path,
732            addonId = crate::apis::urlencode(addon_id)
733        );
734        let mut local_var_req_builder =
735            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
736
737        if let Some(ref local_var_str) = service_id {
738            local_var_req_builder =
739                local_var_req_builder.query(&[("serviceId", &local_var_str.to_string())]);
740        }
741        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
742            local_var_req_builder = local_var_req_builder
743                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
744        }
745        if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
746            local_var_req_builder = local_var_req_builder.basic_auth(
747                local_var_auth_conf.0.to_owned(),
748                local_var_auth_conf.1.to_owned(),
749            );
750        };
751        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
752            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
753        };
754        local_var_req_builder = local_var_req_builder.json(&request_body);
755
756        let local_var_req = local_var_req_builder.build()?;
757        let local_var_resp = local_var_client.execute(local_var_req).await?;
758
759        let local_var_status = local_var_resp.status();
760        let local_var_content_type = local_var_resp
761            .headers()
762            .get("content-type")
763            .and_then(|v| v.to_str().ok())
764            .unwrap_or("application/octet-stream");
765        let local_var_content_type = super::ContentType::from(local_var_content_type);
766        let local_var_content = local_var_resp.text().await?;
767
768        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
769            match local_var_content_type {
770                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
771                ContentType::Text => {
772                    return Err(Error::from(serde_json::Error::custom(
773                        "Received `text/plain` content type response that cannot be converted to `String`",
774                    )));
775                }
776                ContentType::Unsupported(local_var_unknown_type) => {
777                    return Err(Error::from(serde_json::Error::custom(format!(
778                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
779                    ))));
780                }
781            }
782        } else {
783            let local_var_entity: Option<UpdateAddonConfigurationError> =
784                serde_json::from_str(&local_var_content).ok();
785            let local_var_error = ResponseContent {
786                status: local_var_status,
787                content: local_var_content,
788                entity: local_var_entity,
789            };
790            Err(Error::ResponseError(local_var_error))
791        }
792    }
793}
794
795/// struct for typed errors of method [AddonsApi::get_addon_by_id]
796#[derive(Debug, Clone, Serialize, Deserialize)]
797#[serde(untagged)]
798pub enum GetAddonByIdError {
799    Status404(),
800    UnknownValue(serde_json::Value),
801}
802
803/// struct for typed errors of method [AddonsApi::get_addon_configuration]
804#[derive(Debug, Clone, Serialize, Deserialize)]
805#[serde(untagged)]
806pub enum GetAddonConfigurationError {
807    Status404(),
808    Status500(),
809    UnknownValue(serde_json::Value),
810}
811
812/// struct for typed errors of method [AddonsApi::get_addon_services]
813#[derive(Debug, Clone, Serialize, Deserialize)]
814#[serde(untagged)]
815pub enum GetAddonServicesError {
816    Status404(),
817    UnknownValue(serde_json::Value),
818}
819
820/// struct for typed errors of method [AddonsApi::get_addon_types]
821#[derive(Debug, Clone, Serialize, Deserialize)]
822#[serde(untagged)]
823pub enum GetAddonTypesError {
824    UnknownValue(serde_json::Value),
825}
826
827/// struct for typed errors of method [AddonsApi::get_addons]
828#[derive(Debug, Clone, Serialize, Deserialize)]
829#[serde(untagged)]
830pub enum GetAddonsError {
831    Status404(),
832    UnknownValue(serde_json::Value),
833}
834
835/// struct for typed errors of method [AddonsApi::get_suggested_addons]
836#[derive(Debug, Clone, Serialize, Deserialize)]
837#[serde(untagged)]
838pub enum GetSuggestedAddonsError {
839    UnknownValue(serde_json::Value),
840}
841
842/// struct for typed errors of method [AddonsApi::install_addon_by_id]
843#[derive(Debug, Clone, Serialize, Deserialize)]
844#[serde(untagged)]
845pub enum InstallAddonByIdError {
846    Status404(),
847    UnknownValue(serde_json::Value),
848}
849
850/// struct for typed errors of method [AddonsApi::install_addon_from_url]
851#[derive(Debug, Clone, Serialize, Deserialize)]
852#[serde(untagged)]
853pub enum InstallAddonFromUrlError {
854    Status400(),
855    UnknownValue(serde_json::Value),
856}
857
858/// struct for typed errors of method [AddonsApi::uninstall_addon]
859#[derive(Debug, Clone, Serialize, Deserialize)]
860#[serde(untagged)]
861pub enum UninstallAddonError {
862    Status404(),
863    UnknownValue(serde_json::Value),
864}
865
866/// struct for typed errors of method [AddonsApi::update_addon_configuration]
867#[derive(Debug, Clone, Serialize, Deserialize)]
868#[serde(untagged)]
869pub enum UpdateAddonConfigurationError {
870    Status404(),
871    Status500(),
872    UnknownValue(serde_json::Value),
873}