artifacts/apis/
tasks_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_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    /// Skill of tasks.
14    pub skill: Option<models::Skill>,
15    /// 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)]
86#[serde(untagged)]
87pub enum GetAllTasksError {}
88
89impl<'de> Deserialize<'de> for GetAllTasksError {
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        Err(de::Error::custom(format!(
96            "Unexpected error code: {}",
97            raw.error.code
98        )))
99    }
100}
101
102/// struct for typed errors of method [`get_all_tasks_rewards`]
103#[derive(Debug, Clone, Serialize)]
104#[serde(untagged)]
105pub enum GetAllTasksRewardsError {}
106
107impl<'de> Deserialize<'de> for GetAllTasksRewardsError {
108    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
109    where
110        D: Deserializer<'de>,
111    {
112        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
113        Err(de::Error::custom(format!(
114            "Unexpected error code: {}",
115            raw.error.code
116        )))
117    }
118}
119
120/// struct for typed errors of method [`get_task`]
121#[derive(Debug, Clone, Serialize)]
122#[serde(untagged)]
123pub enum GetTaskError {
124    /// task not found.
125    Status404(models::ErrorResponseSchema),
126}
127
128impl<'de> Deserialize<'de> for GetTaskError {
129    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
130    where
131        D: Deserializer<'de>,
132    {
133        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
134        match raw.error.code {
135            404 => Ok(Self::Status404(raw)),
136            _ => Err(de::Error::custom(format!(
137                "Unexpected error code: {}",
138                raw.error.code
139            ))),
140        }
141    }
142}
143
144/// struct for typed errors of method [`get_tasks_reward`]
145#[derive(Debug, Clone, Serialize)]
146#[serde(untagged)]
147pub enum GetTasksRewardError {
148    /// tasks reward not found.
149    Status404(models::ErrorResponseSchema),
150}
151
152impl<'de> Deserialize<'de> for GetTasksRewardError {
153    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
154    where
155        D: Deserializer<'de>,
156    {
157        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
158        match raw.error.code {
159            404 => Ok(Self::Status404(raw)),
160            _ => Err(de::Error::custom(format!(
161                "Unexpected error code: {}",
162                raw.error.code
163            ))),
164        }
165    }
166}
167
168/// Fetch the list of all tasks.
169pub async fn get_all_tasks(
170    configuration: &configuration::Configuration,
171    params: GetAllTasksParams,
172) -> Result<models::DataPageTaskFullSchema, Error<GetAllTasksError>> {
173    let local_var_configuration = configuration;
174
175    // unbox the parameters
176    let min_level = params.min_level;
177    // unbox the parameters
178    let max_level = params.max_level;
179    // unbox the parameters
180    let skill = params.skill;
181    // unbox the parameters
182    let r#type = params.r#type;
183    // unbox the parameters
184    let page = params.page;
185    // unbox the parameters
186    let size = params.size;
187
188    let local_var_client = &local_var_configuration.client;
189
190    let local_var_uri_str = format!("{}/tasks/list", local_var_configuration.base_path);
191    let mut local_var_req_builder =
192        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194    if let Some(ref local_var_str) = min_level {
195        local_var_req_builder =
196            local_var_req_builder.query(&[("min_level", &local_var_str.to_string())]);
197    }
198    if let Some(ref local_var_str) = max_level {
199        local_var_req_builder =
200            local_var_req_builder.query(&[("max_level", &local_var_str.to_string())]);
201    }
202    if let Some(ref local_var_str) = skill {
203        local_var_req_builder =
204            local_var_req_builder.query(&[("skill", &local_var_str.to_string())]);
205    }
206    if let Some(ref local_var_str) = r#type {
207        local_var_req_builder =
208            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
209    }
210    if let Some(ref local_var_str) = page {
211        local_var_req_builder =
212            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
213    }
214    if let Some(ref local_var_str) = size {
215        local_var_req_builder =
216            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
217    }
218    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219        local_var_req_builder =
220            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221    }
222
223    let local_var_req = local_var_req_builder.build()?;
224    let local_var_resp = local_var_client.execute(local_var_req).await?;
225
226    let local_var_status = local_var_resp.status();
227    let local_var_content = local_var_resp.text().await?;
228
229    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
230        serde_json::from_str(&local_var_content).map_err(Error::from)
231    } else {
232        let local_var_entity: Option<GetAllTasksError> =
233            serde_json::from_str(&local_var_content).ok();
234        let local_var_error = ResponseContent {
235            status: local_var_status,
236            content: local_var_content,
237            entity: local_var_entity,
238        };
239        Err(Error::ResponseError(local_var_error))
240    }
241}
242
243/// Fetch the list of all tasks rewards. To obtain these rewards, you must exchange 6 task coins with a tasks master.
244pub async fn get_all_tasks_rewards(
245    configuration: &configuration::Configuration,
246    params: GetAllTasksRewardsParams,
247) -> Result<models::DataPageDropRateSchema, Error<GetAllTasksRewardsError>> {
248    let local_var_configuration = configuration;
249
250    // unbox the parameters
251    let page = params.page;
252    // unbox the parameters
253    let size = params.size;
254
255    let local_var_client = &local_var_configuration.client;
256
257    let local_var_uri_str = format!("{}/tasks/rewards", local_var_configuration.base_path);
258    let mut local_var_req_builder =
259        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
260
261    if let Some(ref local_var_str) = page {
262        local_var_req_builder =
263            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
264    }
265    if let Some(ref local_var_str) = size {
266        local_var_req_builder =
267            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
268    }
269    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
270        local_var_req_builder =
271            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
272    }
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<GetAllTasksRewardsError> =
284            serde_json::from_str(&local_var_content).ok();
285        let local_var_error = ResponseContent {
286            status: local_var_status,
287            content: local_var_content,
288            entity: local_var_entity,
289        };
290        Err(Error::ResponseError(local_var_error))
291    }
292}
293
294/// Retrieve the details of a task.
295pub async fn get_task(
296    configuration: &configuration::Configuration,
297    params: GetTaskParams,
298) -> Result<models::TaskFullResponseSchema, Error<GetTaskError>> {
299    let local_var_configuration = configuration;
300
301    // unbox the parameters
302    let code = params.code;
303
304    let local_var_client = &local_var_configuration.client;
305
306    let local_var_uri_str = format!(
307        "{}/tasks/list/{code}",
308        local_var_configuration.base_path,
309        code = crate::apis::urlencode(code)
310    );
311    let mut local_var_req_builder =
312        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
313
314    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
315        local_var_req_builder =
316            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
317    }
318
319    let local_var_req = local_var_req_builder.build()?;
320    let local_var_resp = local_var_client.execute(local_var_req).await?;
321
322    let local_var_status = local_var_resp.status();
323    let local_var_content = local_var_resp.text().await?;
324
325    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
326        serde_json::from_str(&local_var_content).map_err(Error::from)
327    } else {
328        let local_var_entity: Option<GetTaskError> = serde_json::from_str(&local_var_content).ok();
329        let local_var_error = ResponseContent {
330            status: local_var_status,
331            content: local_var_content,
332            entity: local_var_entity,
333        };
334        Err(Error::ResponseError(local_var_error))
335    }
336}
337
338/// Retrieve the details of a tasks reward.
339pub async fn get_tasks_reward(
340    configuration: &configuration::Configuration,
341    params: GetTasksRewardParams,
342) -> Result<models::RewardResponseSchema, Error<GetTasksRewardError>> {
343    let local_var_configuration = configuration;
344
345    // unbox the parameters
346    let code = params.code;
347
348    let local_var_client = &local_var_configuration.client;
349
350    let local_var_uri_str = format!(
351        "{}/tasks/rewards/{code}",
352        local_var_configuration.base_path,
353        code = crate::apis::urlencode(code)
354    );
355    let mut local_var_req_builder =
356        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
357
358    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
359        local_var_req_builder =
360            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
361    }
362
363    let local_var_req = local_var_req_builder.build()?;
364    let local_var_resp = local_var_client.execute(local_var_req).await?;
365
366    let local_var_status = local_var_resp.status();
367    let local_var_content = local_var_resp.text().await?;
368
369    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
370        serde_json::from_str(&local_var_content).map_err(Error::from)
371    } else {
372        let local_var_entity: Option<GetTasksRewardError> =
373            serde_json::from_str(&local_var_content).ok();
374        let local_var_error = ResponseContent {
375            status: local_var_status,
376            content: local_var_content,
377            entity: local_var_entity,
378        };
379        Err(Error::ResponseError(local_var_error))
380    }
381}