Skip to main content

artifacts/apis/
season_rewards_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_all_season_rewards`]
7#[derive(Clone, Debug)]
8pub struct GetAllSeasonRewardsParams {
9    /// Filter by reward type.
10    pub r#type: Option<models::RewardType>,
11    /// Page number
12    pub page: Option<u32>,
13    /// Page size
14    pub size: Option<u32>,
15}
16
17impl GetAllSeasonRewardsParams {
18    pub fn new(r#type: Option<models::RewardType>, page: Option<u32>, size: Option<u32>) -> Self {
19        Self { r#type, page, size }
20    }
21}
22
23/// struct for passing parameters to the method [`get_season_rewards_by_code`]
24#[derive(Clone, Debug)]
25pub struct GetSeasonRewardsByCodeParams {
26    /// The code of the season reward.
27    pub code: String,
28    /// Page number
29    pub page: Option<u32>,
30    /// Page size
31    pub size: Option<u32>,
32}
33
34impl GetSeasonRewardsByCodeParams {
35    pub fn new(code: String, page: Option<u32>, size: Option<u32>) -> Self {
36        Self { code, page, size }
37    }
38}
39
40/// struct for typed errors of method [`get_all_season_rewards`]
41#[derive(Debug, Clone, Serialize)]
42#[serde(untagged)]
43pub enum GetAllSeasonRewardsError {}
44
45impl<'de> Deserialize<'de> for GetAllSeasonRewardsError {
46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
47    where
48        D: Deserializer<'de>,
49    {
50        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
51        Err(de::Error::custom(format!(
52            "Unexpected error code: {}",
53            raw.error.code
54        )))
55    }
56}
57
58/// struct for typed errors of method [`get_season_rewards_by_code`]
59#[derive(Debug, Clone, Serialize)]
60#[serde(untagged)]
61pub enum GetSeasonRewardsByCodeError {}
62
63impl<'de> Deserialize<'de> for GetSeasonRewardsByCodeError {
64    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65    where
66        D: Deserializer<'de>,
67    {
68        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
69        Err(de::Error::custom(format!(
70            "Unexpected error code: {}",
71            raw.error.code
72        )))
73    }
74}
75
76/// List of all rewards for the current season.
77pub async fn get_all_season_rewards(
78    configuration: &configuration::Configuration,
79    params: GetAllSeasonRewardsParams,
80) -> Result<models::StaticDataPageSeasonRewardSchema, Error<GetAllSeasonRewardsError>> {
81    let local_var_configuration = configuration;
82
83    // unbox the parameters
84    let r#type = params.r#type;
85    // unbox the parameters
86    let page = params.page;
87    // unbox the parameters
88    let size = params.size;
89
90    let local_var_client = &local_var_configuration.client;
91
92    let local_var_uri_str = format!("{}/season_rewards", local_var_configuration.base_path);
93    let mut local_var_req_builder =
94        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
95
96    if let Some(ref local_var_str) = r#type {
97        local_var_req_builder =
98            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
99    }
100    if let Some(ref local_var_str) = page {
101        local_var_req_builder =
102            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
103    }
104    if let Some(ref local_var_str) = size {
105        local_var_req_builder =
106            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
107    }
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder =
110            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
111    }
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text().await?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        serde_json::from_str(&local_var_content).map_err(Error::from)
121    } else {
122        let local_var_entity: Option<GetAllSeasonRewardsError> =
123            serde_json::from_str(&local_var_content).ok();
124        let local_var_error = ResponseContent {
125            status: local_var_status,
126            content: local_var_content,
127            entity: local_var_entity,
128        };
129        Err(Error::ResponseError(local_var_error))
130    }
131}
132
133/// List all season rewards matching a specific code.
134pub async fn get_season_rewards_by_code(
135    configuration: &configuration::Configuration,
136    params: GetSeasonRewardsByCodeParams,
137) -> Result<models::StaticDataPageSeasonRewardSchema, Error<GetSeasonRewardsByCodeError>> {
138    let local_var_configuration = configuration;
139
140    // unbox the parameters
141    let code = params.code;
142    // unbox the parameters
143    let page = params.page;
144    // unbox the parameters
145    let size = params.size;
146
147    let local_var_client = &local_var_configuration.client;
148
149    let local_var_uri_str = format!(
150        "{}/season_rewards/{code}",
151        local_var_configuration.base_path,
152        code = crate::apis::urlencode(code)
153    );
154    let mut local_var_req_builder =
155        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
156
157    if let Some(ref local_var_str) = page {
158        local_var_req_builder =
159            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
160    }
161    if let Some(ref local_var_str) = size {
162        local_var_req_builder =
163            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
164    }
165    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
166        local_var_req_builder =
167            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169
170    let local_var_req = local_var_req_builder.build()?;
171    let local_var_resp = local_var_client.execute(local_var_req).await?;
172
173    let local_var_status = local_var_resp.status();
174    let local_var_content = local_var_resp.text().await?;
175
176    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
177        serde_json::from_str(&local_var_content).map_err(Error::from)
178    } else {
179        let local_var_entity: Option<GetSeasonRewardsByCodeError> =
180            serde_json::from_str(&local_var_content).ok();
181        let local_var_error = ResponseContent {
182            status: local_var_status,
183            content: local_var_content,
184            entity: local_var_entity,
185        };
186        Err(Error::ResponseError(local_var_error))
187    }
188}