Skip to main content

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 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 SyncApi: Send + Sync {
29    /// GET /sync
30    async fn get<'a>(
31        &self,
32        exclude_domains: Option<bool>,
33    ) -> Result<models::SyncResponseModel, Error<GetError>>;
34}
35
36pub struct SyncApiClient {
37    configuration: Arc<configuration::Configuration>,
38}
39
40impl SyncApiClient {
41    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
42        Self { configuration }
43    }
44}
45
46#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
47#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
48impl SyncApi for SyncApiClient {
49    async fn get<'a>(
50        &self,
51        exclude_domains: Option<bool>,
52    ) -> Result<models::SyncResponseModel, Error<GetError>> {
53        let local_var_configuration = &self.configuration;
54
55        let local_var_client = &local_var_configuration.client;
56
57        let local_var_uri_str = format!("{}/sync", local_var_configuration.base_path);
58        let mut local_var_req_builder =
59            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
60
61        if let Some(ref param_value) = exclude_domains {
62            local_var_req_builder =
63                local_var_req_builder.query(&[("excludeDomains", &param_value.to_string())]);
64        }
65        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
66
67        let local_var_resp = local_var_req_builder.send().await?;
68
69        let local_var_status = local_var_resp.status();
70        let local_var_content_type = local_var_resp
71            .headers()
72            .get("content-type")
73            .and_then(|v| v.to_str().ok())
74            .unwrap_or("application/octet-stream");
75        let local_var_content_type = super::ContentType::from(local_var_content_type);
76        let local_var_content = local_var_resp.text().await?;
77
78        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79            match local_var_content_type {
80                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
81                ContentType::Text => {
82                    return Err(Error::from(serde_json::Error::custom(
83                        "Received `text/plain` content type response that cannot be converted to `models::SyncResponseModel`",
84                    )));
85                }
86                ContentType::Unsupported(local_var_unknown_type) => {
87                    return Err(Error::from(serde_json::Error::custom(format!(
88                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SyncResponseModel`"
89                    ))));
90                }
91            }
92        } else {
93            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
94            let local_var_error = ResponseContent {
95                status: local_var_status,
96                content: local_var_content,
97                entity: local_var_entity,
98            };
99            Err(Error::ResponseError(local_var_error))
100        }
101    }
102}
103
104/// struct for typed errors of method [`SyncApi::get`]
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum GetError {
108    UnknownValue(serde_json::Value),
109}