artifacts/apis/
effects_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_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 effect.
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)]
36#[serde(untagged)]
37pub enum GetAllEffectsError {}
38
39impl<'de> Deserialize<'de> for GetAllEffectsError {
40    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
41    where
42        D: Deserializer<'de>,
43    {
44        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
45        Err(de::Error::custom(format!(
46            "Unexpected error code: {}",
47            raw.error.code
48        )))
49    }
50}
51
52/// struct for typed errors of method [`get_effect`]
53#[derive(Debug, Clone, Serialize)]
54#[serde(untagged)]
55pub enum GetEffectError {
56    /// effect not found.
57    Status404(models::ErrorResponseSchema),
58}
59
60impl<'de> Deserialize<'de> for GetEffectError {
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            404 => Ok(Self::Status404(raw)),
68            _ => Err(de::Error::custom(format!(
69                "Unexpected error code: {}",
70                raw.error.code
71            ))),
72        }
73    }
74}
75
76/// 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.
77pub async fn get_all_effects(
78    configuration: &configuration::Configuration,
79    params: GetAllEffectsParams,
80) -> Result<models::DataPageEffectSchema, Error<GetAllEffectsError>> {
81    let local_var_configuration = configuration;
82
83    // unbox the parameters
84    let page = params.page;
85    // unbox the parameters
86    let size = params.size;
87
88    let local_var_client = &local_var_configuration.client;
89
90    let local_var_uri_str = format!("{}/effects", local_var_configuration.base_path);
91    let mut local_var_req_builder =
92        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_str) = page {
95        local_var_req_builder =
96            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
97    }
98    if let Some(ref local_var_str) = size {
99        local_var_req_builder =
100            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
101    }
102    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103        local_var_req_builder =
104            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105    }
106
107    let local_var_req = local_var_req_builder.build()?;
108    let local_var_resp = local_var_client.execute(local_var_req).await?;
109
110    let local_var_status = local_var_resp.status();
111    let local_var_content = local_var_resp.text().await?;
112
113    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114        serde_json::from_str(&local_var_content).map_err(Error::from)
115    } else {
116        let local_var_entity: Option<GetAllEffectsError> =
117            serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent {
119            status: local_var_status,
120            content: local_var_content,
121            entity: local_var_entity,
122        };
123        Err(Error::ResponseError(local_var_error))
124    }
125}
126
127/// Retrieve the details of an effect.
128pub async fn get_effect(
129    configuration: &configuration::Configuration,
130    params: GetEffectParams,
131) -> Result<models::EffectResponseSchema, Error<GetEffectError>> {
132    let local_var_configuration = configuration;
133
134    // unbox the parameters
135    let code = params.code;
136
137    let local_var_client = &local_var_configuration.client;
138
139    let local_var_uri_str = format!(
140        "{}/effects/{code}",
141        local_var_configuration.base_path,
142        code = crate::apis::urlencode(code)
143    );
144    let mut local_var_req_builder =
145        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
146
147    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148        local_var_req_builder =
149            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
150    }
151
152    let local_var_req = local_var_req_builder.build()?;
153    let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155    let local_var_status = local_var_resp.status();
156    let local_var_content = local_var_resp.text().await?;
157
158    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159        serde_json::from_str(&local_var_content).map_err(Error::from)
160    } else {
161        let local_var_entity: Option<GetEffectError> =
162            serde_json::from_str(&local_var_content).ok();
163        let local_var_error = ResponseContent {
164            status: local_var_status,
165            content: local_var_content,
166            entity: local_var_entity,
167        };
168        Err(Error::ResponseError(local_var_error))
169    }
170}