mesa_dev_oapi/apis/
org_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetByOrgError {
22 Status400(models::PostByOrgApiKeys400Response),
23 Status401(models::PostByOrgApiKeys400Response),
24 Status403(models::PostByOrgApiKeys400Response),
25 Status404(models::PostByOrgApiKeys400Response),
26 Status406(models::PostByOrgApiKeys400Response),
27 Status409(models::PostByOrgApiKeys400Response),
28 Status500(models::PostByOrgApiKeys400Response),
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_by_org(configuration: &configuration::Configuration, org: &str) -> Result<models::GetByOrg200Response, Error<GetByOrgError>> {
35 let p_path_org = org;
37
38 let uri_str = format!("{}/{org}", configuration.base_path, org=crate::apis::urlencode(p_path_org));
39 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
40
41 if let Some(ref user_agent) = configuration.user_agent {
42 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43 }
44 if let Some(ref token) = configuration.bearer_access_token {
45 req_builder = req_builder.bearer_auth(token.to_owned());
46 };
47
48 let req = req_builder.build()?;
49 let resp = configuration.client.execute(req).await?;
50
51 let status = resp.status();
52 let content_type = resp
53 .headers()
54 .get("content-type")
55 .and_then(|v| v.to_str().ok())
56 .unwrap_or("application/octet-stream");
57 let content_type = super::ContentType::from(content_type);
58
59 if !status.is_client_error() && !status.is_server_error() {
60 let content = resp.text().await?;
61 match content_type {
62 ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
63 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrg200Response`"))),
64 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::GetByOrg200Response`")))),
65 }
66 } else {
67 let content = resp.text().await?;
68 let entity: Option<GetByOrgError> = serde_json::from_str(&content).ok();
69 Err(Error::ResponseError(ResponseContent { status, content, entity }))
70 }
71}
72