artifacts/apis/
tasks_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6/// struct for passing parameters to the method [`get_all_tasks`]
7#[derive(Clone, Debug)]
8pub struct GetAllTasksParams {
9    /// Minimum level.
10    pub min_level: Option<u32>,
11    /// Maximum level.
12    pub max_level: Option<u32>,
13    /// The code of the skill.
14    pub skill: Option<models::Skill>,
15    /// The type of tasks.
16    pub r#type: Option<models::TaskType>,
17    /// Page number
18    pub page: Option<u32>,
19    /// Page size
20    pub size: Option<u32>,
21}
22
23impl GetAllTasksParams {
24    pub fn new(
25        min_level: Option<u32>,
26        max_level: Option<u32>,
27        skill: Option<models::Skill>,
28        r#type: Option<models::TaskType>,
29        page: Option<u32>,
30        size: Option<u32>,
31    ) -> Self {
32        Self {
33            min_level,
34            max_level,
35            skill,
36            r#type,
37            page,
38            size,
39        }
40    }
41}
42
43/// struct for passing parameters to the method [`get_all_tasks_rewards`]
44#[derive(Clone, Debug)]
45pub struct GetAllTasksRewardsParams {
46    /// Page number
47    pub page: Option<u32>,
48    /// Page size
49    pub size: Option<u32>,
50}
51
52impl GetAllTasksRewardsParams {
53    pub fn new(page: Option<u32>, size: Option<u32>) -> Self {
54        Self { page, size }
55    }
56}
57
58/// struct for passing parameters to the method [`get_task`]
59#[derive(Clone, Debug)]
60pub struct GetTaskParams {
61    /// The code of the task.
62    pub code: String,
63}
64
65impl GetTaskParams {
66    pub fn new(code: String) -> Self {
67        Self { code }
68    }
69}
70
71/// struct for passing parameters to the method [`get_tasks_reward`]
72#[derive(Clone, Debug)]
73pub struct GetTasksRewardParams {
74    /// The code of the tasks reward.
75    pub code: String,
76}
77
78impl GetTasksRewardParams {
79    pub fn new(code: String) -> Self {
80        Self { code }
81    }
82}
83
84/// struct for typed errors of method [`get_all_tasks`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum GetAllTasksError {}
88
89impl TryFrom<StatusCode> for GetAllTasksError {
90    type Error = &'static str;
91    #[allow(clippy::match_single_binding)]
92    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
93        match status.as_u16() {
94            _ => Err("status code not in spec"),
95        }
96    }
97}
98
99/// struct for typed errors of method [`get_all_tasks_rewards`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetAllTasksRewardsError {}
103
104impl TryFrom<StatusCode> for GetAllTasksRewardsError {
105    type Error = &'static str;
106    #[allow(clippy::match_single_binding)]
107    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
108        match status.as_u16() {
109            _ => Err("status code not in spec"),
110        }
111    }
112}
113
114/// struct for typed errors of method [`get_task`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum GetTaskError {
118    /// Task not found.
119    Status404,
120}
121
122impl TryFrom<StatusCode> for GetTaskError {
123    type Error = &'static str;
124    #[allow(clippy::match_single_binding)]
125    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
126        match status.as_u16() {
127            404 => Ok(Self::Status404),
128            _ => Err("status code not in spec"),
129        }
130    }
131}
132
133/// struct for typed errors of method [`get_tasks_reward`]
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum GetTasksRewardError {
137    /// Tasks reward not found.
138    Status404,
139}
140
141impl TryFrom<StatusCode> for GetTasksRewardError {
142    type Error = &'static str;
143    #[allow(clippy::match_single_binding)]
144    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
145        match status.as_u16() {
146            404 => Ok(Self::Status404),
147            _ => Err("status code not in spec"),
148        }
149    }
150}
151
152/// Fetch the list of all tasks.
153pub async fn get_all_tasks(
154    configuration: &configuration::Configuration,
155    params: GetAllTasksParams,
156) -> Result<models::DataPageTaskFullSchema, Error<GetAllTasksError>> {
157    let local_var_configuration = configuration;
158
159    // unbox the parameters
160    let min_level = params.min_level;
161    // unbox the parameters
162    let max_level = params.max_level;
163    // unbox the parameters
164    let skill = params.skill;
165    // unbox the parameters
166    let r#type = params.r#type;
167    // unbox the parameters
168    let page = params.page;
169    // unbox the parameters
170    let size = params.size;
171
172    let local_var_client = &local_var_configuration.client;
173
174    let local_var_uri_str = format!("{}/tasks/list", local_var_configuration.base_path);
175    let mut local_var_req_builder =
176        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
177
178    if let Some(ref local_var_str) = min_level {
179        local_var_req_builder =
180            local_var_req_builder.query(&[("min_level", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_str) = max_level {
183        local_var_req_builder =
184            local_var_req_builder.query(&[("max_level", &local_var_str.to_string())]);
185    }
186    if let Some(ref local_var_str) = skill {
187        local_var_req_builder =
188            local_var_req_builder.query(&[("skill", &local_var_str.to_string())]);
189    }
190    if let Some(ref local_var_str) = r#type {
191        local_var_req_builder =
192            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
193    }
194    if let Some(ref local_var_str) = page {
195        local_var_req_builder =
196            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
197    }
198    if let Some(ref local_var_str) = size {
199        local_var_req_builder =
200            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
201    }
202    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
203        local_var_req_builder =
204            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205    }
206
207    let local_var_req = local_var_req_builder.build()?;
208    let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210    let local_var_status = local_var_resp.status();
211    let local_var_content = local_var_resp.text().await?;
212
213    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214        serde_json::from_str(&local_var_content).map_err(Error::from)
215    } else {
216        let local_var_entity: Option<GetAllTasksError> = local_var_status.try_into().ok();
217        let local_var_error = ResponseContent {
218            status: local_var_status,
219            content: local_var_content,
220            entity: local_var_entity,
221        };
222        Err(Error::ResponseError(local_var_error))
223    }
224}
225
226/// Fetch the list of all tasks rewards. To obtain these rewards, you must exchange 6 task coins with a tasks master.
227pub async fn get_all_tasks_rewards(
228    configuration: &configuration::Configuration,
229    params: GetAllTasksRewardsParams,
230) -> Result<models::DataPageDropRateSchema, Error<GetAllTasksRewardsError>> {
231    let local_var_configuration = configuration;
232
233    // unbox the parameters
234    let page = params.page;
235    // unbox the parameters
236    let size = params.size;
237
238    let local_var_client = &local_var_configuration.client;
239
240    let local_var_uri_str = format!("{}/tasks/rewards", local_var_configuration.base_path);
241    let mut local_var_req_builder =
242        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
243
244    if let Some(ref local_var_str) = page {
245        local_var_req_builder =
246            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
247    }
248    if let Some(ref local_var_str) = size {
249        local_var_req_builder =
250            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
251    }
252    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
253        local_var_req_builder =
254            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
255    }
256
257    let local_var_req = local_var_req_builder.build()?;
258    let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260    let local_var_status = local_var_resp.status();
261    let local_var_content = local_var_resp.text().await?;
262
263    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264        serde_json::from_str(&local_var_content).map_err(Error::from)
265    } else {
266        let local_var_entity: Option<GetAllTasksRewardsError> = local_var_status.try_into().ok();
267        let local_var_error = ResponseContent {
268            status: local_var_status,
269            content: local_var_content,
270            entity: local_var_entity,
271        };
272        Err(Error::ResponseError(local_var_error))
273    }
274}
275
276/// Retrieve the details of a task.
277pub async fn get_task(
278    configuration: &configuration::Configuration,
279    params: GetTaskParams,
280) -> Result<models::TaskFullResponseSchema, Error<GetTaskError>> {
281    let local_var_configuration = configuration;
282
283    // unbox the parameters
284    let code = params.code;
285
286    let local_var_client = &local_var_configuration.client;
287
288    let local_var_uri_str = format!(
289        "{}/tasks/list/{code}",
290        local_var_configuration.base_path,
291        code = crate::apis::urlencode(code)
292    );
293    let mut local_var_req_builder =
294        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
295
296    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
297        local_var_req_builder =
298            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299    }
300
301    let local_var_req = local_var_req_builder.build()?;
302    let local_var_resp = local_var_client.execute(local_var_req).await?;
303
304    let local_var_status = local_var_resp.status();
305    let local_var_content = local_var_resp.text().await?;
306
307    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
308        serde_json::from_str(&local_var_content).map_err(Error::from)
309    } else {
310        let local_var_entity: Option<GetTaskError> = local_var_status.try_into().ok();
311        let local_var_error = ResponseContent {
312            status: local_var_status,
313            content: local_var_content,
314            entity: local_var_entity,
315        };
316        Err(Error::ResponseError(local_var_error))
317    }
318}
319
320/// Retrieve the details of a tasks reward.
321pub async fn get_tasks_reward(
322    configuration: &configuration::Configuration,
323    params: GetTasksRewardParams,
324) -> Result<models::RewardResponseSchema, Error<GetTasksRewardError>> {
325    let local_var_configuration = configuration;
326
327    // unbox the parameters
328    let code = params.code;
329
330    let local_var_client = &local_var_configuration.client;
331
332    let local_var_uri_str = format!(
333        "{}/tasks/rewards/{code}",
334        local_var_configuration.base_path,
335        code = crate::apis::urlencode(code)
336    );
337    let mut local_var_req_builder =
338        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
339
340    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
341        local_var_req_builder =
342            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
343    }
344
345    let local_var_req = local_var_req_builder.build()?;
346    let local_var_resp = local_var_client.execute(local_var_req).await?;
347
348    let local_var_status = local_var_resp.status();
349    let local_var_content = local_var_resp.text().await?;
350
351    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
352        serde_json::from_str(&local_var_content).map_err(Error::from)
353    } else {
354        let local_var_entity: Option<GetTasksRewardError> = local_var_status.try_into().ok();
355        let local_var_error = ResponseContent {
356            status: local_var_status,
357            content: local_var_content,
358            entity: local_var_entity,
359        };
360        Err(Error::ResponseError(local_var_error))
361    }
362}