rocie_client/apis/
api_get_auth_unit_property_api.rs1use super::{ContentType, Error, configuration};
22use crate::{apis::ResponseContent, models};
23use reqwest;
24use serde::{Deserialize, Serialize, de::Error as _};
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum UnitPropertiesError {
30 Status401(),
31 Status500(String),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum UnitPropertyByIdError {
39 Status401(),
40 Status404(),
41 Status500(String),
42 UnknownValue(serde_json::Value),
43}
44
45pub async fn unit_properties(
46 configuration: &configuration::Configuration,
47) -> Result<Vec<models::UnitProperty>, Error<UnitPropertiesError>> {
48 let uri_str = format!("{}/unit-properties/", configuration.base_path);
49 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54
55 let req = req_builder.build()?;
56 let resp = configuration.client.execute(req).await?;
57
58 let status = resp.status();
59 let content_type = resp
60 .headers()
61 .get("content-type")
62 .and_then(|v| v.to_str().ok())
63 .unwrap_or("application/octet-stream");
64 let content_type = super::ContentType::from(content_type);
65
66 if !status.is_client_error() && !status.is_server_error() {
67 let content = resp.text().await?;
68 match content_type {
69 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70 ContentType::Text => {
71 return Err(Error::from(serde_json::Error::custom(
72 "Received `text/plain` content type response that cannot be converted to `Vec<models::UnitProperty>`",
73 )));
74 }
75 ContentType::Unsupported(unknown_type) => {
76 return Err(Error::from(serde_json::Error::custom(format!(
77 "Received `{unknown_type}` content type response that cannot be converted to `Vec<models::UnitProperty>`"
78 ))));
79 }
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<UnitPropertiesError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent {
85 status,
86 content,
87 entity,
88 }))
89 }
90}
91
92pub async fn unit_property_by_id(
93 configuration: &configuration::Configuration,
94 id: models::UnitPropertyId,
95) -> Result<models::UnitProperty, Error<UnitPropertyByIdError>> {
96 let p_path_id = id;
98
99 let uri_str = format!(
100 "{}/unit-property/{id}",
101 configuration.base_path,
102 id = p_path_id.to_string()
103 );
104 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106 if let Some(ref user_agent) = configuration.user_agent {
107 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108 }
109
110 let req = req_builder.build()?;
111 let resp = configuration.client.execute(req).await?;
112
113 let status = resp.status();
114 let content_type = resp
115 .headers()
116 .get("content-type")
117 .and_then(|v| v.to_str().ok())
118 .unwrap_or("application/octet-stream");
119 let content_type = super::ContentType::from(content_type);
120
121 if !status.is_client_error() && !status.is_server_error() {
122 let content = resp.text().await?;
123 match content_type {
124 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
125 ContentType::Text => {
126 return Err(Error::from(serde_json::Error::custom(
127 "Received `text/plain` content type response that cannot be converted to `models::UnitProperty`",
128 )));
129 }
130 ContentType::Unsupported(unknown_type) => {
131 return Err(Error::from(serde_json::Error::custom(format!(
132 "Received `{unknown_type}` content type response that cannot be converted to `models::UnitProperty`"
133 ))));
134 }
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<UnitPropertyByIdError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent {
140 status,
141 content,
142 entity,
143 }))
144 }
145}