hab_rs_api_client/apis/
uuid_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 UuidApi: Send + Sync {
24 async fn get_uuid(&self) -> Result<String, Error<GetUuidError>>;
28}
29
30pub struct UuidApiClient {
31 configuration: Arc<configuration::Configuration>,
32}
33
34impl UuidApiClient {
35 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
36 Self { configuration }
37 }
38}
39
40#[async_trait]
41impl UuidApi for UuidApiClient {
42 async fn get_uuid(&self) -> Result<String, Error<GetUuidError>> {
43 let local_var_configuration = &self.configuration;
44
45 let local_var_client = &local_var_configuration.client;
46
47 let local_var_uri_str = format!("{}/uuid", local_var_configuration.base_path);
48 let mut local_var_req_builder =
49 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
50
51 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
52 local_var_req_builder = local_var_req_builder
53 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54 }
55
56 let local_var_req = local_var_req_builder.build()?;
57 let local_var_resp = local_var_client.execute(local_var_req).await?;
58
59 let local_var_status = local_var_resp.status();
60 let local_var_content_type = local_var_resp
61 .headers()
62 .get("content-type")
63 .and_then(|v| v.to_str().ok())
64 .unwrap_or("application/octet-stream");
65 let local_var_content_type = super::ContentType::from(local_var_content_type);
66 let local_var_content = local_var_resp.text().await?;
67
68 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69 match local_var_content_type {
70 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
71 ContentType::Text => return Ok(local_var_content),
72 ContentType::Unsupported(local_var_unknown_type) => {
73 return Err(Error::from(serde_json::Error::custom(format!(
74 "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
75 ))));
76 }
77 }
78 } else {
79 let local_var_entity: Option<GetUuidError> =
80 serde_json::from_str(&local_var_content).ok();
81 let local_var_error = ResponseContent {
82 status: local_var_status,
83 content: local_var_content,
84 entity: local_var_entity,
85 };
86 Err(Error::ResponseError(local_var_error))
87 }
88 }
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum GetUuidError {
95 UnknownValue(serde_json::Value),
96}