bitwarden_api_api/apis/
installations_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 InstallationsIdGetError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum InstallationsPostError {
28 UnknownValue(serde_json::Value),
29}
30
31pub async fn installations_id_get(
32 configuration: &configuration::Configuration,
33 id: uuid::Uuid,
34) -> Result<models::InstallationResponseModel, Error<InstallationsIdGetError>> {
35 let p_id = id;
37
38 let uri_str = format!(
39 "{}/installations/{id}",
40 configuration.base_path,
41 id = crate::apis::urlencode(p_id.to_string())
42 );
43 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45 if let Some(ref user_agent) = configuration.user_agent {
46 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
47 }
48 if let Some(ref token) = configuration.oauth_access_token {
49 req_builder = req_builder.bearer_auth(token.to_owned());
50 };
51
52 let req = req_builder.build()?;
53 let resp = configuration.client.execute(req).await?;
54
55 let status = resp.status();
56 let content_type = resp
57 .headers()
58 .get("content-type")
59 .and_then(|v| v.to_str().ok())
60 .unwrap_or("application/octet-stream");
61 let content_type = super::ContentType::from(content_type);
62
63 if !status.is_client_error() && !status.is_server_error() {
64 let content = resp.text().await?;
65 match content_type {
66 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
67 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`"))),
68 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::InstallationResponseModel`")))),
69 }
70 } else {
71 let content = resp.text().await?;
72 let entity: Option<InstallationsIdGetError> = serde_json::from_str(&content).ok();
73 Err(Error::ResponseError(ResponseContent {
74 status,
75 content,
76 entity,
77 }))
78 }
79}
80
81pub async fn installations_post(
82 configuration: &configuration::Configuration,
83 installation_request_model: Option<models::InstallationRequestModel>,
84) -> Result<models::InstallationResponseModel, Error<InstallationsPostError>> {
85 let p_installation_request_model = installation_request_model;
87
88 let uri_str = format!("{}/installations", configuration.base_path);
89 let mut req_builder = configuration
90 .client
91 .request(reqwest::Method::POST, &uri_str);
92
93 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96 if let Some(ref token) = configuration.oauth_access_token {
97 req_builder = req_builder.bearer_auth(token.to_owned());
98 };
99 req_builder = req_builder.json(&p_installation_request_model);
100
101 let req = req_builder.build()?;
102 let resp = configuration.client.execute(req).await?;
103
104 let status = resp.status();
105 let content_type = resp
106 .headers()
107 .get("content-type")
108 .and_then(|v| v.to_str().ok())
109 .unwrap_or("application/octet-stream");
110 let content_type = super::ContentType::from(content_type);
111
112 if !status.is_client_error() && !status.is_server_error() {
113 let content = resp.text().await?;
114 match content_type {
115 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
116 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`"))),
117 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::InstallationResponseModel`")))),
118 }
119 } else {
120 let content = resp.text().await?;
121 let entity: Option<InstallationsPostError> = serde_json::from_str(&content).ok();
122 Err(Error::ResponseError(ResponseContent {
123 status,
124 content,
125 entity,
126 }))
127 }
128}