Skip to main content

artifacts/apis/
gems_shop_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 [`buy_custom_design`]
7#[derive(Clone, Debug)]
8pub struct BuyCustomDesignParams {
9    pub buy_custom_design_request_schema: models::BuyCustomDesignRequestSchema,
10}
11
12impl BuyCustomDesignParams {
13    pub fn new(buy_custom_design_request_schema: models::BuyCustomDesignRequestSchema) -> Self {
14        Self {
15            buy_custom_design_request_schema,
16        }
17    }
18}
19
20/// struct for passing parameters to the method [`buy_skin`]
21#[derive(Clone, Debug)]
22pub struct BuySkinParams {
23    pub buy_skin_request_schema: models::BuySkinRequestSchema,
24}
25
26impl BuySkinParams {
27    pub fn new(buy_skin_request_schema: models::BuySkinRequestSchema) -> Self {
28        Self {
29            buy_skin_request_schema,
30        }
31    }
32}
33
34/// struct for passing parameters to the method [`buy_spawn_event`]
35#[derive(Clone, Debug)]
36pub struct BuySpawnEventParams {
37    pub spawn_event_request_schema: models::SpawnEventRequestSchema,
38}
39
40impl BuySpawnEventParams {
41    pub fn new(spawn_event_request_schema: models::SpawnEventRequestSchema) -> Self {
42        Self {
43            spawn_event_request_schema,
44        }
45    }
46}
47
48/// struct for typed errors of method [`buy_custom_design`]
49#[derive(Debug, Clone, Serialize)]
50#[serde(untagged)]
51pub enum BuyCustomDesignError {
52    /// Insufficient gems.
53    Status563(models::ErrorResponseSchema),
54    /// Custom design not found.
55    Status404(models::ErrorResponseSchema),
56    /// Request could not be processed due to an invalid payload.
57    Status422(models::ErrorResponseSchema),
58}
59
60impl<'de> Deserialize<'de> for BuyCustomDesignError {
61    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62    where
63        D: Deserializer<'de>,
64    {
65        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
66        match raw.error.code {
67            563 => Ok(Self::Status563(raw)),
68            404 => Ok(Self::Status404(raw)),
69            422 => Ok(Self::Status422(raw)),
70            _ => Err(de::Error::custom(format!(
71                "Unexpected error code: {}",
72                raw.error.code
73            ))),
74        }
75    }
76}
77
78/// struct for typed errors of method [`buy_skin`]
79#[derive(Debug, Clone, Serialize)]
80#[serde(untagged)]
81pub enum BuySkinError {
82    /// Skin not found.
83    Status404(models::ErrorResponseSchema),
84    /// You already own this skin.
85    Status551(models::ErrorResponseSchema),
86    /// This skin is not available for purchase.
87    Status552(models::ErrorResponseSchema),
88    /// Insufficient gems.
89    Status563(models::ErrorResponseSchema),
90    /// Request could not be processed due to an invalid payload.
91    Status422(models::ErrorResponseSchema),
92}
93
94impl<'de> Deserialize<'de> for BuySkinError {
95    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
96    where
97        D: Deserializer<'de>,
98    {
99        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
100        match raw.error.code {
101            404 => Ok(Self::Status404(raw)),
102            551 => Ok(Self::Status551(raw)),
103            552 => Ok(Self::Status552(raw)),
104            563 => Ok(Self::Status563(raw)),
105            422 => Ok(Self::Status422(raw)),
106            _ => Err(de::Error::custom(format!(
107                "Unexpected error code: {}",
108                raw.error.code
109            ))),
110        }
111    }
112}
113
114/// struct for typed errors of method [`buy_spawn_event`]
115#[derive(Debug, Clone, Serialize)]
116#[serde(untagged)]
117pub enum BuySpawnEventError {
118    /// Insufficient gems.
119    Status563(models::ErrorResponseSchema),
120    /// Event not found.
121    Status404(models::ErrorResponseSchema),
122    /// Event already active or maximum active events reached.
123    Status564(models::ErrorResponseSchema),
124    /// This event is on cooldown and cannot be spawned yet.
125    Status566(models::ErrorResponseSchema),
126    /// This event is not available for purchase.
127    Status571(models::ErrorResponseSchema),
128    /// Request could not be processed due to an invalid payload.
129    Status422(models::ErrorResponseSchema),
130}
131
132impl<'de> Deserialize<'de> for BuySpawnEventError {
133    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
134    where
135        D: Deserializer<'de>,
136    {
137        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
138        match raw.error.code {
139            563 => Ok(Self::Status563(raw)),
140            404 => Ok(Self::Status404(raw)),
141            564 => Ok(Self::Status564(raw)),
142            566 => Ok(Self::Status566(raw)),
143            571 => Ok(Self::Status571(raw)),
144            422 => Ok(Self::Status422(raw)),
145            _ => Err(de::Error::custom(format!(
146                "Unexpected error code: {}",
147                raw.error.code
148            ))),
149        }
150    }
151}
152
153/// struct for typed errors of method [`buy_subscription`]
154#[derive(Debug, Clone, Serialize)]
155#[serde(untagged)]
156pub enum BuySubscriptionError {
157    /// Insufficient gems.
158    Status563(models::ErrorResponseSchema),
159    /// An active Stripe subscription cannot be extended with gems or member tokens.
160    Status573(models::ErrorResponseSchema),
161    /// Request could not be processed due to an invalid payload.
162    Status422(models::ErrorResponseSchema),
163}
164
165impl<'de> Deserialize<'de> for BuySubscriptionError {
166    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
167    where
168        D: Deserializer<'de>,
169    {
170        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
171        match raw.error.code {
172            563 => Ok(Self::Status563(raw)),
173            573 => Ok(Self::Status573(raw)),
174            422 => Ok(Self::Status422(raw)),
175            _ => Err(de::Error::custom(format!(
176                "Unexpected error code: {}",
177                raw.error.code
178            ))),
179        }
180    }
181}
182
183/// struct for typed errors of method [`get_catalog`]
184#[derive(Debug, Clone, Serialize)]
185#[serde(untagged)]
186pub enum GetCatalogError {}
187
188impl<'de> Deserialize<'de> for GetCatalogError {
189    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
190    where
191        D: Deserializer<'de>,
192    {
193        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
194        Err(de::Error::custom(format!(
195            "Unexpected error code: {}",
196            raw.error.code
197        )))
198    }
199}
200
201/// Buy a custom design using gems.
202pub async fn buy_custom_design(
203    configuration: &configuration::Configuration,
204    params: BuyCustomDesignParams,
205) -> Result<models::GemShopCustomDesignPurchaseResponseSchema, Error<BuyCustomDesignError>> {
206    let local_var_configuration = configuration;
207
208    // unbox the parameters
209    let buy_custom_design_request_schema = params.buy_custom_design_request_schema;
210
211    let local_var_client = &local_var_configuration.client;
212
213    let local_var_uri_str = format!(
214        "{}/gems_shop/buy_custom_design",
215        local_var_configuration.base_path
216    );
217    let mut local_var_req_builder =
218        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder =
222            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223    }
224    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
225        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226    };
227    local_var_req_builder = local_var_req_builder.json(&buy_custom_design_request_schema);
228
229    let local_var_req = local_var_req_builder.build()?;
230    let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232    let local_var_status = local_var_resp.status();
233    let local_var_content = local_var_resp.text().await?;
234
235    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236        serde_json::from_str(&local_var_content).map_err(Error::from)
237    } else {
238        let local_var_entity: Option<BuyCustomDesignError> =
239            serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent {
241            status: local_var_status,
242            content: local_var_content,
243            entity: local_var_entity,
244        };
245        Err(Error::ResponseError(local_var_error))
246    }
247}
248
249/// Buy a skin from the gems shop using gems.
250pub async fn buy_skin(
251    configuration: &configuration::Configuration,
252    params: BuySkinParams,
253) -> Result<models::BuySkinResponseSchema, Error<BuySkinError>> {
254    let local_var_configuration = configuration;
255
256    // unbox the parameters
257    let buy_skin_request_schema = params.buy_skin_request_schema;
258
259    let local_var_client = &local_var_configuration.client;
260
261    let local_var_uri_str = format!("{}/gems_shop/skin", local_var_configuration.base_path);
262    let mut local_var_req_builder =
263        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
264
265    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266        local_var_req_builder =
267            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
270        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
271    };
272    local_var_req_builder = local_var_req_builder.json(&buy_skin_request_schema);
273
274    let local_var_req = local_var_req_builder.build()?;
275    let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277    let local_var_status = local_var_resp.status();
278    let local_var_content = local_var_resp.text().await?;
279
280    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281        serde_json::from_str(&local_var_content).map_err(Error::from)
282    } else {
283        let local_var_entity: Option<BuySkinError> = serde_json::from_str(&local_var_content).ok();
284        let local_var_error = ResponseContent {
285            status: local_var_status,
286            content: local_var_content,
287            entity: local_var_entity,
288        };
289        Err(Error::ResponseError(local_var_error))
290    }
291}
292
293/// Spawn an event from the gems shop using gems.
294pub async fn buy_spawn_event(
295    configuration: &configuration::Configuration,
296    params: BuySpawnEventParams,
297) -> Result<models::ActiveEventResponseSchema, Error<BuySpawnEventError>> {
298    let local_var_configuration = configuration;
299
300    // unbox the parameters
301    let spawn_event_request_schema = params.spawn_event_request_schema;
302
303    let local_var_client = &local_var_configuration.client;
304
305    let local_var_uri_str = format!(
306        "{}/gems_shop/spawn_event",
307        local_var_configuration.base_path
308    );
309    let mut local_var_req_builder =
310        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
311
312    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
313        local_var_req_builder =
314            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
315    }
316    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
317        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
318    };
319    local_var_req_builder = local_var_req_builder.json(&spawn_event_request_schema);
320
321    let local_var_req = local_var_req_builder.build()?;
322    let local_var_resp = local_var_client.execute(local_var_req).await?;
323
324    let local_var_status = local_var_resp.status();
325    let local_var_content = local_var_resp.text().await?;
326
327    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
328        serde_json::from_str(&local_var_content).map_err(Error::from)
329    } else {
330        let local_var_entity: Option<BuySpawnEventError> =
331            serde_json::from_str(&local_var_content).ok();
332        let local_var_error = ResponseContent {
333            status: local_var_status,
334            content: local_var_content,
335            entity: local_var_entity,
336        };
337        Err(Error::ResponseError(local_var_error))
338    }
339}
340
341/// Buy or extend membership by 30 days using gems. Unavailable while a Stripe subscription is active.
342pub async fn buy_subscription(
343    configuration: &configuration::Configuration,
344) -> Result<models::GemShopSubscriptionResponseSchema, Error<BuySubscriptionError>> {
345    let local_var_configuration = configuration;
346
347    let local_var_client = &local_var_configuration.client;
348
349    let local_var_uri_str = format!(
350        "{}/gems_shop/subscription",
351        local_var_configuration.base_path
352    );
353    let mut local_var_req_builder =
354        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
355
356    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
357        local_var_req_builder =
358            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
359    }
360    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
361        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
362    };
363
364    let local_var_req = local_var_req_builder.build()?;
365    let local_var_resp = local_var_client.execute(local_var_req).await?;
366
367    let local_var_status = local_var_resp.status();
368    let local_var_content = local_var_resp.text().await?;
369
370    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
371        serde_json::from_str(&local_var_content).map_err(Error::from)
372    } else {
373        let local_var_entity: Option<BuySubscriptionError> =
374            serde_json::from_str(&local_var_content).ok();
375        let local_var_error = ResponseContent {
376            status: local_var_status,
377            content: local_var_content,
378            entity: local_var_entity,
379        };
380        Err(Error::ResponseError(local_var_error))
381    }
382}
383
384/// Return the gems shop catalog.
385pub async fn get_catalog(
386    configuration: &configuration::Configuration,
387) -> Result<models::GemShopCatalogResponseSchema, Error<GetCatalogError>> {
388    let local_var_configuration = configuration;
389
390    let local_var_client = &local_var_configuration.client;
391
392    let local_var_uri_str = format!("{}/gems_shop/", local_var_configuration.base_path);
393    let mut local_var_req_builder =
394        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
395
396    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
397        local_var_req_builder =
398            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
399    }
400
401    let local_var_req = local_var_req_builder.build()?;
402    let local_var_resp = local_var_client.execute(local_var_req).await?;
403
404    let local_var_status = local_var_resp.status();
405    let local_var_content = local_var_resp.text().await?;
406
407    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
408        serde_json::from_str(&local_var_content).map_err(Error::from)
409    } else {
410        let local_var_entity: Option<GetCatalogError> =
411            serde_json::from_str(&local_var_content).ok();
412        let local_var_error = ResponseContent {
413            status: local_var_status,
414            content: local_var_content,
415            entity: local_var_entity,
416        };
417        Err(Error::ResponseError(local_var_error))
418    }
419}