1use super::{configuration, ContentType, Error};
10use crate::{apis::ResponseContent, models};
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum CloseInstanceError {
18 Status401(models::Error),
19 Status403(models::Error),
20 Status404(models::Error),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum CreateInstanceError {
28 Status401(models::Error),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetInstanceError {
36 Status401(models::Error),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetInstanceByShortNameError {
44 Status401(models::Error),
45 Status404(models::Error),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum GetRecentLocationsError {
53 Status401(models::Error),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetShortNameError {
61 Status401(models::Error),
62 UnknownValue(serde_json::Value),
63}
64
65pub async fn close_instance(
67 configuration: &configuration::Configuration,
68 world_id: &str,
69 instance_id: &str,
70 hard_close: Option<bool>,
71 closed_at: Option<String>,
72) -> Result<models::Instance, Error<CloseInstanceError>> {
73 let p_path_world_id = world_id;
75 let p_path_instance_id = instance_id;
76 let p_query_hard_close = hard_close;
77 let p_query_closed_at = closed_at;
78
79 let uri_str = format!(
80 "{}/instances/{worldId}:{instanceId}",
81 configuration.base_path,
82 worldId = crate::apis::urlencode(p_path_world_id),
83 instanceId = crate::apis::urlencode(p_path_instance_id)
84 );
85 let mut req_builder = configuration
86 .client
87 .request(reqwest::Method::DELETE, &uri_str);
88
89 if let Some(ref param_value) = p_query_hard_close {
90 req_builder = req_builder.query(&[("hardClose", ¶m_value.to_string())]);
91 }
92 if let Some(ref param_value) = p_query_closed_at {
93 req_builder = req_builder.query(&[("closedAt", ¶m_value.to_string())]);
94 }
95 if let Some(ref user_agent) = configuration.user_agent {
96 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97 }
98
99 let req = req_builder.build()?;
100 let resp = configuration.client.execute(req).await?;
101
102 let status = resp.status();
103 let content_type = resp
104 .headers()
105 .get("content-type")
106 .and_then(|v| v.to_str().ok())
107 .unwrap_or("application/octet-stream");
108 let content_type = super::ContentType::from(content_type);
109
110 if !status.is_client_error() && !status.is_server_error() {
111 let content = resp.text().await?;
112 match content_type {
113 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Instance`"))),
115 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::Instance`")))),
116 }
117 } else {
118 let content = resp.text().await?;
119 let entity: Option<CloseInstanceError> = serde_json::from_str(&content).ok();
120 Err(Error::ResponseError(ResponseContent {
121 status,
122 content,
123 entity,
124 }))
125 }
126}
127
128pub async fn create_instance(
130 configuration: &configuration::Configuration,
131 create_instance_request: models::CreateInstanceRequest,
132) -> Result<models::Instance, Error<CreateInstanceError>> {
133 let p_body_create_instance_request = create_instance_request;
135
136 let uri_str = format!("{}/instances", configuration.base_path);
137 let mut req_builder = configuration
138 .client
139 .request(reqwest::Method::POST, &uri_str);
140
141 if let Some(ref user_agent) = configuration.user_agent {
142 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143 }
144 req_builder = req_builder.json(&p_body_create_instance_request);
145
146 let req = req_builder.build()?;
147 let resp = configuration.client.execute(req).await?;
148
149 let status = resp.status();
150 let content_type = resp
151 .headers()
152 .get("content-type")
153 .and_then(|v| v.to_str().ok())
154 .unwrap_or("application/octet-stream");
155 let content_type = super::ContentType::from(content_type);
156
157 if !status.is_client_error() && !status.is_server_error() {
158 let content = resp.text().await?;
159 match content_type {
160 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Instance`"))),
162 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::Instance`")))),
163 }
164 } else {
165 let content = resp.text().await?;
166 let entity: Option<CreateInstanceError> = serde_json::from_str(&content).ok();
167 Err(Error::ResponseError(ResponseContent {
168 status,
169 content,
170 entity,
171 }))
172 }
173}
174
175pub async fn get_instance(
177 configuration: &configuration::Configuration,
178 world_id: &str,
179 instance_id: &str,
180) -> Result<models::Instance, Error<GetInstanceError>> {
181 let p_path_world_id = world_id;
183 let p_path_instance_id = instance_id;
184
185 let uri_str = format!(
186 "{}/instances/{worldId}:{instanceId}",
187 configuration.base_path,
188 worldId = crate::apis::urlencode(p_path_world_id),
189 instanceId = crate::apis::urlencode(p_path_instance_id)
190 );
191 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
192
193 if let Some(ref user_agent) = configuration.user_agent {
194 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
195 }
196
197 let req = req_builder.build()?;
198 let resp = configuration.client.execute(req).await?;
199
200 let status = resp.status();
201 let content_type = resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let content_type = super::ContentType::from(content_type);
207
208 if !status.is_client_error() && !status.is_server_error() {
209 let content = resp.text().await?;
210 match content_type {
211 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Instance`"))),
213 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::Instance`")))),
214 }
215 } else {
216 let content = resp.text().await?;
217 let entity: Option<GetInstanceError> = serde_json::from_str(&content).ok();
218 Err(Error::ResponseError(ResponseContent {
219 status,
220 content,
221 entity,
222 }))
223 }
224}
225
226pub async fn get_instance_by_short_name(
228 configuration: &configuration::Configuration,
229 short_name: &str,
230) -> Result<models::Instance, Error<GetInstanceByShortNameError>> {
231 let p_path_short_name = short_name;
233
234 let uri_str = format!(
235 "{}/instances/s/{shortName}",
236 configuration.base_path,
237 shortName = crate::apis::urlencode(p_path_short_name)
238 );
239 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
240
241 if let Some(ref user_agent) = configuration.user_agent {
242 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
243 }
244
245 let req = req_builder.build()?;
246 let resp = configuration.client.execute(req).await?;
247
248 let status = resp.status();
249 let content_type = resp
250 .headers()
251 .get("content-type")
252 .and_then(|v| v.to_str().ok())
253 .unwrap_or("application/octet-stream");
254 let content_type = super::ContentType::from(content_type);
255
256 if !status.is_client_error() && !status.is_server_error() {
257 let content = resp.text().await?;
258 match content_type {
259 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
260 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Instance`"))),
261 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::Instance`")))),
262 }
263 } else {
264 let content = resp.text().await?;
265 let entity: Option<GetInstanceByShortNameError> = serde_json::from_str(&content).ok();
266 Err(Error::ResponseError(ResponseContent {
267 status,
268 content,
269 entity,
270 }))
271 }
272}
273
274pub async fn get_recent_locations(
276 configuration: &configuration::Configuration,
277 n: Option<i32>,
278 offset: Option<i32>,
279) -> Result<Vec<String>, Error<GetRecentLocationsError>> {
280 let p_query_n = n;
282 let p_query_offset = offset;
283
284 let uri_str = format!("{}/instances/recent", configuration.base_path);
285 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
286
287 if let Some(ref param_value) = p_query_n {
288 req_builder = req_builder.query(&[("n", ¶m_value.to_string())]);
289 }
290 if let Some(ref param_value) = p_query_offset {
291 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
292 }
293 if let Some(ref user_agent) = configuration.user_agent {
294 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295 }
296
297 let req = req_builder.build()?;
298 let resp = configuration.client.execute(req).await?;
299
300 let status = resp.status();
301 let content_type = resp
302 .headers()
303 .get("content-type")
304 .and_then(|v| v.to_str().ok())
305 .unwrap_or("application/octet-stream");
306 let content_type = super::ContentType::from(content_type);
307
308 if !status.is_client_error() && !status.is_server_error() {
309 let content = resp.text().await?;
310 match content_type {
311 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
312 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<String>`"))),
313 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<String>`")))),
314 }
315 } else {
316 let content = resp.text().await?;
317 let entity: Option<GetRecentLocationsError> = serde_json::from_str(&content).ok();
318 Err(Error::ResponseError(ResponseContent {
319 status,
320 content,
321 entity,
322 }))
323 }
324}
325
326pub async fn get_short_name(
328 configuration: &configuration::Configuration,
329 world_id: &str,
330 instance_id: &str,
331) -> Result<models::InstanceShortNameResponse, Error<GetShortNameError>> {
332 let p_path_world_id = world_id;
334 let p_path_instance_id = instance_id;
335
336 let uri_str = format!(
337 "{}/instances/{worldId}:{instanceId}/shortName",
338 configuration.base_path,
339 worldId = crate::apis::urlencode(p_path_world_id),
340 instanceId = crate::apis::urlencode(p_path_instance_id)
341 );
342 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
343
344 if let Some(ref user_agent) = configuration.user_agent {
345 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
346 }
347
348 let req = req_builder.build()?;
349 let resp = configuration.client.execute(req).await?;
350
351 let status = resp.status();
352 let content_type = resp
353 .headers()
354 .get("content-type")
355 .and_then(|v| v.to_str().ok())
356 .unwrap_or("application/octet-stream");
357 let content_type = super::ContentType::from(content_type);
358
359 if !status.is_client_error() && !status.is_server_error() {
360 let content = resp.text().await?;
361 match content_type {
362 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
363 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstanceShortNameResponse`"))),
364 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::InstanceShortNameResponse`")))),
365 }
366 } else {
367 let content = resp.text().await?;
368 let entity: Option<GetShortNameError> = serde_json::from_str(&content).ok();
369 Err(Error::ResponseError(ResponseContent {
370 status,
371 content,
372 entity,
373 }))
374 }
375}