thunderstore_api/apis/v2/
mod.rs

1////////////////////////////////////////////////////////////////////////////////
2// This Source Code Form is subject to the terms of the Mozilla Public         /
3// License, v. 2.0. If a copy of the MPL was not distributed with this         /
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.                   /
5////////////////////////////////////////////////////////////////////////////////
6
7use crate::apis::configuration::Configuration;
8use crate::apis::{Error, ResponseContent};
9use crate::models::v2::community::Community;
10use crate::models::v2::front_page_content::FrontPageContent;
11use crate::models::v2::render_markdown::{RenderMarkdownParams, RenderMarkdownResponse};
12
13pub mod authenticate;
14pub mod community;
15pub mod package;
16pub mod submission;
17pub mod user_media;
18
19/// struct for typed errors of method [`api_experimental_current_user_list`]
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum CurrentUserError {
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`api_experimental_submission_upload_list`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum UploadListError {
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`experimental_period_community_period_current`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum CurrentCommunityError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`experimental_period_frontend_period_frontpage`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum FrontpageError {
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`experimental_period_frontend_period_render_markdown`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum RenderMarkdownError {
51    UnknownValue(serde_json::Value),
52}
53
54/// Gets information about the current user, such as rated packages and permissions
55pub async fn current_user(configuration: &Configuration) -> Result<(), Error<CurrentUserError>> {
56    let local_var_configuration = configuration;
57
58    let local_var_client = &local_var_configuration.client;
59
60    let local_var_uri_str = format!(
61        "{}/api/experimental/current-user/",
62        local_var_configuration.base_path
63    );
64    let mut local_var_req_builder =
65        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
66
67    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
68        local_var_req_builder =
69            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
70    }
71    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
72        local_var_req_builder = local_var_req_builder
73            .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
74    };
75
76    let local_var_req = local_var_req_builder.build()?;
77    let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79    let local_var_status = local_var_resp.status();
80    let local_var_content = local_var_resp.text().await?;
81
82    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83        Ok(())
84    } else {
85        let local_var_entity: Option<CurrentUserError> =
86            serde_json::from_str(&local_var_content).ok();
87        let local_var_error = ResponseContent {
88            status: local_var_status,
89            content: local_var_content,
90            entity: local_var_entity,
91        };
92        Err(Error::ResponseError(local_var_error))
93    }
94}
95
96/// Uploads a package. Requires multipart/form-data.
97pub async fn upload_list(configuration: &Configuration) -> Result<(), Error<UploadListError>> {
98    let local_var_configuration = configuration;
99
100    let local_var_client = &local_var_configuration.client;
101
102    let local_var_uri_str = format!(
103        "{}/api/experimental/submission/upload/",
104        local_var_configuration.base_path
105    );
106    let mut local_var_req_builder =
107        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
108
109    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
110        local_var_req_builder =
111            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112    }
113    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
114        local_var_req_builder = local_var_req_builder
115            .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
116    };
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    let local_var_status = local_var_resp.status();
122    let local_var_content = local_var_resp.text().await?;
123
124    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125        Ok(())
126    } else {
127        let local_var_entity: Option<UploadListError> =
128            serde_json::from_str(&local_var_content).ok();
129        let local_var_error = ResponseContent {
130            status: local_var_status,
131            content: local_var_content,
132            entity: local_var_entity,
133        };
134        Err(Error::ResponseError(local_var_error))
135    }
136}
137
138/// Fetch the Community of the queried domain
139pub async fn current_community(
140    configuration: &Configuration,
141) -> Result<Community, Error<CurrentCommunityError>> {
142    let local_var_configuration = configuration;
143
144    let local_var_client = &local_var_configuration.client;
145
146    let local_var_uri_str = format!(
147        "{}/api/experimental/current-community/",
148        local_var_configuration.base_path
149    );
150    let mut local_var_req_builder =
151        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
152
153    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
154        local_var_req_builder =
155            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
156    }
157    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
158        local_var_req_builder = local_var_req_builder
159            .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
160    };
161
162    let local_var_req = local_var_req_builder.build()?;
163    let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165    let local_var_status = local_var_resp.status();
166    let local_var_content = local_var_resp.text().await?;
167
168    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
169        serde_json::from_str(&local_var_content).map_err(Error::from)
170    } else {
171        let local_var_entity: Option<CurrentCommunityError> =
172            serde_json::from_str(&local_var_content).ok();
173        let local_var_error = ResponseContent {
174            status: local_var_status,
175            content: local_var_content,
176            entity: local_var_entity,
177        };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182/// Return information required to render the site's front page.
183pub async fn frontpage(
184    configuration: &Configuration,
185) -> Result<FrontPageContent, Error<FrontpageError>> {
186    let local_var_configuration = configuration;
187
188    let local_var_client = &local_var_configuration.client;
189
190    let local_var_uri_str = format!(
191        "{}/api/experimental/frontend/frontpage/",
192        local_var_configuration.base_path
193    );
194    let mut local_var_req_builder =
195        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
196
197    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198        local_var_req_builder =
199            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
200    }
201    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
202        local_var_req_builder = local_var_req_builder
203            .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
204    };
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text().await?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<FrontpageError> =
216            serde_json::from_str(&local_var_content).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
226pub async fn render_markdown(
227    configuration: &Configuration,
228    data: RenderMarkdownParams,
229) -> Result<RenderMarkdownResponse, Error<RenderMarkdownError>> {
230    let local_var_configuration = configuration;
231
232    let local_var_client = &local_var_configuration.client;
233
234    let local_var_uri_str = format!(
235        "{}/api/experimental/frontend/render-markdown/",
236        local_var_configuration.base_path
237    );
238    let mut local_var_req_builder =
239        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
240
241    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
242        local_var_req_builder =
243            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244    }
245    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
246        local_var_req_builder = local_var_req_builder
247            .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
248    };
249    local_var_req_builder = local_var_req_builder.json(&data);
250
251    let local_var_req = local_var_req_builder.build()?;
252    let local_var_resp = local_var_client.execute(local_var_req).await?;
253
254    let local_var_status = local_var_resp.status();
255    let local_var_content = local_var_resp.text().await?;
256
257    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
258        serde_json::from_str(&local_var_content).map_err(Error::from)
259    } else {
260        let local_var_entity: Option<RenderMarkdownError> =
261            serde_json::from_str(&local_var_content).ok();
262        let local_var_error = ResponseContent {
263            status: local_var_status,
264            content: local_var_content,
265            entity: local_var_entity,
266        };
267        Err(Error::ResponseError(local_var_error))
268    }
269}