Skip to main content

artifacts/apis/
grand_exchange_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{de, Deserialize, Deserializer, Serialize};
5
6/// struct for passing parameters to the method [`get_ge_history`]
7#[derive(Clone, Debug)]
8pub struct GetGeHistoryParams {
9    /// The code of the item.
10    pub code: String,
11    /// Account involved in the transaction (matches either seller or buyer).
12    pub account: Option<String>,
13    /// Page number
14    pub page: Option<u32>,
15    /// Page size
16    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/// struct for passing parameters to the method [`get_ge_order`]
36#[derive(Clone, Debug)]
37pub struct GetGeOrderParams {
38    /// The id of the order.
39    pub id: String,
40}
41
42impl GetGeOrderParams {
43    pub fn new(id: String) -> Self {
44        Self { id }
45    }
46}
47
48/// struct for passing parameters to the method [`get_ge_orders`]
49#[derive(Clone, Debug)]
50pub struct GetGeOrdersParams {
51    /// The code of the item.
52    pub code: Option<String>,
53    /// The account that sells or buys items.
54    pub account: Option<String>,
55    /// Filter by order type (sell or buy).
56    pub r#type: Option<models::GeOrderType>,
57    /// Filter by item type.
58    pub item_type: Option<models::ItemType>,
59    /// Page number
60    pub page: Option<u32>,
61    /// Page size
62    pub size: Option<u32>,
63}
64
65impl GetGeOrdersParams {
66    pub fn new(
67        code: Option<String>,
68        account: Option<String>,
69        r#type: Option<models::GeOrderType>,
70        item_type: Option<models::ItemType>,
71        page: Option<u32>,
72        size: Option<u32>,
73    ) -> Self {
74        Self {
75            code,
76            account,
77            r#type,
78            item_type,
79            page,
80            size,
81        }
82    }
83}
84
85/// struct for typed errors of method [`get_ge_history`]
86#[derive(Debug, Clone, Serialize)]
87#[serde(untagged)]
88pub enum GetGeHistoryError {
89    /// item history not found.
90    Status404(models::ErrorResponseSchema),
91}
92
93impl<'de> Deserialize<'de> for GetGeHistoryError {
94    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
95    where
96        D: Deserializer<'de>,
97    {
98        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
99        match raw.error.code {
100            404 => Ok(Self::Status404(raw)),
101            _ => Err(de::Error::custom(format!(
102                "Unexpected error code: {}",
103                raw.error.code
104            ))),
105        }
106    }
107}
108
109/// struct for typed errors of method [`get_ge_order`]
110#[derive(Debug, Clone, Serialize)]
111#[serde(untagged)]
112pub enum GetGeOrderError {
113    /// GE order not found.
114    Status404(models::ErrorResponseSchema),
115}
116
117impl<'de> Deserialize<'de> for GetGeOrderError {
118    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
119    where
120        D: Deserializer<'de>,
121    {
122        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
123        match raw.error.code {
124            404 => Ok(Self::Status404(raw)),
125            _ => Err(de::Error::custom(format!(
126                "Unexpected error code: {}",
127                raw.error.code
128            ))),
129        }
130    }
131}
132
133/// struct for typed errors of method [`get_ge_orders`]
134#[derive(Debug, Clone, Serialize)]
135#[serde(untagged)]
136pub enum GetGeOrdersError {}
137
138impl<'de> Deserialize<'de> for GetGeOrdersError {
139    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
140    where
141        D: Deserializer<'de>,
142    {
143        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
144        Err(de::Error::custom(format!(
145            "Unexpected error code: {}",
146            raw.error.code
147        )))
148    }
149}
150
151/// Fetch the transaction history of the item for the last 7 days (buy and sell orders).
152pub async fn get_ge_history(
153    configuration: &configuration::Configuration,
154    params: GetGeHistoryParams,
155) -> Result<models::DataPageGeOrderHistorySchema, Error<GetGeHistoryError>> {
156    let local_var_configuration = configuration;
157
158    // unbox the parameters
159    let code = params.code;
160    // unbox the parameters
161    let account = params.account;
162    // unbox the parameters
163    let page = params.page;
164    // unbox the parameters
165    let size = params.size;
166
167    let local_var_client = &local_var_configuration.client;
168
169    let local_var_uri_str = format!(
170        "{}/grandexchange/history/{code}",
171        local_var_configuration.base_path,
172        code = crate::apis::urlencode(code)
173    );
174    let mut local_var_req_builder =
175        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
176
177    if let Some(ref local_var_str) = account {
178        local_var_req_builder =
179            local_var_req_builder.query(&[("account", &local_var_str.to_string())]);
180    }
181    if let Some(ref local_var_str) = page {
182        local_var_req_builder =
183            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
184    }
185    if let Some(ref local_var_str) = size {
186        local_var_req_builder =
187            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
188    }
189    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
190        local_var_req_builder =
191            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
192    }
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<GetGeHistoryError> =
204            serde_json::from_str(&local_var_content).ok();
205        let local_var_error = ResponseContent {
206            status: local_var_status,
207            content: local_var_content,
208            entity: local_var_entity,
209        };
210        Err(Error::ResponseError(local_var_error))
211    }
212}
213
214/// Retrieve a specific order by ID.
215pub async fn get_ge_order(
216    configuration: &configuration::Configuration,
217    params: GetGeOrderParams,
218) -> Result<models::GeOrderResponseSchema, Error<GetGeOrderError>> {
219    let local_var_configuration = configuration;
220
221    // unbox the parameters
222    let id = params.id;
223
224    let local_var_client = &local_var_configuration.client;
225
226    let local_var_uri_str = format!(
227        "{}/grandexchange/orders/{id}",
228        local_var_configuration.base_path,
229        id = crate::apis::urlencode(id)
230    );
231    let mut local_var_req_builder =
232        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
233
234    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
235        local_var_req_builder =
236            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237    }
238
239    let local_var_req = local_var_req_builder.build()?;
240    let local_var_resp = local_var_client.execute(local_var_req).await?;
241
242    let local_var_status = local_var_resp.status();
243    let local_var_content = local_var_resp.text().await?;
244
245    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246        serde_json::from_str(&local_var_content).map_err(Error::from)
247    } else {
248        let local_var_entity: Option<GetGeOrderError> =
249            serde_json::from_str(&local_var_content).ok();
250        let local_var_error = ResponseContent {
251            status: local_var_status,
252            content: local_var_content,
253            entity: local_var_entity,
254        };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258
259/// Fetch all orders (sell and buy orders).  Use the `type` parameter to filter by order type; when using `account`, `type` is required to keep account searches explicit.
260pub async fn get_ge_orders(
261    configuration: &configuration::Configuration,
262    params: GetGeOrdersParams,
263) -> Result<models::DataPageGeOrderSchema, Error<GetGeOrdersError>> {
264    let local_var_configuration = configuration;
265
266    // unbox the parameters
267    let code = params.code;
268    // unbox the parameters
269    let account = params.account;
270    // unbox the parameters
271    let r#type = params.r#type;
272    // unbox the parameters
273    let item_type = params.item_type;
274    // unbox the parameters
275    let page = params.page;
276    // unbox the parameters
277    let size = params.size;
278
279    let local_var_client = &local_var_configuration.client;
280
281    let local_var_uri_str = format!("{}/grandexchange/orders", local_var_configuration.base_path);
282    let mut local_var_req_builder =
283        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
284
285    if let Some(ref local_var_str) = code {
286        local_var_req_builder =
287            local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
288    }
289    if let Some(ref local_var_str) = account {
290        local_var_req_builder =
291            local_var_req_builder.query(&[("account", &local_var_str.to_string())]);
292    }
293    if let Some(ref local_var_str) = r#type {
294        local_var_req_builder =
295            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
296    }
297    if let Some(ref local_var_str) = item_type {
298        local_var_req_builder =
299            local_var_req_builder.query(&[("item_type", &local_var_str.to_string())]);
300    }
301    if let Some(ref local_var_str) = page {
302        local_var_req_builder =
303            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
304    }
305    if let Some(ref local_var_str) = size {
306        local_var_req_builder =
307            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
308    }
309    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
310        local_var_req_builder =
311            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
312    }
313
314    let local_var_req = local_var_req_builder.build()?;
315    let local_var_resp = local_var_client.execute(local_var_req).await?;
316
317    let local_var_status = local_var_resp.status();
318    let local_var_content = local_var_resp.text().await?;
319
320    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321        serde_json::from_str(&local_var_content).map_err(Error::from)
322    } else {
323        let local_var_entity: Option<GetGeOrdersError> =
324            serde_json::from_str(&local_var_content).ok();
325        let local_var_error = ResponseContent {
326            status: local_var_status,
327            content: local_var_content,
328            entity: local_var_entity,
329        };
330        Err(Error::ResponseError(local_var_error))
331    }
332}