space_traders_api/apis/
systems_api.rs

1/*
2 * SpaceTraders API
3 *
4 * SpaceTraders is an open-universe game and learning platform that offers a set of HTTP endpoints to control a fleet of ships and explore a multiplayer universe.  The API is documented using [OpenAPI](https://github.com/SpaceTradersAPI/api-docs). You can send your first request right here in your browser to check the status of the game server.  ```json http {   \"method\": \"GET\",   \"url\": \"https://api.spacetraders.io/v2\", } ```  Unlike a traditional game, SpaceTraders does not have a first-party client or app to play the game. Instead, you can use the API to build your own client, write a script to automate your ships, or try an app built by the community.  We have a [Discord channel](https://discord.com/invite/jh6zurdWk5) where you can share your projects, ask questions, and get help from other players.   
5 *
6 * The version of the OpenAPI document: 2.3.0
7 * Contact: joel@spacetraders.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_construction`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetConstructionError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_jump_gate`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetJumpGateError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_market`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetMarketError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_shipyard`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetShipyardError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_system`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSystemError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_system_waypoints`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetSystemWaypointsError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_systems`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetSystemsError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`get_waypoint`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum GetWaypointError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`supply_construction`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum SupplyConstructionError {
78    UnknownValue(serde_json::Value),
79}
80
81
82/// Get construction details for a waypoint. Requires a waypoint with a property of `isUnderConstruction` to be true.
83pub async fn get_construction(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetConstruction200Response, Error<GetConstructionError>> {
84    // add a prefix to parameters to efficiently prevent name collisions
85    let p_system_symbol = system_symbol;
86    let p_waypoint_symbol = waypoint_symbol;
87
88    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}/construction", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
89    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
90
91    if let Some(ref user_agent) = configuration.user_agent {
92        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
93    }
94    if let Some(ref token) = configuration.bearer_access_token {
95        req_builder = req_builder.bearer_auth(token.to_owned());
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConstruction200Response`"))),
114            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::GetConstruction200Response`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<GetConstructionError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122
123/// Get jump gate details for a waypoint. Requires a waypoint of type `JUMP_GATE` to use.  Waypoints connected to this jump gate can be 
124pub async fn get_jump_gate(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetJumpGate200Response, Error<GetJumpGateError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_system_symbol = system_symbol;
127    let p_waypoint_symbol = waypoint_symbol;
128
129    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}/jump-gate", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
130    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
131
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135    if let Some(ref token) = configuration.bearer_access_token {
136        req_builder = req_builder.bearer_auth(token.to_owned());
137    };
138
139    let req = req_builder.build()?;
140    let resp = configuration.client.execute(req).await?;
141
142    let status = resp.status();
143    let content_type = resp
144        .headers()
145        .get("content-type")
146        .and_then(|v| v.to_str().ok())
147        .unwrap_or("application/octet-stream");
148    let content_type = super::ContentType::from(content_type);
149
150    if !status.is_client_error() && !status.is_server_error() {
151        let content = resp.text().await?;
152        match content_type {
153            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
154            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetJumpGate200Response`"))),
155            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::GetJumpGate200Response`")))),
156        }
157    } else {
158        let content = resp.text().await?;
159        let entity: Option<GetJumpGateError> = serde_json::from_str(&content).ok();
160        Err(Error::ResponseError(ResponseContent { status, content, entity }))
161    }
162}
163
164/// Retrieve imports, exports and exchange data from a marketplace. Requires a waypoint that has the `Marketplace` trait to use.  Send a ship to the waypoint to access trade good prices and recent transactions. Refer to the [Market Overview page](https://docs.spacetraders.io/game-concepts/markets) to gain better a understanding of the market in the game.
165pub async fn get_market(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetMarket200Response, Error<GetMarketError>> {
166    // add a prefix to parameters to efficiently prevent name collisions
167    let p_system_symbol = system_symbol;
168    let p_waypoint_symbol = waypoint_symbol;
169
170    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}/market", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
171    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
172
173    if let Some(ref user_agent) = configuration.user_agent {
174        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175    }
176    if let Some(ref token) = configuration.bearer_access_token {
177        req_builder = req_builder.bearer_auth(token.to_owned());
178    };
179
180    let req = req_builder.build()?;
181    let resp = configuration.client.execute(req).await?;
182
183    let status = resp.status();
184    let content_type = resp
185        .headers()
186        .get("content-type")
187        .and_then(|v| v.to_str().ok())
188        .unwrap_or("application/octet-stream");
189    let content_type = super::ContentType::from(content_type);
190
191    if !status.is_client_error() && !status.is_server_error() {
192        let content = resp.text().await?;
193        match content_type {
194            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
195            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMarket200Response`"))),
196            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::GetMarket200Response`")))),
197        }
198    } else {
199        let content = resp.text().await?;
200        let entity: Option<GetMarketError> = serde_json::from_str(&content).ok();
201        Err(Error::ResponseError(ResponseContent { status, content, entity }))
202    }
203}
204
205/// Get the shipyard for a waypoint. Requires a waypoint that has the `Shipyard` trait to use. Send a ship to the waypoint to access data on ships that are currently available for purchase and recent transactions.
206pub async fn get_shipyard(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetShipyard200Response, Error<GetShipyardError>> {
207    // add a prefix to parameters to efficiently prevent name collisions
208    let p_system_symbol = system_symbol;
209    let p_waypoint_symbol = waypoint_symbol;
210
211    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}/shipyard", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
212    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
213
214    if let Some(ref user_agent) = configuration.user_agent {
215        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
216    }
217    if let Some(ref token) = configuration.bearer_access_token {
218        req_builder = req_builder.bearer_auth(token.to_owned());
219    };
220
221    let req = req_builder.build()?;
222    let resp = configuration.client.execute(req).await?;
223
224    let status = resp.status();
225    let content_type = resp
226        .headers()
227        .get("content-type")
228        .and_then(|v| v.to_str().ok())
229        .unwrap_or("application/octet-stream");
230    let content_type = super::ContentType::from(content_type);
231
232    if !status.is_client_error() && !status.is_server_error() {
233        let content = resp.text().await?;
234        match content_type {
235            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
236            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetShipyard200Response`"))),
237            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::GetShipyard200Response`")))),
238        }
239    } else {
240        let content = resp.text().await?;
241        let entity: Option<GetShipyardError> = serde_json::from_str(&content).ok();
242        Err(Error::ResponseError(ResponseContent { status, content, entity }))
243    }
244}
245
246/// Get the details of a system.
247pub async fn get_system(configuration: &configuration::Configuration, system_symbol: &str) -> Result<models::GetSystem200Response, Error<GetSystemError>> {
248    // add a prefix to parameters to efficiently prevent name collisions
249    let p_system_symbol = system_symbol;
250
251    let uri_str = format!("{}/systems/{systemSymbol}", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol));
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref user_agent) = configuration.user_agent {
255        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256    }
257    if let Some(ref token) = configuration.bearer_access_token {
258        req_builder = req_builder.bearer_auth(token.to_owned());
259    };
260
261    let req = req_builder.build()?;
262    let resp = configuration.client.execute(req).await?;
263
264    let status = resp.status();
265    let content_type = resp
266        .headers()
267        .get("content-type")
268        .and_then(|v| v.to_str().ok())
269        .unwrap_or("application/octet-stream");
270    let content_type = super::ContentType::from(content_type);
271
272    if !status.is_client_error() && !status.is_server_error() {
273        let content = resp.text().await?;
274        match content_type {
275            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
276            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystem200Response`"))),
277            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::GetSystem200Response`")))),
278        }
279    } else {
280        let content = resp.text().await?;
281        let entity: Option<GetSystemError> = serde_json::from_str(&content).ok();
282        Err(Error::ResponseError(ResponseContent { status, content, entity }))
283    }
284}
285
286/// Return a paginated list of all of the waypoints for a given system.  If a waypoint is uncharted, it will return the `Uncharted` trait instead of its actual traits.
287pub async fn get_system_waypoints(configuration: &configuration::Configuration, system_symbol: &str, page: Option<i32>, limit: Option<i32>, r#type: Option<models::WaypointType>, traits: Option<&str>) -> Result<models::GetSystemWaypoints200Response, Error<GetSystemWaypointsError>> {
288    // add a prefix to parameters to efficiently prevent name collisions
289    let p_system_symbol = system_symbol;
290    let p_page = page;
291    let p_limit = limit;
292    let p_type = r#type;
293    let p_traits = traits;
294
295    let uri_str = format!("{}/systems/{systemSymbol}/waypoints", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol));
296    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
297
298    if let Some(ref param_value) = p_page {
299        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
300    }
301    if let Some(ref param_value) = p_limit {
302        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
303    }
304    if let Some(ref param_value) = p_type {
305        req_builder = req_builder.query(&[("type", &param_value.to_string())]);
306    }
307    if let Some(ref param_value) = p_traits {
308        req_builder = req_builder.query(&[("traits", &serde_json::to_string(param_value)?)]);
309    }
310    if let Some(ref user_agent) = configuration.user_agent {
311        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
312    }
313    if let Some(ref token) = configuration.bearer_access_token {
314        req_builder = req_builder.bearer_auth(token.to_owned());
315    };
316
317    let req = req_builder.build()?;
318    let resp = configuration.client.execute(req).await?;
319
320    let status = resp.status();
321    let content_type = resp
322        .headers()
323        .get("content-type")
324        .and_then(|v| v.to_str().ok())
325        .unwrap_or("application/octet-stream");
326    let content_type = super::ContentType::from(content_type);
327
328    if !status.is_client_error() && !status.is_server_error() {
329        let content = resp.text().await?;
330        match content_type {
331            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
332            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystemWaypoints200Response`"))),
333            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::GetSystemWaypoints200Response`")))),
334        }
335    } else {
336        let content = resp.text().await?;
337        let entity: Option<GetSystemWaypointsError> = serde_json::from_str(&content).ok();
338        Err(Error::ResponseError(ResponseContent { status, content, entity }))
339    }
340}
341
342/// Return a paginated list of all systems.
343pub async fn get_systems(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::GetSystems200Response, Error<GetSystemsError>> {
344    // add a prefix to parameters to efficiently prevent name collisions
345    let p_page = page;
346    let p_limit = limit;
347
348    let uri_str = format!("{}/systems", configuration.base_path);
349    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
350
351    if let Some(ref param_value) = p_page {
352        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
353    }
354    if let Some(ref param_value) = p_limit {
355        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
356    }
357    if let Some(ref user_agent) = configuration.user_agent {
358        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
359    }
360    if let Some(ref token) = configuration.bearer_access_token {
361        req_builder = req_builder.bearer_auth(token.to_owned());
362    };
363
364    let req = req_builder.build()?;
365    let resp = configuration.client.execute(req).await?;
366
367    let status = resp.status();
368    let content_type = resp
369        .headers()
370        .get("content-type")
371        .and_then(|v| v.to_str().ok())
372        .unwrap_or("application/octet-stream");
373    let content_type = super::ContentType::from(content_type);
374
375    if !status.is_client_error() && !status.is_server_error() {
376        let content = resp.text().await?;
377        match content_type {
378            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
379            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystems200Response`"))),
380            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::GetSystems200Response`")))),
381        }
382    } else {
383        let content = resp.text().await?;
384        let entity: Option<GetSystemsError> = serde_json::from_str(&content).ok();
385        Err(Error::ResponseError(ResponseContent { status, content, entity }))
386    }
387}
388
389/// View the details of a waypoint.  If the waypoint is uncharted, it will return the 'Uncharted' trait instead of its actual traits.
390pub async fn get_waypoint(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetWaypoint200Response, Error<GetWaypointError>> {
391    // add a prefix to parameters to efficiently prevent name collisions
392    let p_system_symbol = system_symbol;
393    let p_waypoint_symbol = waypoint_symbol;
394
395    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
396    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
397
398    if let Some(ref user_agent) = configuration.user_agent {
399        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
400    }
401    if let Some(ref token) = configuration.bearer_access_token {
402        req_builder = req_builder.bearer_auth(token.to_owned());
403    };
404
405    let req = req_builder.build()?;
406    let resp = configuration.client.execute(req).await?;
407
408    let status = resp.status();
409    let content_type = resp
410        .headers()
411        .get("content-type")
412        .and_then(|v| v.to_str().ok())
413        .unwrap_or("application/octet-stream");
414    let content_type = super::ContentType::from(content_type);
415
416    if !status.is_client_error() && !status.is_server_error() {
417        let content = resp.text().await?;
418        match content_type {
419            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
420            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWaypoint200Response`"))),
421            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::GetWaypoint200Response`")))),
422        }
423    } else {
424        let content = resp.text().await?;
425        let entity: Option<GetWaypointError> = serde_json::from_str(&content).ok();
426        Err(Error::ResponseError(ResponseContent { status, content, entity }))
427    }
428}
429
430/// Supply a construction site with the specified good. Requires a waypoint with a property of `isUnderConstruction` to be true.  The good must be in your ship's cargo. The good will be removed from your ship's cargo and added to the construction site's materials.
431pub async fn supply_construction(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str, supply_construction_request: Option<models::SupplyConstructionRequest>) -> Result<models::SupplyConstruction201Response, Error<SupplyConstructionError>> {
432    // add a prefix to parameters to efficiently prevent name collisions
433    let p_system_symbol = system_symbol;
434    let p_waypoint_symbol = waypoint_symbol;
435    let p_supply_construction_request = supply_construction_request;
436
437    let uri_str = format!("{}/systems/{systemSymbol}/waypoints/{waypointSymbol}/construction/supply", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol), waypointSymbol=crate::apis::urlencode(p_waypoint_symbol));
438    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
439
440    if let Some(ref user_agent) = configuration.user_agent {
441        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
442    }
443    if let Some(ref token) = configuration.bearer_access_token {
444        req_builder = req_builder.bearer_auth(token.to_owned());
445    };
446    req_builder = req_builder.json(&p_supply_construction_request);
447
448    let req = req_builder.build()?;
449    let resp = configuration.client.execute(req).await?;
450
451    let status = resp.status();
452    let content_type = resp
453        .headers()
454        .get("content-type")
455        .and_then(|v| v.to_str().ok())
456        .unwrap_or("application/octet-stream");
457    let content_type = super::ContentType::from(content_type);
458
459    if !status.is_client_error() && !status.is_server_error() {
460        let content = resp.text().await?;
461        match content_type {
462            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
463            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SupplyConstruction201Response`"))),
464            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::SupplyConstruction201Response`")))),
465        }
466    } else {
467        let content = resp.text().await?;
468        let entity: Option<SupplyConstructionError> = serde_json::from_str(&content).ok();
469        Err(Error::ResponseError(ResponseContent { status, content, entity }))
470    }
471}
472