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 ChangeUserIconError {
22 Status400(models::InvalidInputError),
23 Status404(),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetFollowedProjectsError {
31 Status401(models::AuthError),
32 Status404(),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetPayoutHistoryError {
40 Status401(models::AuthError),
41 Status404(),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetUserError {
49 Status404(),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetUserFromAuthError {
57 Status401(models::AuthError),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetUserProjectsError {
65 Status404(),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetUsersError {
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ModifyUserError {
80 Status401(models::AuthError),
81 Status404(),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum WithdrawPayoutError {
89 Status401(models::AuthError),
90 Status404(),
91 UnknownValue(serde_json::Value),
92}
93
94
95pub async fn change_user_icon(configuration: &configuration::Configuration, id_pipe_username: &str, body: Option<std::path::PathBuf>) -> Result<(), Error<ChangeUserIconError>> {
97 let local_var_configuration = configuration;
98
99 let local_var_client = &local_var_configuration.client;
100
101 let local_var_uri_str = format!("{}/user/{term_2}/icon", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
102 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, 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 local_var_req_builder = local_var_req_builder.json(&body);
116
117 let local_var_req = local_var_req_builder.build()?;
118 let local_var_resp = local_var_client.execute(local_var_req).await?;
119
120 let local_var_status = local_var_resp.status();
121 let local_var_content = local_var_resp.text().await?;
122
123 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124 Ok(())
125 } else {
126 let local_var_entity: Option<ChangeUserIconError> = serde_json::from_str(&local_var_content).ok();
127 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
128 Err(Error::ResponseError(local_var_error))
129 }
130}
131
132pub async fn get_followed_projects(configuration: &configuration::Configuration, id_pipe_username: &str) -> Result<Vec<models::Project>, Error<GetFollowedProjectsError>> {
133 let local_var_configuration = configuration;
134
135 let local_var_client = &local_var_configuration.client;
136
137 let local_var_uri_str = format!("{}/user/{term_2}/follows", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
138 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
139
140 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
141 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
142 }
143 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
144 let local_var_key = local_var_apikey.key.clone();
145 let local_var_value = match local_var_apikey.prefix {
146 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
147 None => local_var_key,
148 };
149 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
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<GetFollowedProjectsError> = serde_json::from_str(&local_var_content).ok();
162 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163 Err(Error::ResponseError(local_var_error))
164 }
165}
166
167pub async fn get_payout_history(configuration: &configuration::Configuration, id_pipe_username: &str) -> Result<models::UserPayoutHistory, Error<GetPayoutHistoryError>> {
168 let local_var_configuration = configuration;
169
170 let local_var_client = &local_var_configuration.client;
171
172 let local_var_uri_str = format!("{}/user/{term_2}/payouts", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
173 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
174
175 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
176 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
177 }
178 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
179 let local_var_key = local_var_apikey.key.clone();
180 let local_var_value = match local_var_apikey.prefix {
181 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
182 None => local_var_key,
183 };
184 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
185 };
186
187 let local_var_req = local_var_req_builder.build()?;
188 let local_var_resp = local_var_client.execute(local_var_req).await?;
189
190 let local_var_status = local_var_resp.status();
191 let local_var_content = local_var_resp.text().await?;
192
193 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194 serde_json::from_str(&local_var_content).map_err(Error::from)
195 } else {
196 let local_var_entity: Option<GetPayoutHistoryError> = serde_json::from_str(&local_var_content).ok();
197 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
198 Err(Error::ResponseError(local_var_error))
199 }
200}
201
202pub async fn get_user(configuration: &configuration::Configuration, id_pipe_username: &str) -> Result<models::User, Error<GetUserError>> {
203 let local_var_configuration = configuration;
204
205 let local_var_client = &local_var_configuration.client;
206
207 let local_var_uri_str = format!("{}/user/{term_2}", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
208 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
209
210 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
211 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
212 }
213
214 let local_var_req = local_var_req_builder.build()?;
215 let local_var_resp = local_var_client.execute(local_var_req).await?;
216
217 let local_var_status = local_var_resp.status();
218 let local_var_content = local_var_resp.text().await?;
219
220 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221 serde_json::from_str(&local_var_content).map_err(Error::from)
222 } else {
223 let local_var_entity: Option<GetUserError> = serde_json::from_str(&local_var_content).ok();
224 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
225 Err(Error::ResponseError(local_var_error))
226 }
227}
228
229pub async fn get_user_from_auth(configuration: &configuration::Configuration, ) -> Result<models::User, Error<GetUserFromAuthError>> {
230 let local_var_configuration = configuration;
231
232 let local_var_client = &local_var_configuration.client;
233
234 let local_var_uri_str = format!("{}/user", local_var_configuration.base_path);
235 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
236
237 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
238 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
239 }
240 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
241 let local_var_key = local_var_apikey.key.clone();
242 let local_var_value = match local_var_apikey.prefix {
243 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
244 None => local_var_key,
245 };
246 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
247 };
248
249 let local_var_req = local_var_req_builder.build()?;
250 let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252 let local_var_status = local_var_resp.status();
253 let local_var_content = local_var_resp.text().await?;
254
255 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
256 serde_json::from_str(&local_var_content).map_err(Error::from)
257 } else {
258 let local_var_entity: Option<GetUserFromAuthError> = serde_json::from_str(&local_var_content).ok();
259 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
260 Err(Error::ResponseError(local_var_error))
261 }
262}
263
264pub async fn get_user_projects(configuration: &configuration::Configuration, id_pipe_username: &str) -> Result<Vec<models::Project>, Error<GetUserProjectsError>> {
265 let local_var_configuration = configuration;
266
267 let local_var_client = &local_var_configuration.client;
268
269 let local_var_uri_str = format!("{}/user/{term_2}/projects", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
270 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
271
272 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
273 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274 }
275
276 let local_var_req = local_var_req_builder.build()?;
277 let local_var_resp = local_var_client.execute(local_var_req).await?;
278
279 let local_var_status = local_var_resp.status();
280 let local_var_content = local_var_resp.text().await?;
281
282 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
283 serde_json::from_str(&local_var_content).map_err(Error::from)
284 } else {
285 let local_var_entity: Option<GetUserProjectsError> = serde_json::from_str(&local_var_content).ok();
286 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
287 Err(Error::ResponseError(local_var_error))
288 }
289}
290
291pub async fn get_users(configuration: &configuration::Configuration, ids: &str) -> Result<Vec<models::User>, Error<GetUsersError>> {
292 let local_var_configuration = configuration;
293
294 let local_var_client = &local_var_configuration.client;
295
296 let local_var_uri_str = format!("{}/users", local_var_configuration.base_path);
297 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
298
299 local_var_req_builder = local_var_req_builder.query(&[("ids", &ids.to_string())]);
300 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
301 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302 }
303
304 let local_var_req = local_var_req_builder.build()?;
305 let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307 let local_var_status = local_var_resp.status();
308 let local_var_content = local_var_resp.text().await?;
309
310 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
311 serde_json::from_str(&local_var_content).map_err(Error::from)
312 } else {
313 let local_var_entity: Option<GetUsersError> = serde_json::from_str(&local_var_content).ok();
314 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
315 Err(Error::ResponseError(local_var_error))
316 }
317}
318
319pub async fn modify_user(configuration: &configuration::Configuration, id_pipe_username: &str, editable_user: Option<models::EditableUser>) -> Result<(), Error<ModifyUserError>> {
320 let local_var_configuration = configuration;
321
322 let local_var_client = &local_var_configuration.client;
323
324 let local_var_uri_str = format!("{}/user/{term_2}", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
325 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
326
327 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
328 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
329 }
330 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
331 let local_var_key = local_var_apikey.key.clone();
332 let local_var_value = match local_var_apikey.prefix {
333 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
334 None => local_var_key,
335 };
336 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
337 };
338 local_var_req_builder = local_var_req_builder.json(&editable_user);
339
340 let local_var_req = local_var_req_builder.build()?;
341 let local_var_resp = local_var_client.execute(local_var_req).await?;
342
343 let local_var_status = local_var_resp.status();
344 let local_var_content = local_var_resp.text().await?;
345
346 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
347 Ok(())
348 } else {
349 let local_var_entity: Option<ModifyUserError> = serde_json::from_str(&local_var_content).ok();
350 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
351 Err(Error::ResponseError(local_var_error))
352 }
353}
354
355pub async fn withdraw_payout(configuration: &configuration::Configuration, id_pipe_username: &str, amount: i32) -> Result<(), Error<WithdrawPayoutError>> {
357 let local_var_configuration = configuration;
358
359 let local_var_client = &local_var_configuration.client;
360
361 let local_var_uri_str = format!("{}/user/{term_2}/payouts", local_var_configuration.base_path, term_2=crate::apis::urlencode(id_pipe_username));
362 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
363
364 local_var_req_builder = local_var_req_builder.query(&[("amount", &amount.to_string())]);
365 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
366 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
367 }
368 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
369 let local_var_key = local_var_apikey.key.clone();
370 let local_var_value = match local_var_apikey.prefix {
371 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
372 None => local_var_key,
373 };
374 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
375 };
376
377 let local_var_req = local_var_req_builder.build()?;
378 let local_var_resp = local_var_client.execute(local_var_req).await?;
379
380 let local_var_status = local_var_resp.status();
381 let local_var_content = local_var_resp.text().await?;
382
383 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
384 Ok(())
385 } else {
386 let local_var_entity: Option<WithdrawPayoutError> = serde_json::from_str(&local_var_content).ok();
387 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
388 Err(Error::ResponseError(local_var_error))
389 }
390}
391