bitwarden_api_api/apis/
settings_api.rs1use 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 async fn get_domains<'a>(
31 &self,
32 excluded: Option<bool>,
33 ) -> Result<models::DomainsResponseModel, Error<GetDomainsError>>;
34
35 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", ¶m_value.to_string())]);
70 }
71 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
72
73 let local_var_resp = local_var_req_builder.send().await?;
74
75 let local_var_status = local_var_resp.status();
76 let local_var_content_type = local_var_resp
77 .headers()
78 .get("content-type")
79 .and_then(|v| v.to_str().ok())
80 .unwrap_or("application/octet-stream");
81 let local_var_content_type = super::ContentType::from(local_var_content_type);
82 let local_var_content = local_var_resp.text().await?;
83
84 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85 match local_var_content_type {
86 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
87 ContentType::Text => {
88 return Err(Error::from(serde_json::Error::custom(
89 "Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`",
90 )));
91 }
92 ContentType::Unsupported(local_var_unknown_type) => {
93 return Err(Error::from(serde_json::Error::custom(format!(
94 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`"
95 ))));
96 }
97 }
98 } else {
99 let local_var_entity: Option<GetDomainsError> =
100 serde_json::from_str(&local_var_content).ok();
101 let local_var_error = ResponseContent {
102 status: local_var_status,
103 content: local_var_content,
104 entity: local_var_entity,
105 };
106 Err(Error::ResponseError(local_var_error))
107 }
108 }
109
110 async fn put_domains<'a>(
111 &self,
112 update_domains_request_model: Option<models::UpdateDomainsRequestModel>,
113 ) -> Result<models::DomainsResponseModel, Error<PutDomainsError>> {
114 let local_var_configuration = &self.configuration;
115
116 let local_var_client = &local_var_configuration.client;
117
118 let local_var_uri_str = format!("{}/settings/domains", local_var_configuration.base_path);
119 let mut local_var_req_builder =
120 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
121
122 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
123 local_var_req_builder = local_var_req_builder.json(&update_domains_request_model);
124
125 let local_var_resp = local_var_req_builder.send().await?;
126
127 let local_var_status = local_var_resp.status();
128 let local_var_content_type = local_var_resp
129 .headers()
130 .get("content-type")
131 .and_then(|v| v.to_str().ok())
132 .unwrap_or("application/octet-stream");
133 let local_var_content_type = super::ContentType::from(local_var_content_type);
134 let local_var_content = local_var_resp.text().await?;
135
136 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137 match local_var_content_type {
138 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
139 ContentType::Text => {
140 return Err(Error::from(serde_json::Error::custom(
141 "Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`",
142 )));
143 }
144 ContentType::Unsupported(local_var_unknown_type) => {
145 return Err(Error::from(serde_json::Error::custom(format!(
146 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`"
147 ))));
148 }
149 }
150 } else {
151 let local_var_entity: Option<PutDomainsError> =
152 serde_json::from_str(&local_var_content).ok();
153 let local_var_error = ResponseContent {
154 status: local_var_status,
155 content: local_var_content,
156 entity: local_var_entity,
157 };
158 Err(Error::ResponseError(local_var_error))
159 }
160 }
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize)]
165#[serde(untagged)]
166pub enum GetDomainsError {
167 UnknownValue(serde_json::Value),
168}
169#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum PutDomainsError {
173 UnknownValue(serde_json::Value),
174}