artifacts/apis/
effects_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_effects`]
7#[derive(Clone, Debug)]
8pub struct GetAllEffectsParams {
9    /// Page number
10    pub page: Option<u32>,
11    /// Page size
12    pub size: Option<u32>,
13}
14
15impl GetAllEffectsParams {
16    pub fn new(page: Option<u32>, size: Option<u32>) -> Self {
17        Self { page, size }
18    }
19}
20
21/// struct for passing parameters to the method [`get_effect`]
22#[derive(Clone, Debug)]
23pub struct GetEffectParams {
24    /// The code of the achievement.
25    pub code: String,
26}
27
28impl GetEffectParams {
29    pub fn new(code: String) -> Self {
30        Self { code }
31    }
32}
33
34/// struct for typed errors of method [`get_all_effects`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAllEffectsError {}
38
39impl TryFrom<StatusCode> for GetAllEffectsError {
40    type Error = &'static str;
41    #[allow(clippy::match_single_binding)]
42    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
43        match status.as_u16() {
44            _ => Err("status code not in spec"),
45        }
46    }
47}
48
49/// struct for typed errors of method [`get_effect`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum GetEffectError {
53    /// effect not found.
54    Status404,
55}
56
57impl TryFrom<StatusCode> for GetEffectError {
58    type Error = &'static str;
59    #[allow(clippy::match_single_binding)]
60    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
61        match status.as_u16() {
62            404 => Ok(Self::Status404),
63            _ => Err("status code not in spec"),
64        }
65    }
66}
67
68/// List of all effects. Effects are used by equipment, tools, runes, consumables and monsters. An effect is an action that produces an effect on the game.
69pub async fn get_all_effects(
70    configuration: &configuration::Configuration,
71    params: GetAllEffectsParams,
72) -> Result<models::DataPageEffectSchema, Error<GetAllEffectsError>> {
73    let local_var_configuration = configuration;
74
75    // unbox the parameters
76    let page = params.page;
77    // unbox the parameters
78    let size = params.size;
79
80    let local_var_client = &local_var_configuration.client;
81
82    let local_var_uri_str = format!("{}/effects", local_var_configuration.base_path);
83    let mut local_var_req_builder =
84        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
85
86    if let Some(ref local_var_str) = page {
87        local_var_req_builder =
88            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
89    }
90    if let Some(ref local_var_str) = size {
91        local_var_req_builder =
92            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
93    }
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder =
96            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97    }
98
99    let local_var_req = local_var_req_builder.build()?;
100    let local_var_resp = local_var_client.execute(local_var_req).await?;
101
102    let local_var_status = local_var_resp.status();
103    let local_var_content = local_var_resp.text().await?;
104
105    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
106        serde_json::from_str(&local_var_content).map_err(Error::from)
107    } else {
108        let local_var_entity: Option<GetAllEffectsError> = local_var_status.try_into().ok();
109        let local_var_error = ResponseContent {
110            status: local_var_status,
111            content: local_var_content,
112            entity: local_var_entity,
113        };
114        Err(Error::ResponseError(local_var_error))
115    }
116}
117
118/// Retrieve the details of a badge.
119pub async fn get_effect(
120    configuration: &configuration::Configuration,
121    params: GetEffectParams,
122) -> Result<models::EffectResponseSchema, Error<GetEffectError>> {
123    let local_var_configuration = configuration;
124
125    // unbox the parameters
126    let code = params.code;
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!(
131        "{}/effects/{code}",
132        local_var_configuration.base_path,
133        code = crate::apis::urlencode(code)
134    );
135    let mut local_var_req_builder =
136        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
137
138    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
139        local_var_req_builder =
140            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141    }
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<GetEffectError> = local_var_status.try_into().ok();
153        let local_var_error = ResponseContent {
154            status: local_var_status,
155            content: local_var_content,
156            entity: local_var_entity,
157        };
158        Err(Error::ResponseError(local_var_error))
159    }
160}