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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`settings_domains_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SettingsDomainsGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`settings_domains_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum SettingsDomainsPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`settings_domains_put`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum SettingsDomainsPutError {
35    UnknownValue(serde_json::Value),
36}
37
38pub async fn settings_domains_get(
39    configuration: &configuration::Configuration,
40    excluded: Option<bool>,
41) -> Result<models::DomainsResponseModel, Error<SettingsDomainsGetError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_excluded = excluded;
44
45    let uri_str = format!("{}/settings/domains", configuration.base_path);
46    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48    if let Some(ref param_value) = p_excluded {
49        req_builder = req_builder.query(&[("excluded", &param_value.to_string())]);
50    }
51    if let Some(ref user_agent) = configuration.user_agent {
52        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53    }
54    if let Some(ref token) = configuration.oauth_access_token {
55        req_builder = req_builder.bearer_auth(token.to_owned());
56    };
57
58    let req = req_builder.build()?;
59    let resp = configuration.client.execute(req).await?;
60
61    let status = resp.status();
62    let content_type = resp
63        .headers()
64        .get("content-type")
65        .and_then(|v| v.to_str().ok())
66        .unwrap_or("application/octet-stream");
67    let content_type = super::ContentType::from(content_type);
68
69    if !status.is_client_error() && !status.is_server_error() {
70        let content = resp.text().await?;
71        match content_type {
72            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
73            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`"))),
74            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`")))),
75        }
76    } else {
77        let content = resp.text().await?;
78        let entity: Option<SettingsDomainsGetError> = serde_json::from_str(&content).ok();
79        Err(Error::ResponseError(ResponseContent {
80            status,
81            content,
82            entity,
83        }))
84    }
85}
86
87pub async fn settings_domains_post(
88    configuration: &configuration::Configuration,
89    update_domains_request_model: Option<models::UpdateDomainsRequestModel>,
90) -> Result<models::DomainsResponseModel, Error<SettingsDomainsPostError>> {
91    // add a prefix to parameters to efficiently prevent name collisions
92    let p_update_domains_request_model = update_domains_request_model;
93
94    let uri_str = format!("{}/settings/domains", configuration.base_path);
95    let mut req_builder = configuration
96        .client
97        .request(reqwest::Method::POST, &uri_str);
98
99    if let Some(ref user_agent) = configuration.user_agent {
100        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101    }
102    if let Some(ref token) = configuration.oauth_access_token {
103        req_builder = req_builder.bearer_auth(token.to_owned());
104    };
105    req_builder = req_builder.json(&p_update_domains_request_model);
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111    let content_type = resp
112        .headers()
113        .get("content-type")
114        .and_then(|v| v.to_str().ok())
115        .unwrap_or("application/octet-stream");
116    let content_type = super::ContentType::from(content_type);
117
118    if !status.is_client_error() && !status.is_server_error() {
119        let content = resp.text().await?;
120        match content_type {
121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`"))),
123            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`")))),
124        }
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<SettingsDomainsPostError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent {
129            status,
130            content,
131            entity,
132        }))
133    }
134}
135
136pub async fn settings_domains_put(
137    configuration: &configuration::Configuration,
138    update_domains_request_model: Option<models::UpdateDomainsRequestModel>,
139) -> Result<models::DomainsResponseModel, Error<SettingsDomainsPutError>> {
140    // add a prefix to parameters to efficiently prevent name collisions
141    let p_update_domains_request_model = update_domains_request_model;
142
143    let uri_str = format!("{}/settings/domains", configuration.base_path);
144    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
145
146    if let Some(ref user_agent) = configuration.user_agent {
147        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148    }
149    if let Some(ref token) = configuration.oauth_access_token {
150        req_builder = req_builder.bearer_auth(token.to_owned());
151    };
152    req_builder = req_builder.json(&p_update_domains_request_model);
153
154    let req = req_builder.build()?;
155    let resp = configuration.client.execute(req).await?;
156
157    let status = resp.status();
158    let content_type = resp
159        .headers()
160        .get("content-type")
161        .and_then(|v| v.to_str().ok())
162        .unwrap_or("application/octet-stream");
163    let content_type = super::ContentType::from(content_type);
164
165    if !status.is_client_error() && !status.is_server_error() {
166        let content = resp.text().await?;
167        match content_type {
168            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
169            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DomainsResponseModel`"))),
170            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DomainsResponseModel`")))),
171        }
172    } else {
173        let content = resp.text().await?;
174        let entity: Option<SettingsDomainsPutError> = serde_json::from_str(&content).ok();
175        Err(Error::ResponseError(ResponseContent {
176            status,
177            content,
178            entity,
179        }))
180    }
181}