hab_rs_api_client/apis/
audio_api.rs1use super::{Error, configuration};
12use crate::apis::ContentType;
13use crate::{apis::ResponseContent, models};
14use async_trait::async_trait;
15#[cfg(feature = "mockall")]
16use mockall::automock;
17use reqwest;
18use serde::{Deserialize, Serialize, de::Error as _};
19use std::sync::Arc;
20
21#[cfg_attr(feature = "mockall", automock)]
22#[async_trait]
23pub trait AudioApi: Send + Sync {
24 async fn get_audio_default_sink<'accept_language>(
28 &self,
29 accept_language: Option<&'accept_language str>,
30 ) -> Result<models::AudioSinkDto, Error<GetAudioDefaultSinkError>>;
31
32 async fn get_audio_default_source<'accept_language>(
36 &self,
37 accept_language: Option<&'accept_language str>,
38 ) -> Result<models::AudioSourceDto, Error<GetAudioDefaultSourceError>>;
39
40 async fn get_audio_sinks<'accept_language>(
44 &self,
45 accept_language: Option<&'accept_language str>,
46 ) -> Result<Vec<models::AudioSinkDto>, Error<GetAudioSinksError>>;
47
48 async fn get_audio_sources<'accept_language>(
52 &self,
53 accept_language: Option<&'accept_language str>,
54 ) -> Result<Vec<models::AudioSourceDto>, Error<GetAudioSourcesError>>;
55}
56
57pub struct AudioApiClient {
58 configuration: Arc<configuration::Configuration>,
59}
60
61impl AudioApiClient {
62 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63 Self { configuration }
64 }
65}
66
67#[async_trait]
68impl AudioApi for AudioApiClient {
69 async fn get_audio_default_sink<'accept_language>(
70 &self,
71 accept_language: Option<&'accept_language str>,
72 ) -> Result<models::AudioSinkDto, Error<GetAudioDefaultSinkError>> {
73 let local_var_configuration = &self.configuration;
74
75 let local_var_client = &local_var_configuration.client;
76
77 let local_var_uri_str = format!("{}/audio/defaultsink", local_var_configuration.base_path);
78 let mut local_var_req_builder =
79 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
80
81 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
82 local_var_req_builder = local_var_req_builder
83 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
84 }
85 if let Some(local_var_param_value) = accept_language {
86 local_var_req_builder =
87 local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
88 }
89
90 let local_var_req = local_var_req_builder.build()?;
91 let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93 let local_var_status = local_var_resp.status();
94 let local_var_content_type = local_var_resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let local_var_content_type = super::ContentType::from(local_var_content_type);
100 let local_var_content = local_var_resp.text().await?;
101
102 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103 match local_var_content_type {
104 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
105 ContentType::Text => {
106 return Err(Error::from(serde_json::Error::custom(
107 "Received `text/plain` content type response that cannot be converted to `models::AudioSinkDto`",
108 )));
109 }
110 ContentType::Unsupported(local_var_unknown_type) => {
111 return Err(Error::from(serde_json::Error::custom(format!(
112 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AudioSinkDto`"
113 ))));
114 }
115 }
116 } else {
117 let local_var_entity: Option<GetAudioDefaultSinkError> =
118 serde_json::from_str(&local_var_content).ok();
119 let local_var_error = ResponseContent {
120 status: local_var_status,
121 content: local_var_content,
122 entity: local_var_entity,
123 };
124 Err(Error::ResponseError(local_var_error))
125 }
126 }
127
128 async fn get_audio_default_source<'accept_language>(
129 &self,
130 accept_language: Option<&'accept_language str>,
131 ) -> Result<models::AudioSourceDto, Error<GetAudioDefaultSourceError>> {
132 let local_var_configuration = &self.configuration;
133
134 let local_var_client = &local_var_configuration.client;
135
136 let local_var_uri_str =
137 format!("{}/audio/defaultsource", local_var_configuration.base_path);
138 let mut local_var_req_builder =
139 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
140
141 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142 local_var_req_builder = local_var_req_builder
143 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
144 }
145 if let Some(local_var_param_value) = accept_language {
146 local_var_req_builder =
147 local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
148 }
149
150 let local_var_req = local_var_req_builder.build()?;
151 let local_var_resp = local_var_client.execute(local_var_req).await?;
152
153 let local_var_status = local_var_resp.status();
154 let local_var_content_type = local_var_resp
155 .headers()
156 .get("content-type")
157 .and_then(|v| v.to_str().ok())
158 .unwrap_or("application/octet-stream");
159 let local_var_content_type = super::ContentType::from(local_var_content_type);
160 let local_var_content = local_var_resp.text().await?;
161
162 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163 match local_var_content_type {
164 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
165 ContentType::Text => {
166 return Err(Error::from(serde_json::Error::custom(
167 "Received `text/plain` content type response that cannot be converted to `models::AudioSourceDto`",
168 )));
169 }
170 ContentType::Unsupported(local_var_unknown_type) => {
171 return Err(Error::from(serde_json::Error::custom(format!(
172 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AudioSourceDto`"
173 ))));
174 }
175 }
176 } else {
177 let local_var_entity: Option<GetAudioDefaultSourceError> =
178 serde_json::from_str(&local_var_content).ok();
179 let local_var_error = ResponseContent {
180 status: local_var_status,
181 content: local_var_content,
182 entity: local_var_entity,
183 };
184 Err(Error::ResponseError(local_var_error))
185 }
186 }
187
188 async fn get_audio_sinks<'accept_language>(
189 &self,
190 accept_language: Option<&'accept_language str>,
191 ) -> Result<Vec<models::AudioSinkDto>, Error<GetAudioSinksError>> {
192 let local_var_configuration = &self.configuration;
193
194 let local_var_client = &local_var_configuration.client;
195
196 let local_var_uri_str = format!("{}/audio/sinks", local_var_configuration.base_path);
197 let mut local_var_req_builder =
198 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
199
200 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201 local_var_req_builder = local_var_req_builder
202 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203 }
204 if let Some(local_var_param_value) = accept_language {
205 local_var_req_builder =
206 local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
207 }
208
209 let local_var_req = local_var_req_builder.build()?;
210 let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212 let local_var_status = local_var_resp.status();
213 let local_var_content_type = local_var_resp
214 .headers()
215 .get("content-type")
216 .and_then(|v| v.to_str().ok())
217 .unwrap_or("application/octet-stream");
218 let local_var_content_type = super::ContentType::from(local_var_content_type);
219 let local_var_content = local_var_resp.text().await?;
220
221 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
222 match local_var_content_type {
223 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
224 ContentType::Text => {
225 return Err(Error::from(serde_json::Error::custom(
226 "Received `text/plain` content type response that cannot be converted to `Vec<models::AudioSinkDto>`",
227 )));
228 }
229 ContentType::Unsupported(local_var_unknown_type) => {
230 return Err(Error::from(serde_json::Error::custom(format!(
231 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::AudioSinkDto>`"
232 ))));
233 }
234 }
235 } else {
236 let local_var_entity: Option<GetAudioSinksError> =
237 serde_json::from_str(&local_var_content).ok();
238 let local_var_error = ResponseContent {
239 status: local_var_status,
240 content: local_var_content,
241 entity: local_var_entity,
242 };
243 Err(Error::ResponseError(local_var_error))
244 }
245 }
246
247 async fn get_audio_sources<'accept_language>(
248 &self,
249 accept_language: Option<&'accept_language str>,
250 ) -> Result<Vec<models::AudioSourceDto>, Error<GetAudioSourcesError>> {
251 let local_var_configuration = &self.configuration;
252
253 let local_var_client = &local_var_configuration.client;
254
255 let local_var_uri_str = format!("{}/audio/sources", local_var_configuration.base_path);
256 let mut local_var_req_builder =
257 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
258
259 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
260 local_var_req_builder = local_var_req_builder
261 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
262 }
263 if let Some(local_var_param_value) = accept_language {
264 local_var_req_builder =
265 local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
266 }
267
268 let local_var_req = local_var_req_builder.build()?;
269 let local_var_resp = local_var_client.execute(local_var_req).await?;
270
271 let local_var_status = local_var_resp.status();
272 let local_var_content_type = local_var_resp
273 .headers()
274 .get("content-type")
275 .and_then(|v| v.to_str().ok())
276 .unwrap_or("application/octet-stream");
277 let local_var_content_type = super::ContentType::from(local_var_content_type);
278 let local_var_content = local_var_resp.text().await?;
279
280 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281 match local_var_content_type {
282 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
283 ContentType::Text => {
284 return Err(Error::from(serde_json::Error::custom(
285 "Received `text/plain` content type response that cannot be converted to `Vec<models::AudioSourceDto>`",
286 )));
287 }
288 ContentType::Unsupported(local_var_unknown_type) => {
289 return Err(Error::from(serde_json::Error::custom(format!(
290 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::AudioSourceDto>`"
291 ))));
292 }
293 }
294 } else {
295 let local_var_entity: Option<GetAudioSourcesError> =
296 serde_json::from_str(&local_var_content).ok();
297 let local_var_error = ResponseContent {
298 status: local_var_status,
299 content: local_var_content,
300 entity: local_var_entity,
301 };
302 Err(Error::ResponseError(local_var_error))
303 }
304 }
305}
306
307#[derive(Debug, Clone, Serialize, Deserialize)]
309#[serde(untagged)]
310pub enum GetAudioDefaultSinkError {
311 Status404(),
312 UnknownValue(serde_json::Value),
313}
314
315#[derive(Debug, Clone, Serialize, Deserialize)]
317#[serde(untagged)]
318pub enum GetAudioDefaultSourceError {
319 Status404(),
320 UnknownValue(serde_json::Value),
321}
322
323#[derive(Debug, Clone, Serialize, Deserialize)]
325#[serde(untagged)]
326pub enum GetAudioSinksError {
327 UnknownValue(serde_json::Value),
328}
329
330#[derive(Debug, Clone, Serialize, Deserialize)]
332#[serde(untagged)]
333pub enum GetAudioSourcesError {
334 UnknownValue(serde_json::Value),
335}