bitwarden_api_api/apis/
sync_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[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 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", ¶m_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}