artifacts/apis/
resources_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_resources`]
7#[derive(Clone, Debug)]
8pub struct GetAllResourcesParams {
9    /// Skill minimum level.
10    pub min_level: Option<u32>,
11    /// Skill maximum level.
12    pub max_level: Option<u32>,
13    /// The code of the skill.
14    pub skill: Option<models::GatheringSkill>,
15    /// Item code of the drop.
16    pub drop: Option<String>,
17    /// Page number
18    pub page: Option<u32>,
19    /// Page size
20    pub size: Option<u32>,
21}
22
23impl GetAllResourcesParams {
24    pub fn new(
25        min_level: Option<u32>,
26        max_level: Option<u32>,
27        skill: Option<models::GatheringSkill>,
28        drop: Option<String>,
29        page: Option<u32>,
30        size: Option<u32>,
31    ) -> Self {
32        Self {
33            min_level,
34            max_level,
35            skill,
36            drop,
37            page,
38            size,
39        }
40    }
41}
42
43/// struct for passing parameters to the method [`get_resource`]
44#[derive(Clone, Debug)]
45pub struct GetResourceParams {
46    /// The code of the resource.
47    pub code: String,
48}
49
50impl GetResourceParams {
51    pub fn new(code: String) -> Self {
52        Self { code }
53    }
54}
55
56/// struct for typed errors of method [`get_all_resources`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetAllResourcesError {}
60
61impl TryFrom<StatusCode> for GetAllResourcesError {
62    type Error = &'static str;
63    #[allow(clippy::match_single_binding)]
64    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
65        match status.as_u16() {
66            _ => Err("status code not in spec"),
67        }
68    }
69}
70
71/// struct for typed errors of method [`get_resource`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetResourceError {
75    /// Resource not found.
76    Status404,
77}
78
79impl TryFrom<StatusCode> for GetResourceError {
80    type Error = &'static str;
81    #[allow(clippy::match_single_binding)]
82    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
83        match status.as_u16() {
84            404 => Ok(Self::Status404),
85            _ => Err("status code not in spec"),
86        }
87    }
88}
89
90/// Fetch resources details.
91pub async fn get_all_resources(
92    configuration: &configuration::Configuration,
93    params: GetAllResourcesParams,
94) -> Result<models::DataPageResourceSchema, Error<GetAllResourcesError>> {
95    let local_var_configuration = configuration;
96
97    // unbox the parameters
98    let min_level = params.min_level;
99    // unbox the parameters
100    let max_level = params.max_level;
101    // unbox the parameters
102    let skill = params.skill;
103    // unbox the parameters
104    let drop = params.drop;
105    // unbox the parameters
106    let page = params.page;
107    // unbox the parameters
108    let size = params.size;
109
110    let local_var_client = &local_var_configuration.client;
111
112    let local_var_uri_str = format!("{}/resources", local_var_configuration.base_path);
113    let mut local_var_req_builder =
114        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
115
116    if let Some(ref local_var_str) = min_level {
117        local_var_req_builder =
118            local_var_req_builder.query(&[("min_level", &local_var_str.to_string())]);
119    }
120    if let Some(ref local_var_str) = max_level {
121        local_var_req_builder =
122            local_var_req_builder.query(&[("max_level", &local_var_str.to_string())]);
123    }
124    if let Some(ref local_var_str) = skill {
125        local_var_req_builder =
126            local_var_req_builder.query(&[("skill", &local_var_str.to_string())]);
127    }
128    if let Some(ref local_var_str) = drop {
129        local_var_req_builder =
130            local_var_req_builder.query(&[("drop", &local_var_str.to_string())]);
131    }
132    if let Some(ref local_var_str) = page {
133        local_var_req_builder =
134            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = size {
137        local_var_req_builder =
138            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
139    }
140    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
141        local_var_req_builder =
142            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
143    }
144
145    let local_var_req = local_var_req_builder.build()?;
146    let local_var_resp = local_var_client.execute(local_var_req).await?;
147
148    let local_var_status = local_var_resp.status();
149    let local_var_content = local_var_resp.text().await?;
150
151    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
152        serde_json::from_str(&local_var_content).map_err(Error::from)
153    } else {
154        let local_var_entity: Option<GetAllResourcesError> = local_var_status.try_into().ok();
155        let local_var_error = ResponseContent {
156            status: local_var_status,
157            content: local_var_content,
158            entity: local_var_entity,
159        };
160        Err(Error::ResponseError(local_var_error))
161    }
162}
163
164/// Retrieve the details of a resource.
165pub async fn get_resource(
166    configuration: &configuration::Configuration,
167    params: GetResourceParams,
168) -> Result<models::ResourceResponseSchema, Error<GetResourceError>> {
169    let local_var_configuration = configuration;
170
171    // unbox the parameters
172    let code = params.code;
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!(
177        "{}/resources/{code}",
178        local_var_configuration.base_path,
179        code = crate::apis::urlencode(code)
180    );
181    let mut local_var_req_builder =
182        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
183
184    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
185        local_var_req_builder =
186            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188
189    let local_var_req = local_var_req_builder.build()?;
190    let local_var_resp = local_var_client.execute(local_var_req).await?;
191
192    let local_var_status = local_var_resp.status();
193    let local_var_content = local_var_resp.text().await?;
194
195    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
196        serde_json::from_str(&local_var_content).map_err(Error::from)
197    } else {
198        let local_var_entity: Option<GetResourceError> = local_var_status.try_into().ok();
199        let local_var_error = ResponseContent {
200            status: local_var_status,
201            content: local_var_content,
202            entity: local_var_entity,
203        };
204        Err(Error::ResponseError(local_var_error))
205    }
206}