/*
* SpaceTraders API
*
* 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.
*
* The version of the OpenAPI document: 2.3.0
* Contact: joel@spacetraders.io
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`get_construction`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetConstructionError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_jump_gate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetJumpGateError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_market`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMarketError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_shipyard`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetShipyardError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_system`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSystemError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_system_waypoints`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSystemWaypointsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_systems`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSystemsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_waypoint`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetWaypointError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`supply_construction`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SupplyConstructionError {
UnknownValue(serde_json::Value),
}
/// Get construction details for a waypoint. Requires a waypoint with a property of `isUnderConstruction` to be true.
pub async fn get_construction(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetConstruction200Response, Error<GetConstructionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConstruction200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetConstructionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get jump gate details for a waypoint. Requires a waypoint of type `JUMP_GATE` to use. Waypoints connected to this jump gate can be
pub async fn get_jump_gate(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetJumpGate200Response, Error<GetJumpGateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetJumpGate200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetJumpGateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn get_market(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetMarket200Response, Error<GetMarketError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMarket200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMarketError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn get_shipyard(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetShipyard200Response, Error<GetShipyardError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetShipyard200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetShipyardError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get the details of a system.
pub async fn get_system(configuration: &configuration::Configuration, system_symbol: &str) -> Result<models::GetSystem200Response, Error<GetSystemError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let uri_str = format!("{}/systems/{systemSymbol}", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystem200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSystemError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_page = page;
let p_limit = limit;
let p_type = r#type;
let p_traits = traits;
let uri_str = format!("{}/systems/{systemSymbol}/waypoints", configuration.base_path, systemSymbol=crate::apis::urlencode(p_system_symbol));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_type {
req_builder = req_builder.query(&[("type", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_traits {
req_builder = req_builder.query(&[("traits", &serde_json::to_string(param_value)?)]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystemWaypoints200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSystemWaypointsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Return a paginated list of all systems.
pub async fn get_systems(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::GetSystems200Response, Error<GetSystemsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_page = page;
let p_limit = limit;
let uri_str = format!("{}/systems", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetSystems200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSystemsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// View the details of a waypoint. If the waypoint is uncharted, it will return the 'Uncharted' trait instead of its actual traits.
pub async fn get_waypoint(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str) -> Result<models::GetWaypoint200Response, Error<GetWaypointError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWaypoint200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetWaypointError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn supply_construction(configuration: &configuration::Configuration, system_symbol: &str, waypoint_symbol: &str, supply_construction_request: Option<models::SupplyConstructionRequest>) -> Result<models::SupplyConstruction201Response, Error<SupplyConstructionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_system_symbol = system_symbol;
let p_waypoint_symbol = waypoint_symbol;
let p_supply_construction_request = supply_construction_request;
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));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_supply_construction_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SupplyConstruction201Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SupplyConstructionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}