space_traders/apis/
default_api.rs1use reqwest::StatusCode;
8
9use super::{configuration, Error};
10use crate::apis::ResponseContent;
11
12#[derive(Debug, Clone)]
14pub enum GetStatusSuccess {
15 Status200(crate::models::GetStatus200Response),
17}
18
19impl GetStatusSuccess {
20 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
21 match status.as_u16() {
23 200 => Some(match serde_json::from_str(body) {
24 Ok(data) => Ok(Self::Status200(data)),
25 Err(err) => Err(err),
26 }),
27 _ => None,
28 }
29 }
30}
31
32#[derive(Debug, Clone)]
34pub enum RegisterSuccess {
35 Status201(crate::models::Register201Response),
37}
38
39impl RegisterSuccess {
40 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
41 match status.as_u16() {
43 201 => Some(match serde_json::from_str(body) {
44 Ok(data) => Ok(Self::Status201(data)),
45 Err(err) => Err(err),
46 }),
47 _ => None,
48 }
49 }
50}
51
52#[derive(Debug, Clone)]
54pub enum GetStatusError {}
55
56impl GetStatusError {
57 #[allow(unused_variables, clippy::match_single_binding)]
58 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
59 match status.as_u16() {
61 _ => None,
62 }
63 }
64}
65
66#[derive(Debug, Clone)]
68pub enum RegisterError {}
69
70impl RegisterError {
71 #[allow(unused_variables, clippy::match_single_binding)]
72 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
73 match status.as_u16() {
75 _ => None,
76 }
77 }
78}
79
80pub async fn get_status(
82 configuration: &configuration::Configuration,
83) -> Result<ResponseContent<GetStatusSuccess>, Error<GetStatusError>> {
84 let client = &configuration.client;
85
86 let uri_str = format!("{}/", configuration.base_path);
89 let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
90
91 if let Some(user_agent) = &configuration.user_agent {
95 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
96 }
97
98 if let Some(token) = &configuration.bearer_access_token {
101 req_builder = req_builder.bearer_auth(token.to_owned());
102 };
103
104 let req = req_builder.build()?;
108 let resp = client.execute(req).await?;
109
110 let status = resp.status();
112 let response_body = resp.text().await?;
113
114 if !status.is_client_error() && !status.is_server_error() {
115 match GetStatusSuccess::from_body(status, &response_body) {
117 Some(Ok(content)) => Ok(ResponseContent {
118 status,
119 response_body,
120 content,
121 }),
122 Some(Err(err)) => Err(err.into()),
123 None => Err(Error::UnknownResponse {
124 status,
125 is_error: false,
126 response_body,
127 }),
128 }
129 } else {
130 match GetStatusError::from_body(status, &response_body) {
132 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
133 status,
134 response_body,
135 content,
136 })),
137 Some(Err(err)) => Err(err.into()),
138 None => Err(Error::UnknownResponse {
139 status,
140 is_error: true,
141 response_body,
142 }),
143 }
144 }
145}
146
147pub async fn register(
149 configuration: &configuration::Configuration,
150 register_request: Option<crate::models::RegisterRequest>,
151) -> Result<ResponseContent<RegisterSuccess>, Error<RegisterError>> {
152 let client = &configuration.client;
153
154 let uri_str = format!("{}/register", configuration.base_path);
157 let mut req_builder = client.request(reqwest::Method::POST, &uri_str);
158
159 if let Some(user_agent) = &configuration.user_agent {
163 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
164 }
165
166 req_builder = req_builder.json(®ister_request);
169
170 let req = req_builder.build()?;
174 let resp = client.execute(req).await?;
175
176 let status = resp.status();
178 let response_body = resp.text().await?;
179
180 if !status.is_client_error() && !status.is_server_error() {
181 match RegisterSuccess::from_body(status, &response_body) {
183 Some(Ok(content)) => Ok(ResponseContent {
184 status,
185 response_body,
186 content,
187 }),
188 Some(Err(err)) => Err(err.into()),
189 None => Err(Error::UnknownResponse {
190 status,
191 is_error: false,
192 response_body,
193 }),
194 }
195 } else {
196 match RegisterError::from_body(status, &response_body) {
198 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
199 status,
200 response_body,
201 content,
202 })),
203 Some(Err(err)) => Err(err.into()),
204 None => Err(Error::UnknownResponse {
205 status,
206 is_error: true,
207 response_body,
208 }),
209 }
210 }
211}