rocie_client/apis/
api_get_auth_inventory_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 AmountByIdError {
30 Status401(),
31 Status404(),
32 Status500(String),
33 UnknownValue(serde_json::Value),
34}
35
36pub async fn amount_by_id(
37 configuration: &configuration::Configuration,
38 id: models::ProductId,
39) -> Result<models::ProductAmount, Error<AmountByIdError>> {
40 let p_path_id = id;
42
43 let uri_str = format!(
44 "{}/inventory/{id}",
45 configuration.base_path,
46 id = p_path_id.to_string()
47 );
48 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
49
50 if let Some(ref user_agent) = configuration.user_agent {
51 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52 }
53
54 let req = req_builder.build()?;
55 let resp = configuration.client.execute(req).await?;
56
57 let status = resp.status();
58 let content_type = resp
59 .headers()
60 .get("content-type")
61 .and_then(|v| v.to_str().ok())
62 .unwrap_or("application/octet-stream");
63 let content_type = super::ContentType::from(content_type);
64
65 if !status.is_client_error() && !status.is_server_error() {
66 let content = resp.text().await?;
67 match content_type {
68 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69 ContentType::Text => {
70 return Err(Error::from(serde_json::Error::custom(
71 "Received `text/plain` content type response that cannot be converted to `models::ProductAmount`",
72 )));
73 }
74 ContentType::Unsupported(unknown_type) => {
75 return Err(Error::from(serde_json::Error::custom(format!(
76 "Received `{unknown_type}` content type response that cannot be converted to `models::ProductAmount`"
77 ))));
78 }
79 }
80 } else {
81 let content = resp.text().await?;
82 let entity: Option<AmountByIdError> = serde_json::from_str(&content).ok();
83 Err(Error::ResponseError(ResponseContent {
84 status,
85 content,
86 entity,
87 }))
88 }
89}