bitwarden_api_api/apis/
info_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 AliveGetError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum NowGetError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum VersionGetError {
35 UnknownValue(serde_json::Value),
36}
37
38pub async fn alive_get(
39 configuration: &configuration::Configuration,
40) -> Result<String, Error<AliveGetError>> {
41 let uri_str = format!("{}/alive", configuration.base_path);
42 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
43
44 if let Some(ref user_agent) = configuration.user_agent {
45 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
46 }
47 if let Some(ref token) = configuration.oauth_access_token {
48 req_builder = req_builder.bearer_auth(token.to_owned());
49 };
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => return Ok(content),
67 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
68 }
69 } else {
70 let content = resp.text().await?;
71 let entity: Option<AliveGetError> = serde_json::from_str(&content).ok();
72 Err(Error::ResponseError(ResponseContent {
73 status,
74 content,
75 entity,
76 }))
77 }
78}
79
80pub async fn now_get(
81 configuration: &configuration::Configuration,
82) -> Result<String, Error<NowGetError>> {
83 let uri_str = format!("{}/now", configuration.base_path);
84 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(ref token) = configuration.oauth_access_token {
90 req_builder = req_builder.bearer_auth(token.to_owned());
91 };
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97 let content_type = resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let content_type = super::ContentType::from(content_type);
103
104 if !status.is_client_error() && !status.is_server_error() {
105 let content = resp.text().await?;
106 match content_type {
107 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108 ContentType::Text => return Ok(content),
109 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
110 }
111 } else {
112 let content = resp.text().await?;
113 let entity: Option<NowGetError> = serde_json::from_str(&content).ok();
114 Err(Error::ResponseError(ResponseContent {
115 status,
116 content,
117 entity,
118 }))
119 }
120}
121
122pub async fn version_get(
123 configuration: &configuration::Configuration,
124) -> Result<(), Error<VersionGetError>> {
125 let uri_str = format!("{}/version", configuration.base_path);
126 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref token) = configuration.oauth_access_token {
132 req_builder = req_builder.bearer_auth(token.to_owned());
133 };
134
135 let req = req_builder.build()?;
136 let resp = configuration.client.execute(req).await?;
137
138 let status = resp.status();
139
140 if !status.is_client_error() && !status.is_server_error() {
141 Ok(())
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<VersionGetError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent {
146 status,
147 content,
148 entity,
149 }))
150 }
151}