bitwarden_api_api/apis/
sync_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 [`sync_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SyncGetError {
21    UnknownValue(serde_json::Value),
22}
23
24pub async fn sync_get(
25    configuration: &configuration::Configuration,
26    exclude_domains: Option<bool>,
27) -> Result<models::SyncResponseModel, Error<SyncGetError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    let p_exclude_domains = exclude_domains;
30
31    let uri_str = format!("{}/sync", configuration.base_path);
32    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
33
34    if let Some(ref param_value) = p_exclude_domains {
35        req_builder = req_builder.query(&[("excludeDomains", &param_value.to_string())]);
36    }
37    if let Some(ref user_agent) = configuration.user_agent {
38        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
39    }
40    if let Some(ref token) = configuration.oauth_access_token {
41        req_builder = req_builder.bearer_auth(token.to_owned());
42    };
43
44    let req = req_builder.build()?;
45    let resp = configuration.client.execute(req).await?;
46
47    let status = resp.status();
48    let content_type = resp
49        .headers()
50        .get("content-type")
51        .and_then(|v| v.to_str().ok())
52        .unwrap_or("application/octet-stream");
53    let content_type = super::ContentType::from(content_type);
54
55    if !status.is_client_error() && !status.is_server_error() {
56        let content = resp.text().await?;
57        match content_type {
58            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
59            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncResponseModel`"))),
60            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::SyncResponseModel`")))),
61        }
62    } else {
63        let content = resp.text().await?;
64        let entity: Option<SyncGetError> = serde_json::from_str(&content).ok();
65        Err(Error::ResponseError(ResponseContent {
66            status,
67            content,
68            entity,
69        }))
70    }
71}