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::{Deserialize, Serialize};
13
14use super::{configuration, 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    let local_var_configuration = configuration;
29
30    let local_var_client = &local_var_configuration.client;
31
32    let local_var_uri_str = format!("{}/sync", local_var_configuration.base_path);
33    let mut local_var_req_builder =
34        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_str) = exclude_domains {
37        local_var_req_builder =
38            local_var_req_builder.query(&[("excludeDomains", &local_var_str.to_string())]);
39    }
40    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
41        local_var_req_builder =
42            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
43    }
44    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
45        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
46    };
47
48    let local_var_req = local_var_req_builder.build()?;
49    let local_var_resp = local_var_client.execute(local_var_req).await?;
50
51    let local_var_status = local_var_resp.status();
52    let local_var_content = local_var_resp.text().await?;
53
54    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
55        serde_json::from_str(&local_var_content).map_err(Error::from)
56    } else {
57        let local_var_entity: Option<SyncGetError> = serde_json::from_str(&local_var_content).ok();
58        let local_var_error = ResponseContent {
59            status: local_var_status,
60            content: local_var_content,
61            entity: local_var_entity,
62        };
63        Err(Error::ResponseError(local_var_error))
64    }
65}