bitwarden_api_identity/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
48 let req = req_builder.build()?;
49 let resp = configuration.client.execute(req).await?;
50
51 let status = resp.status();
52 let content_type = resp
53 .headers()
54 .get("content-type")
55 .and_then(|v| v.to_str().ok())
56 .unwrap_or("application/octet-stream");
57 let content_type = super::ContentType::from(content_type);
58
59 if !status.is_client_error() && !status.is_server_error() {
60 let content = resp.text().await?;
61 match content_type {
62 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
63 ContentType::Text => return Ok(content),
64 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`")))),
65 }
66 } else {
67 let content = resp.text().await?;
68 let entity: Option<AliveGetError> = serde_json::from_str(&content).ok();
69 Err(Error::ResponseError(ResponseContent {
70 status,
71 content,
72 entity,
73 }))
74 }
75}
76
77pub async fn now_get(
78 configuration: &configuration::Configuration,
79) -> Result<String, Error<NowGetError>> {
80 let uri_str = format!("{}/now", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86
87 let req = req_builder.build()?;
88 let resp = configuration.client.execute(req).await?;
89
90 let status = resp.status();
91 let content_type = resp
92 .headers()
93 .get("content-type")
94 .and_then(|v| v.to_str().ok())
95 .unwrap_or("application/octet-stream");
96 let content_type = super::ContentType::from(content_type);
97
98 if !status.is_client_error() && !status.is_server_error() {
99 let content = resp.text().await?;
100 match content_type {
101 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102 ContentType::Text => return Ok(content),
103 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`")))),
104 }
105 } else {
106 let content = resp.text().await?;
107 let entity: Option<NowGetError> = serde_json::from_str(&content).ok();
108 Err(Error::ResponseError(ResponseContent {
109 status,
110 content,
111 entity,
112 }))
113 }
114}
115
116pub async fn version_get(
117 configuration: &configuration::Configuration,
118) -> Result<(), Error<VersionGetError>> {
119 let uri_str = format!("{}/version", configuration.base_path);
120 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122 if let Some(ref user_agent) = configuration.user_agent {
123 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124 }
125
126 let req = req_builder.build()?;
127 let resp = configuration.client.execute(req).await?;
128
129 let status = resp.status();
130
131 if !status.is_client_error() && !status.is_server_error() {
132 Ok(())
133 } else {
134 let content = resp.text().await?;
135 let entity: Option<VersionGetError> = serde_json::from_str(&content).ok();
136 Err(Error::ResponseError(ResponseContent {
137 status,
138 content,
139 entity,
140 }))
141 }
142}