space_traders_api/apis/
contracts_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 AcceptContractError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeliverContractError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum FulfillContractError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetContractError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetContractsError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn accept_contract(configuration: &configuration::Configuration, contract_id: &str) -> Result<models::AcceptContract200Response, Error<AcceptContractError>> {
56 let p_contract_id = contract_id;
58
59 let uri_str = format!("{}/my/contracts/{contractId}/accept", configuration.base_path, contractId=crate::apis::urlencode(p_contract_id));
60 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
61
62 if let Some(ref user_agent) = configuration.user_agent {
63 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64 }
65 if let Some(ref token) = configuration.bearer_access_token {
66 req_builder = req_builder.bearer_auth(token.to_owned());
67 };
68
69 let req = req_builder.build()?;
70 let resp = configuration.client.execute(req).await?;
71
72 let status = resp.status();
73 let content_type = resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let content_type = super::ContentType::from(content_type);
79
80 if !status.is_client_error() && !status.is_server_error() {
81 let content = resp.text().await?;
82 match content_type {
83 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AcceptContract200Response`"))),
85 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::AcceptContract200Response`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<AcceptContractError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent { status, content, entity }))
91 }
92}
93
94pub async fn deliver_contract(configuration: &configuration::Configuration, contract_id: &str, deliver_contract_request: Option<models::DeliverContractRequest>) -> Result<models::DeliverContract200Response, Error<DeliverContractError>> {
96 let p_contract_id = contract_id;
98 let p_deliver_contract_request = deliver_contract_request;
99
100 let uri_str = format!("{}/my/contracts/{contractId}/deliver", configuration.base_path, contractId=crate::apis::urlencode(p_contract_id));
101 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
102
103 if let Some(ref user_agent) = configuration.user_agent {
104 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
105 }
106 if let Some(ref token) = configuration.bearer_access_token {
107 req_builder = req_builder.bearer_auth(token.to_owned());
108 };
109 req_builder = req_builder.json(&p_deliver_contract_request);
110
111 let req = req_builder.build()?;
112 let resp = configuration.client.execute(req).await?;
113
114 let status = resp.status();
115 let content_type = resp
116 .headers()
117 .get("content-type")
118 .and_then(|v| v.to_str().ok())
119 .unwrap_or("application/octet-stream");
120 let content_type = super::ContentType::from(content_type);
121
122 if !status.is_client_error() && !status.is_server_error() {
123 let content = resp.text().await?;
124 match content_type {
125 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeliverContract200Response`"))),
127 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::DeliverContract200Response`")))),
128 }
129 } else {
130 let content = resp.text().await?;
131 let entity: Option<DeliverContractError> = serde_json::from_str(&content).ok();
132 Err(Error::ResponseError(ResponseContent { status, content, entity }))
133 }
134}
135
136pub async fn fulfill_contract(configuration: &configuration::Configuration, contract_id: &str) -> Result<models::FulfillContract200Response, Error<FulfillContractError>> {
138 let p_contract_id = contract_id;
140
141 let uri_str = format!("{}/my/contracts/{contractId}/fulfill", configuration.base_path, contractId=crate::apis::urlencode(p_contract_id));
142 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
143
144 if let Some(ref user_agent) = configuration.user_agent {
145 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
146 }
147 if let Some(ref token) = configuration.bearer_access_token {
148 req_builder = req_builder.bearer_auth(token.to_owned());
149 };
150
151 let req = req_builder.build()?;
152 let resp = configuration.client.execute(req).await?;
153
154 let status = resp.status();
155 let content_type = resp
156 .headers()
157 .get("content-type")
158 .and_then(|v| v.to_str().ok())
159 .unwrap_or("application/octet-stream");
160 let content_type = super::ContentType::from(content_type);
161
162 if !status.is_client_error() && !status.is_server_error() {
163 let content = resp.text().await?;
164 match content_type {
165 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
166 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FulfillContract200Response`"))),
167 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::FulfillContract200Response`")))),
168 }
169 } else {
170 let content = resp.text().await?;
171 let entity: Option<FulfillContractError> = serde_json::from_str(&content).ok();
172 Err(Error::ResponseError(ResponseContent { status, content, entity }))
173 }
174}
175
176pub async fn get_contract(configuration: &configuration::Configuration, contract_id: &str) -> Result<models::GetContract200Response, Error<GetContractError>> {
178 let p_contract_id = contract_id;
180
181 let uri_str = format!("{}/my/contracts/{contractId}", configuration.base_path, contractId=crate::apis::urlencode(p_contract_id));
182 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184 if let Some(ref user_agent) = configuration.user_agent {
185 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186 }
187 if let Some(ref token) = configuration.bearer_access_token {
188 req_builder = req_builder.bearer_auth(token.to_owned());
189 };
190
191 let req = req_builder.build()?;
192 let resp = configuration.client.execute(req).await?;
193
194 let status = resp.status();
195 let content_type = resp
196 .headers()
197 .get("content-type")
198 .and_then(|v| v.to_str().ok())
199 .unwrap_or("application/octet-stream");
200 let content_type = super::ContentType::from(content_type);
201
202 if !status.is_client_error() && !status.is_server_error() {
203 let content = resp.text().await?;
204 match content_type {
205 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
206 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetContract200Response`"))),
207 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::GetContract200Response`")))),
208 }
209 } else {
210 let content = resp.text().await?;
211 let entity: Option<GetContractError> = serde_json::from_str(&content).ok();
212 Err(Error::ResponseError(ResponseContent { status, content, entity }))
213 }
214}
215
216pub async fn get_contracts(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::GetContracts200Response, Error<GetContractsError>> {
218 let p_page = page;
220 let p_limit = limit;
221
222 let uri_str = format!("{}/my/contracts", configuration.base_path);
223 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
224
225 if let Some(ref param_value) = p_page {
226 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
227 }
228 if let Some(ref param_value) = p_limit {
229 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
230 }
231 if let Some(ref user_agent) = configuration.user_agent {
232 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233 }
234 if let Some(ref token) = configuration.bearer_access_token {
235 req_builder = req_builder.bearer_auth(token.to_owned());
236 };
237
238 let req = req_builder.build()?;
239 let resp = configuration.client.execute(req).await?;
240
241 let status = resp.status();
242 let content_type = resp
243 .headers()
244 .get("content-type")
245 .and_then(|v| v.to_str().ok())
246 .unwrap_or("application/octet-stream");
247 let content_type = super::ContentType::from(content_type);
248
249 if !status.is_client_error() && !status.is_server_error() {
250 let content = resp.text().await?;
251 match content_type {
252 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetContracts200Response`"))),
254 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::GetContracts200Response`")))),
255 }
256 } else {
257 let content = resp.text().await?;
258 let entity: Option<GetContractsError> = serde_json::from_str(&content).ok();
259 Err(Error::ResponseError(ResponseContent { status, content, entity }))
260 }
261}
262