rocie_client/apis/
api_get_no_auth_state_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 CanBeProvisionedError {
30 Status500(String),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum IsLoggedInError {
38 UnknownValue(serde_json::Value),
39}
40
41pub async fn can_be_provisioned(
42 configuration: &configuration::Configuration,
43) -> Result<bool, Error<CanBeProvisionedError>> {
44 let uri_str = format!("{}/can-be-provisioned", configuration.base_path);
45 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47 if let Some(ref user_agent) = configuration.user_agent {
48 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
49 }
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => {
67 return Err(Error::from(serde_json::Error::custom(
68 "Received `text/plain` content type response that cannot be converted to `bool`",
69 )));
70 }
71 ContentType::Unsupported(unknown_type) => {
72 return Err(Error::from(serde_json::Error::custom(format!(
73 "Received `{unknown_type}` content type response that cannot be converted to `bool`"
74 ))));
75 }
76 }
77 } else {
78 let content = resp.text().await?;
79 let entity: Option<CanBeProvisionedError> = serde_json::from_str(&content).ok();
80 Err(Error::ResponseError(ResponseContent {
81 status,
82 content,
83 entity,
84 }))
85 }
86}
87
88pub async fn is_logged_in(
89 configuration: &configuration::Configuration,
90) -> Result<bool, Error<IsLoggedInError>> {
91 let uri_str = format!("{}/is-logged-in", configuration.base_path);
92 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
93
94 if let Some(ref user_agent) = configuration.user_agent {
95 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
96 }
97
98 let req = req_builder.build()?;
99 let resp = configuration.client.execute(req).await?;
100
101 let status = resp.status();
102 let content_type = resp
103 .headers()
104 .get("content-type")
105 .and_then(|v| v.to_str().ok())
106 .unwrap_or("application/octet-stream");
107 let content_type = super::ContentType::from(content_type);
108
109 if !status.is_client_error() && !status.is_server_error() {
110 let content = resp.text().await?;
111 match content_type {
112 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113 ContentType::Text => {
114 return Err(Error::from(serde_json::Error::custom(
115 "Received `text/plain` content type response that cannot be converted to `bool`",
116 )));
117 }
118 ContentType::Unsupported(unknown_type) => {
119 return Err(Error::from(serde_json::Error::custom(format!(
120 "Received `{unknown_type}` content type response that cannot be converted to `bool`"
121 ))));
122 }
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<IsLoggedInError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent {
128 status,
129 content,
130 entity,
131 }))
132 }
133}