bitwarden_api_api/apis/
settings_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait SettingsApi: Send + Sync {
29    /// GET /settings/domains
30    async fn get_domains<'a>(
31        &self,
32        excluded: Option<bool>,
33    ) -> Result<models::DomainsResponseModel, Error<GetDomainsError>>;
34
35    /// PUT /settings/domains
36    async fn put_domains<'a>(
37        &self,
38        update_domains_request_model: Option<models::UpdateDomainsRequestModel>,
39    ) -> Result<models::DomainsResponseModel, Error<PutDomainsError>>;
40}
41
42pub struct SettingsApiClient {
43    configuration: Arc<configuration::Configuration>,
44}
45
46impl SettingsApiClient {
47    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
48        Self { configuration }
49    }
50}
51
52#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
53#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
54impl SettingsApi for SettingsApiClient {
55    async fn get_domains<'a>(
56        &self,
57        excluded: Option<bool>,
58    ) -> Result<models::DomainsResponseModel, Error<GetDomainsError>> {
59        let local_var_configuration = &self.configuration;
60
61        let local_var_client = &local_var_configuration.client;
62
63        let local_var_uri_str = format!("{}/settings/domains", local_var_configuration.base_path);
64        let mut local_var_req_builder =
65            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
66
67        if let Some(ref param_value) = excluded {
68            local_var_req_builder =
69                local_var_req_builder.query(&[("excluded", &param_value.to_string())]);
70        }
71        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
72            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
73        };
74        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
75
76        let local_var_req = local_var_req_builder.build()?;
77        let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79        let local_var_status = local_var_resp.status();
80        let local_var_content_type = local_var_resp
81            .headers()
82            .get("content-type")
83            .and_then(|v| v.to_str().ok())
84            .unwrap_or("application/octet-stream");
85        let local_var_content_type = super::ContentType::from(local_var_content_type);
86        let local_var_content = local_var_resp.text().await?;
87
88        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89            match local_var_content_type {
90                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
91                ContentType::Text => {
92                    return Err(Error::from(serde_json::Error::custom(
93                        "Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`",
94                    )));
95                }
96                ContentType::Unsupported(local_var_unknown_type) => {
97                    return Err(Error::from(serde_json::Error::custom(format!(
98                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`"
99                    ))));
100                }
101            }
102        } else {
103            let local_var_entity: Option<GetDomainsError> =
104                serde_json::from_str(&local_var_content).ok();
105            let local_var_error = ResponseContent {
106                status: local_var_status,
107                content: local_var_content,
108                entity: local_var_entity,
109            };
110            Err(Error::ResponseError(local_var_error))
111        }
112    }
113
114    async fn put_domains<'a>(
115        &self,
116        update_domains_request_model: Option<models::UpdateDomainsRequestModel>,
117    ) -> Result<models::DomainsResponseModel, Error<PutDomainsError>> {
118        let local_var_configuration = &self.configuration;
119
120        let local_var_client = &local_var_configuration.client;
121
122        let local_var_uri_str = format!("{}/settings/domains", local_var_configuration.base_path);
123        let mut local_var_req_builder =
124            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
125
126        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
127            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
128        };
129        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
130        local_var_req_builder = local_var_req_builder.json(&update_domains_request_model);
131
132        let local_var_req = local_var_req_builder.build()?;
133        let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135        let local_var_status = local_var_resp.status();
136        let local_var_content_type = local_var_resp
137            .headers()
138            .get("content-type")
139            .and_then(|v| v.to_str().ok())
140            .unwrap_or("application/octet-stream");
141        let local_var_content_type = super::ContentType::from(local_var_content_type);
142        let local_var_content = local_var_resp.text().await?;
143
144        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145            match local_var_content_type {
146                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
147                ContentType::Text => {
148                    return Err(Error::from(serde_json::Error::custom(
149                        "Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`",
150                    )));
151                }
152                ContentType::Unsupported(local_var_unknown_type) => {
153                    return Err(Error::from(serde_json::Error::custom(format!(
154                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`"
155                    ))));
156                }
157            }
158        } else {
159            let local_var_entity: Option<PutDomainsError> =
160                serde_json::from_str(&local_var_content).ok();
161            let local_var_error = ResponseContent {
162                status: local_var_status,
163                content: local_var_content,
164                entity: local_var_entity,
165            };
166            Err(Error::ResponseError(local_var_error))
167        }
168    }
169}
170
171/// struct for typed errors of method [`SettingsApi::get_domains`]
172#[derive(Debug, Clone, Serialize, Deserialize)]
173#[serde(untagged)]
174pub enum GetDomainsError {
175    UnknownValue(serde_json::Value),
176}
177/// struct for typed errors of method [`SettingsApi::put_domains`]
178#[derive(Debug, Clone, Serialize, Deserialize)]
179#[serde(untagged)]
180pub enum PutDomainsError {
181    UnknownValue(serde_json::Value),
182}