space_traders_api/apis/
factions_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetFactionError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetFactionsError {
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_faction(configuration: &configuration::Configuration, faction_symbol: &str) -> Result<models::GetFaction200Response, Error<GetFactionError>> {
35 let p_faction_symbol = faction_symbol;
37
38 let uri_str = format!("{}/factions/{factionSymbol}", configuration.base_path, factionSymbol=crate::apis::urlencode(p_faction_symbol));
39 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
40
41 if let Some(ref user_agent) = configuration.user_agent {
42 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43 }
44 if let Some(ref token) = configuration.bearer_access_token {
45 req_builder = req_builder.bearer_auth(token.to_owned());
46 };
47 if let Some(ref token) = configuration.bearer_access_token {
48 req_builder = req_builder.bearer_auth(token.to_owned());
49 };
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFaction200Response`"))),
67 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::GetFaction200Response`")))),
68 }
69 } else {
70 let content = resp.text().await?;
71 let entity: Option<GetFactionError> = serde_json::from_str(&content).ok();
72 Err(Error::ResponseError(ResponseContent { status, content, entity }))
73 }
74}
75
76pub async fn get_factions(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::GetFactions200Response, Error<GetFactionsError>> {
78 let p_page = page;
80 let p_limit = limit;
81
82 let uri_str = format!("{}/factions", configuration.base_path);
83 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
84
85 if let Some(ref param_value) = p_page {
86 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
87 }
88 if let Some(ref param_value) = p_limit {
89 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
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::GetFactions200Response`"))),
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::GetFactions200Response`")))),
115 }
116 } else {
117 let content = resp.text().await?;
118 let entity: Option<GetFactionsError> = serde_json::from_str(&content).ok();
119 Err(Error::ResponseError(ResponseContent { status, content, entity }))
120 }
121}
122