1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{de, Deserialize, Deserializer, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct GetGeHistoryParams {
9 pub code: String,
11 pub account: Option<String>,
13 pub page: Option<u32>,
15 pub size: Option<u32>,
17}
18
19impl GetGeHistoryParams {
20 pub fn new(
21 code: String,
22 account: Option<String>,
23 page: Option<u32>,
24 size: Option<u32>,
25 ) -> Self {
26 Self {
27 code,
28 account,
29 page,
30 size,
31 }
32 }
33}
34
35#[derive(Clone, Debug)]
37pub struct GetGeOrderParams {
38 pub id: String,
40}
41
42impl GetGeOrderParams {
43 pub fn new(id: String) -> Self {
44 Self { id }
45 }
46}
47
48#[derive(Clone, Debug)]
50pub struct GetGeOrdersParams {
51 pub code: Option<String>,
53 pub account: Option<String>,
55 pub r#type: Option<models::GeOrderType>,
57 pub page: Option<u32>,
59 pub size: Option<u32>,
61}
62
63impl GetGeOrdersParams {
64 pub fn new(
65 code: Option<String>,
66 account: Option<String>,
67 r#type: Option<models::GeOrderType>,
68 page: Option<u32>,
69 size: Option<u32>,
70 ) -> Self {
71 Self {
72 code,
73 account,
74 r#type,
75 page,
76 size,
77 }
78 }
79}
80
81#[derive(Debug, Clone, Serialize)]
83#[serde(untagged)]
84pub enum GetGeHistoryError {
85 Status404(models::ErrorResponseSchema),
87}
88
89impl<'de> Deserialize<'de> for GetGeHistoryError {
90 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
91 where
92 D: Deserializer<'de>,
93 {
94 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
95 match raw.error.code {
96 404 => Ok(Self::Status404(raw)),
97 _ => Err(de::Error::custom(format!(
98 "Unexpected error code: {}",
99 raw.error.code
100 ))),
101 }
102 }
103}
104
105#[derive(Debug, Clone, Serialize)]
107#[serde(untagged)]
108pub enum GetGeOrderError {
109 Status404(models::ErrorResponseSchema),
111}
112
113impl<'de> Deserialize<'de> for GetGeOrderError {
114 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
115 where
116 D: Deserializer<'de>,
117 {
118 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
119 match raw.error.code {
120 404 => Ok(Self::Status404(raw)),
121 _ => Err(de::Error::custom(format!(
122 "Unexpected error code: {}",
123 raw.error.code
124 ))),
125 }
126 }
127}
128
129#[derive(Debug, Clone, Serialize)]
131#[serde(untagged)]
132pub enum GetGeOrdersError {}
133
134impl<'de> Deserialize<'de> for GetGeOrdersError {
135 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
136 where
137 D: Deserializer<'de>,
138 {
139 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
140 Err(de::Error::custom(format!(
141 "Unexpected error code: {}",
142 raw.error.code
143 )))
144 }
145}
146
147pub async fn get_ge_history(
149 configuration: &configuration::Configuration,
150 params: GetGeHistoryParams,
151) -> Result<models::DataPageGeOrderHistorySchema, Error<GetGeHistoryError>> {
152 let local_var_configuration = configuration;
153
154 let code = params.code;
156 let account = params.account;
158 let page = params.page;
160 let size = params.size;
162
163 let local_var_client = &local_var_configuration.client;
164
165 let local_var_uri_str = format!(
166 "{}/grandexchange/history/{code}",
167 local_var_configuration.base_path,
168 code = crate::apis::urlencode(code)
169 );
170 let mut local_var_req_builder =
171 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
172
173 if let Some(ref local_var_str) = account {
174 local_var_req_builder =
175 local_var_req_builder.query(&[("account", &local_var_str.to_string())]);
176 }
177 if let Some(ref local_var_str) = page {
178 local_var_req_builder =
179 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
180 }
181 if let Some(ref local_var_str) = size {
182 local_var_req_builder =
183 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
184 }
185 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186 local_var_req_builder =
187 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188 }
189
190 let local_var_req = local_var_req_builder.build()?;
191 let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193 let local_var_status = local_var_resp.status();
194 let local_var_content = local_var_resp.text().await?;
195
196 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197 serde_json::from_str(&local_var_content).map_err(Error::from)
198 } else {
199 let local_var_entity: Option<GetGeHistoryError> =
200 serde_json::from_str(&local_var_content).ok();
201 let local_var_error = ResponseContent {
202 status: local_var_status,
203 content: local_var_content,
204 entity: local_var_entity,
205 };
206 Err(Error::ResponseError(local_var_error))
207 }
208}
209
210pub async fn get_ge_order(
212 configuration: &configuration::Configuration,
213 params: GetGeOrderParams,
214) -> Result<models::GeOrderResponseSchema, Error<GetGeOrderError>> {
215 let local_var_configuration = configuration;
216
217 let id = params.id;
219
220 let local_var_client = &local_var_configuration.client;
221
222 let local_var_uri_str = format!(
223 "{}/grandexchange/orders/{id}",
224 local_var_configuration.base_path,
225 id = crate::apis::urlencode(id)
226 );
227 let mut local_var_req_builder =
228 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
229
230 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
231 local_var_req_builder =
232 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
233 }
234
235 let local_var_req = local_var_req_builder.build()?;
236 let local_var_resp = local_var_client.execute(local_var_req).await?;
237
238 let local_var_status = local_var_resp.status();
239 let local_var_content = local_var_resp.text().await?;
240
241 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242 serde_json::from_str(&local_var_content).map_err(Error::from)
243 } else {
244 let local_var_entity: Option<GetGeOrderError> =
245 serde_json::from_str(&local_var_content).ok();
246 let local_var_error = ResponseContent {
247 status: local_var_status,
248 content: local_var_content,
249 entity: local_var_entity,
250 };
251 Err(Error::ResponseError(local_var_error))
252 }
253}
254
255pub async fn get_ge_orders(
257 configuration: &configuration::Configuration,
258 params: GetGeOrdersParams,
259) -> Result<models::DataPageGeOrderSchema, Error<GetGeOrdersError>> {
260 let local_var_configuration = configuration;
261
262 let code = params.code;
264 let account = params.account;
266 let r#type = params.r#type;
268 let page = params.page;
270 let size = params.size;
272
273 let local_var_client = &local_var_configuration.client;
274
275 let local_var_uri_str = format!("{}/grandexchange/orders", local_var_configuration.base_path);
276 let mut local_var_req_builder =
277 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
278
279 if let Some(ref local_var_str) = code {
280 local_var_req_builder =
281 local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
282 }
283 if let Some(ref local_var_str) = account {
284 local_var_req_builder =
285 local_var_req_builder.query(&[("account", &local_var_str.to_string())]);
286 }
287 if let Some(ref local_var_str) = r#type {
288 local_var_req_builder =
289 local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
290 }
291 if let Some(ref local_var_str) = page {
292 local_var_req_builder =
293 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
294 }
295 if let Some(ref local_var_str) = size {
296 local_var_req_builder =
297 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
298 }
299 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
300 local_var_req_builder =
301 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302 }
303
304 let local_var_req = local_var_req_builder.build()?;
305 let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307 let local_var_status = local_var_resp.status();
308 let local_var_content = local_var_resp.text().await?;
309
310 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
311 serde_json::from_str(&local_var_content).map_err(Error::from)
312 } else {
313 let local_var_entity: Option<GetGeOrdersError> =
314 serde_json::from_str(&local_var_content).ok();
315 let local_var_error = ResponseContent {
316 status: local_var_status,
317 content: local_var_content,
318 entity: local_var_entity,
319 };
320 Err(Error::ResponseError(local_var_error))
321 }
322}