1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddFilesToVersionError {
22 Status401(models::AuthError),
23 Status404(),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateVersionError {
31 Status400(models::InvalidInputError),
32 Status401(models::AuthError),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteVersionError {
40 Status401(models::AuthError),
41 Status404(),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetProjectVersionsError {
49 Status404(),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetVersionError {
57 Status404(),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetVersionFromIdOrNumberError {
65 Status404(),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetVersionsError {
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ModifyVersionError {
80 Status401(models::AuthError),
81 Status404(),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ScheduleVersionError {
89 Status400(models::InvalidInputError),
90 Status401(models::AuthError),
91 UnknownValue(serde_json::Value),
92}
93
94
95pub async fn add_files_to_version(configuration: &configuration::Configuration, id: &str, data: Option<serde_json::Value>) -> Result<(), Error<AddFilesToVersionError>> {
97 let local_var_configuration = configuration;
98
99 let local_var_client = &local_var_configuration.client;
100
101 let local_var_uri_str = format!("{}/version/{id}/file", local_var_configuration.base_path, id=crate::apis::urlencode(id));
102 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
103
104 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
105 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106 }
107 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
108 let local_var_key = local_var_apikey.key.clone();
109 let local_var_value = match local_var_apikey.prefix {
110 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
111 None => local_var_key,
112 };
113 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
114 };
115 let mut local_var_form = reqwest::multipart::Form::new();
116 if let Some(local_var_param_value) = data {
117 local_var_form = local_var_form.text("data", local_var_param_value.to_string());
118 }
119 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
120
121 let local_var_req = local_var_req_builder.build()?;
122 let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124 let local_var_status = local_var_resp.status();
125 let local_var_content = local_var_resp.text().await?;
126
127 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
128 Ok(())
129 } else {
130 let local_var_entity: Option<AddFilesToVersionError> = serde_json::from_str(&local_var_content).ok();
131 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
132 Err(Error::ResponseError(local_var_error))
133 }
134}
135
136pub async fn create_version(configuration: &configuration::Configuration, data: models::CreatableVersion) -> Result<models::Version, Error<CreateVersionError>> {
138 let local_var_configuration = configuration;
139
140 let local_var_client = &local_var_configuration.client;
141
142 let local_var_uri_str = format!("{}/version", local_var_configuration.base_path);
143 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
149 let local_var_key = local_var_apikey.key.clone();
150 let local_var_value = match local_var_apikey.prefix {
151 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
152 None => local_var_key,
153 };
154 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
155 };
156 let mut local_var_form = reqwest::multipart::Form::new();
157 local_var_form = local_var_form.text("data", serde_json::to_string(&data)?);
158 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
159
160 let local_var_req = local_var_req_builder.build()?;
161 let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163 let local_var_status = local_var_resp.status();
164 let local_var_content = local_var_resp.text().await?;
165
166 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167 serde_json::from_str(&local_var_content).map_err(Error::from)
168 } else {
169 let local_var_entity: Option<CreateVersionError> = serde_json::from_str(&local_var_content).ok();
170 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
171 Err(Error::ResponseError(local_var_error))
172 }
173}
174
175pub async fn delete_version(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteVersionError>> {
176 let local_var_configuration = configuration;
177
178 let local_var_client = &local_var_configuration.client;
179
180 let local_var_uri_str = format!("{}/version/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
181 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
182
183 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
184 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
185 }
186 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
187 let local_var_key = local_var_apikey.key.clone();
188 let local_var_value = match local_var_apikey.prefix {
189 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
190 None => local_var_key,
191 };
192 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
193 };
194
195 let local_var_req = local_var_req_builder.build()?;
196 let local_var_resp = local_var_client.execute(local_var_req).await?;
197
198 let local_var_status = local_var_resp.status();
199 let local_var_content = local_var_resp.text().await?;
200
201 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
202 Ok(())
203 } else {
204 let local_var_entity: Option<DeleteVersionError> = serde_json::from_str(&local_var_content).ok();
205 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
206 Err(Error::ResponseError(local_var_error))
207 }
208}
209
210pub async fn get_project_versions(configuration: &configuration::Configuration, id_pipe_slug: &str, loaders: Option<&str>, game_versions: Option<&str>, featured: Option<bool>) -> Result<Vec<models::Version>, Error<GetProjectVersionsError>> {
211 let local_var_configuration = configuration;
212
213 let local_var_client = &local_var_configuration.client;
214
215 let local_var_uri_str = format!("{}/project/{term_1}/version", local_var_configuration.base_path, term_1=crate::apis::urlencode(id_pipe_slug));
216 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
217
218 if let Some(ref local_var_str) = loaders {
219 local_var_req_builder = local_var_req_builder.query(&[("loaders", &local_var_str.to_string())]);
220 }
221 if let Some(ref local_var_str) = game_versions {
222 local_var_req_builder = local_var_req_builder.query(&[("game_versions", &local_var_str.to_string())]);
223 }
224 if let Some(ref local_var_str) = featured {
225 local_var_req_builder = local_var_req_builder.query(&[("featured", &local_var_str.to_string())]);
226 }
227 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
228 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229 }
230
231 let local_var_req = local_var_req_builder.build()?;
232 let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234 let local_var_status = local_var_resp.status();
235 let local_var_content = local_var_resp.text().await?;
236
237 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238 serde_json::from_str(&local_var_content).map_err(Error::from)
239 } else {
240 let local_var_entity: Option<GetProjectVersionsError> = serde_json::from_str(&local_var_content).ok();
241 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
242 Err(Error::ResponseError(local_var_error))
243 }
244}
245
246pub async fn get_version(configuration: &configuration::Configuration, id: &str) -> Result<models::Version, Error<GetVersionError>> {
247 let local_var_configuration = configuration;
248
249 let local_var_client = &local_var_configuration.client;
250
251 let local_var_uri_str = format!("{}/version/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
252 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
253
254 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
255 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
256 }
257
258 let local_var_req = local_var_req_builder.build()?;
259 let local_var_resp = local_var_client.execute(local_var_req).await?;
260
261 let local_var_status = local_var_resp.status();
262 let local_var_content = local_var_resp.text().await?;
263
264 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
265 serde_json::from_str(&local_var_content).map_err(Error::from)
266 } else {
267 let local_var_entity: Option<GetVersionError> = serde_json::from_str(&local_var_content).ok();
268 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
269 Err(Error::ResponseError(local_var_error))
270 }
271}
272
273pub async fn get_version_from_id_or_number(configuration: &configuration::Configuration, id_pipe_slug: &str, id_pipe_number: &str) -> Result<models::Version, Error<GetVersionFromIdOrNumberError>> {
275 let local_var_configuration = configuration;
276
277 let local_var_client = &local_var_configuration.client;
278
279 let local_var_uri_str = format!("{}/project/{term_1}/version/{term_3}", local_var_configuration.base_path, term_1=crate::apis::urlencode(id_pipe_slug), term_3=crate::apis::urlencode(id_pipe_number));
280 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
281
282 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284 }
285
286 let local_var_req = local_var_req_builder.build()?;
287 let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289 let local_var_status = local_var_resp.status();
290 let local_var_content = local_var_resp.text().await?;
291
292 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293 serde_json::from_str(&local_var_content).map_err(Error::from)
294 } else {
295 let local_var_entity: Option<GetVersionFromIdOrNumberError> = serde_json::from_str(&local_var_content).ok();
296 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
297 Err(Error::ResponseError(local_var_error))
298 }
299}
300
301pub async fn get_versions(configuration: &configuration::Configuration, ids: &str) -> Result<Vec<models::Version>, Error<GetVersionsError>> {
302 let local_var_configuration = configuration;
303
304 let local_var_client = &local_var_configuration.client;
305
306 let local_var_uri_str = format!("{}/versions", local_var_configuration.base_path);
307 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
308
309 local_var_req_builder = local_var_req_builder.query(&[("ids", &ids.to_string())]);
310 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
311 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
312 }
313
314 let local_var_req = local_var_req_builder.build()?;
315 let local_var_resp = local_var_client.execute(local_var_req).await?;
316
317 let local_var_status = local_var_resp.status();
318 let local_var_content = local_var_resp.text().await?;
319
320 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321 serde_json::from_str(&local_var_content).map_err(Error::from)
322 } else {
323 let local_var_entity: Option<GetVersionsError> = serde_json::from_str(&local_var_content).ok();
324 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
325 Err(Error::ResponseError(local_var_error))
326 }
327}
328
329pub async fn modify_version(configuration: &configuration::Configuration, id: &str, editable_version: Option<models::EditableVersion>) -> Result<(), Error<ModifyVersionError>> {
330 let local_var_configuration = configuration;
331
332 let local_var_client = &local_var_configuration.client;
333
334 let local_var_uri_str = format!("{}/version/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
335 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
336
337 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
339 }
340 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
341 let local_var_key = local_var_apikey.key.clone();
342 let local_var_value = match local_var_apikey.prefix {
343 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
344 None => local_var_key,
345 };
346 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
347 };
348 local_var_req_builder = local_var_req_builder.json(&editable_version);
349
350 let local_var_req = local_var_req_builder.build()?;
351 let local_var_resp = local_var_client.execute(local_var_req).await?;
352
353 let local_var_status = local_var_resp.status();
354 let local_var_content = local_var_resp.text().await?;
355
356 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
357 Ok(())
358 } else {
359 let local_var_entity: Option<ModifyVersionError> = serde_json::from_str(&local_var_content).ok();
360 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
361 Err(Error::ResponseError(local_var_error))
362 }
363}
364
365pub async fn schedule_version(configuration: &configuration::Configuration, id: &str, schedule: Option<models::Schedule>) -> Result<(), Error<ScheduleVersionError>> {
366 let local_var_configuration = configuration;
367
368 let local_var_client = &local_var_configuration.client;
369
370 let local_var_uri_str = format!("{}/version/{id}/schedule", local_var_configuration.base_path, id=crate::apis::urlencode(id));
371 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
372
373 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
374 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
375 }
376 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
377 let local_var_key = local_var_apikey.key.clone();
378 let local_var_value = match local_var_apikey.prefix {
379 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
380 None => local_var_key,
381 };
382 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
383 };
384 local_var_req_builder = local_var_req_builder.json(&schedule);
385
386 let local_var_req = local_var_req_builder.build()?;
387 let local_var_resp = local_var_client.execute(local_var_req).await?;
388
389 let local_var_status = local_var_resp.status();
390 let local_var_content = local_var_resp.text().await?;
391
392 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
393 Ok(())
394 } else {
395 let local_var_entity: Option<ScheduleVersionError> = serde_json::from_str(&local_var_content).ok();
396 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
397 Err(Error::ResponseError(local_var_error))
398 }
399}
400