space_traders_api/apis/
agents_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_agent`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAgentError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_agents`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAgentsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_my_agent`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetMyAgentError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Fetch agent details.
41pub async fn get_agent(configuration: &configuration::Configuration, agent_symbol: &str) -> Result<models::GetMyAgent200Response, Error<GetAgentError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_agent_symbol = agent_symbol;
44
45    let uri_str = format!("{}/agents/{agentSymbol}", configuration.base_path, agentSymbol=crate::apis::urlencode(p_agent_symbol));
46    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref token) = configuration.bearer_access_token {
52        req_builder = req_builder.bearer_auth(token.to_owned());
53    };
54
55    let req = req_builder.build()?;
56    let resp = configuration.client.execute(req).await?;
57
58    let status = resp.status();
59    let content_type = resp
60        .headers()
61        .get("content-type")
62        .and_then(|v| v.to_str().ok())
63        .unwrap_or("application/octet-stream");
64    let content_type = super::ContentType::from(content_type);
65
66    if !status.is_client_error() && !status.is_server_error() {
67        let content = resp.text().await?;
68        match content_type {
69            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMyAgent200Response`"))),
71            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::GetMyAgent200Response`")))),
72        }
73    } else {
74        let content = resp.text().await?;
75        let entity: Option<GetAgentError> = serde_json::from_str(&content).ok();
76        Err(Error::ResponseError(ResponseContent { status, content, entity }))
77    }
78}
79
80/// Fetch agents details.
81pub async fn get_agents(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::GetAgents200Response, Error<GetAgentsError>> {
82    // add a prefix to parameters to efficiently prevent name collisions
83    let p_page = page;
84    let p_limit = limit;
85
86    let uri_str = format!("{}/agents", configuration.base_path);
87    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
88
89    if let Some(ref param_value) = p_page {
90        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
91    }
92    if let Some(ref param_value) = p_limit {
93        req_builder = req_builder.query(&[("limit", &param_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    if let Some(ref token) = configuration.bearer_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101
102    let req = req_builder.build()?;
103    let resp = configuration.client.execute(req).await?;
104
105    let status = resp.status();
106    let content_type = resp
107        .headers()
108        .get("content-type")
109        .and_then(|v| v.to_str().ok())
110        .unwrap_or("application/octet-stream");
111    let content_type = super::ContentType::from(content_type);
112
113    if !status.is_client_error() && !status.is_server_error() {
114        let content = resp.text().await?;
115        match content_type {
116            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAgents200Response`"))),
118            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::GetAgents200Response`")))),
119        }
120    } else {
121        let content = resp.text().await?;
122        let entity: Option<GetAgentsError> = serde_json::from_str(&content).ok();
123        Err(Error::ResponseError(ResponseContent { status, content, entity }))
124    }
125}
126
127/// Fetch your agent's details.
128pub async fn get_my_agent(configuration: &configuration::Configuration, ) -> Result<models::GetMyAgent200Response, Error<GetMyAgentError>> {
129
130    let uri_str = format!("{}/my/agent", configuration.base_path);
131    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
132
133    if let Some(ref user_agent) = configuration.user_agent {
134        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135    }
136    if let Some(ref token) = configuration.bearer_access_token {
137        req_builder = req_builder.bearer_auth(token.to_owned());
138    };
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144    let content_type = resp
145        .headers()
146        .get("content-type")
147        .and_then(|v| v.to_str().ok())
148        .unwrap_or("application/octet-stream");
149    let content_type = super::ContentType::from(content_type);
150
151    if !status.is_client_error() && !status.is_server_error() {
152        let content = resp.text().await?;
153        match content_type {
154            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMyAgent200Response`"))),
156            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::GetMyAgent200Response`")))),
157        }
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<GetMyAgentError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent { status, content, entity }))
162    }
163}
164