1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ChangePasswordError {
20 Status400(models::ClerkErrors),
21 Status403(models::ClerkErrors),
22 Status422(models::ClerkErrors),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateServiceTokenError {
30 Status403(models::ClerkErrors),
31 Status404(models::ClerkErrors),
32 Status422(models::ClerkErrors),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteProfileImageError {
40 Status401(models::ClerkErrors),
41 Status404(models::ClerkErrors),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum DeleteUserError {
49 Status401(models::ClerkErrors),
50 Status403(models::ClerkErrors),
51 Status404(models::ClerkErrors),
52 Status500(models::ClerkErrors),
53 UnknownValue(serde_json::Value),
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetUserError {
60 Status401(models::ClerkErrors),
61 Status403(models::ClerkErrors),
62 Status404(models::ClerkErrors),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum PatchUserError {
70 Status400(models::ClerkErrors),
71 Status401(models::ClerkErrors),
72 Status403(models::ClerkErrors),
73 Status404(models::ClerkErrors),
74 Status422(models::ClerkErrors),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum RemovePasswordError {
82 Status400(models::ClerkErrors),
83 Status422(models::ClerkErrors),
84 UnknownValue(serde_json::Value),
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UpdateProfileImageError {
91 Status400(models::ClerkErrors),
92 Status401(models::ClerkErrors),
93 Status422(models::ClerkErrors),
94 UnknownValue(serde_json::Value),
95}
96
97pub async fn change_password(
99 configuration: &configuration::Configuration,
100 current_password: Option<&str>,
101 new_password: Option<&str>,
102 sign_out_of_other_sessions: Option<bool>,
103) -> Result<models::SchemasClientClientWrappedUser, Error<ChangePasswordError>> {
104 let p_form_current_password = current_password;
106 let p_form_new_password = new_password;
107 let p_form_sign_out_of_other_sessions = sign_out_of_other_sessions;
108
109 let uri_str = format!("{}/v1/me/change_password", configuration.base_path);
110 let mut req_builder = configuration
111 .client
112 .request(reqwest::Method::POST, &uri_str);
113
114 if let Some(ref apikey) = configuration.api_key {
115 let key = apikey.key.clone();
116 let value = match apikey.prefix {
117 Some(ref prefix) => format!("{prefix} {key}"),
118 None => key,
119 };
120 req_builder = req_builder.query(&[("__dev_session", value)]);
121 }
122 if let Some(ref user_agent) = configuration.user_agent {
123 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124 }
125 if let Some(ref apikey) = configuration.api_key {
126 let key = apikey.key.clone();
127 let value = match apikey.prefix {
128 Some(ref prefix) => format!("{prefix} {key}"),
129 None => key,
130 };
131 req_builder = req_builder.header("__session", value);
132 };
133 let mut multipart_form_params = std::collections::HashMap::new();
134 if let Some(param_value) = p_form_current_password {
135 multipart_form_params.insert("current_password", param_value.to_string());
136 }
137 if let Some(param_value) = p_form_new_password {
138 multipart_form_params.insert("new_password", param_value.to_string());
139 }
140 if let Some(param_value) = p_form_sign_out_of_other_sessions {
141 multipart_form_params.insert("sign_out_of_other_sessions", param_value.to_string());
142 }
143 req_builder = req_builder.form(&multipart_form_params);
144
145 let req = req_builder.build()?;
146 let resp = configuration.client.execute(req).await?;
147
148 let status = resp.status();
149 let content_type = resp
150 .headers()
151 .get("content-type")
152 .and_then(|v| v.to_str().ok())
153 .unwrap_or("application/octet-stream");
154 let content_type = super::ContentType::from(content_type);
155
156 if !status.is_client_error() && !status.is_server_error() {
157 let content = resp.text().await?;
158 match content_type {
159 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
160 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchemasClientClientWrappedUser`"))),
161 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SchemasClientClientWrappedUser`")))),
162 }
163 } else {
164 let content = resp.text().await?;
165 let entity: Option<ChangePasswordError> = serde_json::from_str(&content).ok();
166 Err(Error::ResponseError(ResponseContent {
167 status,
168 content,
169 entity,
170 }))
171 }
172}
173
174pub async fn create_service_token(
176 configuration: &configuration::Configuration,
177 service: &str,
178 _clerk_session_id: Option<&str>,
179) -> Result<models::Token, Error<CreateServiceTokenError>> {
180 let p_form_service = service;
182 let p_query_clerk_session_id = _clerk_session_id;
183
184 let uri_str = format!("{}/v1/me/tokens", configuration.base_path);
185 let mut req_builder = configuration
186 .client
187 .request(reqwest::Method::POST, &uri_str);
188
189 if let Some(ref param_value) = p_query_clerk_session_id {
190 req_builder = req_builder.query(&[("_clerk_session_id", ¶m_value.to_string())]);
191 }
192 if let Some(ref apikey) = configuration.api_key {
193 let key = apikey.key.clone();
194 let value = match apikey.prefix {
195 Some(ref prefix) => format!("{prefix} {key}"),
196 None => key,
197 };
198 req_builder = req_builder.query(&[("__dev_session", value)]);
199 }
200 if let Some(ref user_agent) = configuration.user_agent {
201 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202 }
203 if let Some(ref apikey) = configuration.api_key {
204 let key = apikey.key.clone();
205 let value = match apikey.prefix {
206 Some(ref prefix) => format!("{prefix} {key}"),
207 None => key,
208 };
209 req_builder = req_builder.header("__session", value);
210 };
211 let mut multipart_form_params = std::collections::HashMap::new();
212 multipart_form_params.insert("service", p_form_service.to_string());
213 req_builder = req_builder.form(&multipart_form_params);
214
215 let req = req_builder.build()?;
216 let resp = configuration.client.execute(req).await?;
217
218 let status = resp.status();
219 let content_type = resp
220 .headers()
221 .get("content-type")
222 .and_then(|v| v.to_str().ok())
223 .unwrap_or("application/octet-stream");
224 let content_type = super::ContentType::from(content_type);
225
226 if !status.is_client_error() && !status.is_server_error() {
227 let content = resp.text().await?;
228 match content_type {
229 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
230 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))),
231 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Token`")))),
232 }
233 } else {
234 let content = resp.text().await?;
235 let entity: Option<CreateServiceTokenError> = serde_json::from_str(&content).ok();
236 Err(Error::ResponseError(ResponseContent {
237 status,
238 content,
239 entity,
240 }))
241 }
242}
243
244pub async fn delete_profile_image(
246 configuration: &configuration::Configuration,
247) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteProfileImageError>> {
248 let uri_str = format!("{}/v1/me/profile_image", configuration.base_path);
249 let mut req_builder = configuration
250 .client
251 .request(reqwest::Method::DELETE, &uri_str);
252
253 if let Some(ref apikey) = configuration.api_key {
254 let key = apikey.key.clone();
255 let value = match apikey.prefix {
256 Some(ref prefix) => format!("{prefix} {key}"),
257 None => key,
258 };
259 req_builder = req_builder.query(&[("__dev_session", value)]);
260 }
261 if let Some(ref user_agent) = configuration.user_agent {
262 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263 }
264 if let Some(ref apikey) = configuration.api_key {
265 let key = apikey.key.clone();
266 let value = match apikey.prefix {
267 Some(ref prefix) => format!("{prefix} {key}"),
268 None => key,
269 };
270 req_builder = req_builder.header("__session", value);
271 };
272
273 let req = req_builder.build()?;
274 let resp = configuration.client.execute(req).await?;
275
276 let status = resp.status();
277 let content_type = resp
278 .headers()
279 .get("content-type")
280 .and_then(|v| v.to_str().ok())
281 .unwrap_or("application/octet-stream");
282 let content_type = super::ContentType::from(content_type);
283
284 if !status.is_client_error() && !status.is_server_error() {
285 let content = resp.text().await?;
286 match content_type {
287 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
288 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
289 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
290 }
291 } else {
292 let content = resp.text().await?;
293 let entity: Option<DeleteProfileImageError> = serde_json::from_str(&content).ok();
294 Err(Error::ResponseError(ResponseContent {
295 status,
296 content,
297 entity,
298 }))
299 }
300}
301
302pub async fn delete_user(
304 configuration: &configuration::Configuration,
305) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteUserError>> {
306 let uri_str = format!("{}/v1/me", configuration.base_path);
307 let mut req_builder = configuration
308 .client
309 .request(reqwest::Method::DELETE, &uri_str);
310
311 if let Some(ref apikey) = configuration.api_key {
312 let key = apikey.key.clone();
313 let value = match apikey.prefix {
314 Some(ref prefix) => format!("{prefix} {key}"),
315 None => key,
316 };
317 req_builder = req_builder.query(&[("__dev_session", value)]);
318 }
319 if let Some(ref user_agent) = configuration.user_agent {
320 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
321 }
322 if let Some(ref apikey) = configuration.api_key {
323 let key = apikey.key.clone();
324 let value = match apikey.prefix {
325 Some(ref prefix) => format!("{prefix} {key}"),
326 None => key,
327 };
328 req_builder = req_builder.header("__session", value);
329 };
330
331 let req = req_builder.build()?;
332 let resp = configuration.client.execute(req).await?;
333
334 let status = resp.status();
335 let content_type = resp
336 .headers()
337 .get("content-type")
338 .and_then(|v| v.to_str().ok())
339 .unwrap_or("application/octet-stream");
340 let content_type = super::ContentType::from(content_type);
341
342 if !status.is_client_error() && !status.is_server_error() {
343 let content = resp.text().await?;
344 match content_type {
345 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
346 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
347 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
348 }
349 } else {
350 let content = resp.text().await?;
351 let entity: Option<DeleteUserError> = serde_json::from_str(&content).ok();
352 Err(Error::ResponseError(ResponseContent {
353 status,
354 content,
355 entity,
356 }))
357 }
358}
359
360pub async fn get_user(
362 configuration: &configuration::Configuration,
363) -> Result<models::ClientClientWrappedUser, Error<GetUserError>> {
364 let uri_str = format!("{}/v1/me", configuration.base_path);
365 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
366
367 if let Some(ref apikey) = configuration.api_key {
368 let key = apikey.key.clone();
369 let value = match apikey.prefix {
370 Some(ref prefix) => format!("{prefix} {key}"),
371 None => key,
372 };
373 req_builder = req_builder.query(&[("__dev_session", value)]);
374 }
375 if let Some(ref user_agent) = configuration.user_agent {
376 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
377 }
378 if let Some(ref apikey) = configuration.api_key {
379 let key = apikey.key.clone();
380 let value = match apikey.prefix {
381 Some(ref prefix) => format!("{prefix} {key}"),
382 None => key,
383 };
384 req_builder = req_builder.header("__session", value);
385 };
386
387 let req = req_builder.build()?;
388 let resp = configuration.client.execute(req).await?;
389
390 let status = resp.status();
391 let content_type = resp
392 .headers()
393 .get("content-type")
394 .and_then(|v| v.to_str().ok())
395 .unwrap_or("application/octet-stream");
396 let content_type = super::ContentType::from(content_type);
397
398 if !status.is_client_error() && !status.is_server_error() {
399 let content = resp.text().await?;
400 match content_type {
401 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
402 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedUser`"))),
403 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedUser`")))),
404 }
405 } else {
406 let content = resp.text().await?;
407 let entity: Option<GetUserError> = serde_json::from_str(&content).ok();
408 Err(Error::ResponseError(ResponseContent {
409 status,
410 content,
411 entity,
412 }))
413 }
414}
415
416pub async fn patch_user(
418 configuration: &configuration::Configuration,
419 username: Option<&str>,
420 first_name: Option<&str>,
421 last_name: Option<&str>,
422 primary_email_address_id: Option<&str>,
423 primary_phone_number_id: Option<&str>,
424 primary_web3_wallet_id: Option<&str>,
425 unsafe_metadata: Option<&str>,
426) -> Result<models::ClientClientWrappedUser, Error<PatchUserError>> {
427 let p_form_username = username;
429 let p_form_first_name = first_name;
430 let p_form_last_name = last_name;
431 let p_form_primary_email_address_id = primary_email_address_id;
432 let p_form_primary_phone_number_id = primary_phone_number_id;
433 let p_form_primary_web3_wallet_id = primary_web3_wallet_id;
434 let p_form_unsafe_metadata = unsafe_metadata;
435
436 let uri_str = format!("{}/v1/me", configuration.base_path);
437 let mut req_builder = configuration
438 .client
439 .request(reqwest::Method::PATCH, &uri_str);
440
441 if let Some(ref apikey) = configuration.api_key {
442 let key = apikey.key.clone();
443 let value = match apikey.prefix {
444 Some(ref prefix) => format!("{prefix} {key}"),
445 None => key,
446 };
447 req_builder = req_builder.query(&[("__dev_session", value)]);
448 }
449 if let Some(ref user_agent) = configuration.user_agent {
450 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
451 }
452 if let Some(ref apikey) = configuration.api_key {
453 let key = apikey.key.clone();
454 let value = match apikey.prefix {
455 Some(ref prefix) => format!("{prefix} {key}"),
456 None => key,
457 };
458 req_builder = req_builder.header("__session", value);
459 };
460 let mut multipart_form_params = std::collections::HashMap::new();
461 if let Some(param_value) = p_form_username {
462 multipart_form_params.insert("username", param_value.to_string());
463 }
464 if let Some(param_value) = p_form_first_name {
465 multipart_form_params.insert("first_name", param_value.to_string());
466 }
467 if let Some(param_value) = p_form_last_name {
468 multipart_form_params.insert("last_name", param_value.to_string());
469 }
470 if let Some(param_value) = p_form_primary_email_address_id {
471 multipart_form_params.insert("primary_email_address_id", param_value.to_string());
472 }
473 if let Some(param_value) = p_form_primary_phone_number_id {
474 multipart_form_params.insert("primary_phone_number_id", param_value.to_string());
475 }
476 if let Some(param_value) = p_form_primary_web3_wallet_id {
477 multipart_form_params.insert("primary_web3_wallet_id", param_value.to_string());
478 }
479 if let Some(param_value) = p_form_unsafe_metadata {
480 multipart_form_params.insert("unsafe_metadata", param_value.to_string());
481 }
482 req_builder = req_builder.form(&multipart_form_params);
483
484 let req = req_builder.build()?;
485 let resp = configuration.client.execute(req).await?;
486
487 let status = resp.status();
488 let content_type = resp
489 .headers()
490 .get("content-type")
491 .and_then(|v| v.to_str().ok())
492 .unwrap_or("application/octet-stream");
493 let content_type = super::ContentType::from(content_type);
494
495 if !status.is_client_error() && !status.is_server_error() {
496 let content = resp.text().await?;
497 match content_type {
498 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
499 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedUser`"))),
500 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedUser`")))),
501 }
502 } else {
503 let content = resp.text().await?;
504 let entity: Option<PatchUserError> = serde_json::from_str(&content).ok();
505 Err(Error::ResponseError(ResponseContent {
506 status,
507 content,
508 entity,
509 }))
510 }
511}
512
513pub async fn remove_password(
515 configuration: &configuration::Configuration,
516 current_password: Option<&str>,
517) -> Result<models::SchemasClientClientWrappedUser, Error<RemovePasswordError>> {
518 let p_form_current_password = current_password;
520
521 let uri_str = format!("{}/v1/me/remove_password", configuration.base_path);
522 let mut req_builder = configuration
523 .client
524 .request(reqwest::Method::POST, &uri_str);
525
526 if let Some(ref apikey) = configuration.api_key {
527 let key = apikey.key.clone();
528 let value = match apikey.prefix {
529 Some(ref prefix) => format!("{prefix} {key}"),
530 None => key,
531 };
532 req_builder = req_builder.query(&[("__dev_session", value)]);
533 }
534 if let Some(ref user_agent) = configuration.user_agent {
535 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
536 }
537 if let Some(ref apikey) = configuration.api_key {
538 let key = apikey.key.clone();
539 let value = match apikey.prefix {
540 Some(ref prefix) => format!("{prefix} {key}"),
541 None => key,
542 };
543 req_builder = req_builder.header("__session", value);
544 };
545 let mut multipart_form_params = std::collections::HashMap::new();
546 if let Some(param_value) = p_form_current_password {
547 multipart_form_params.insert("current_password", param_value.to_string());
548 }
549 req_builder = req_builder.form(&multipart_form_params);
550
551 let req = req_builder.build()?;
552 let resp = configuration.client.execute(req).await?;
553
554 let status = resp.status();
555 let content_type = resp
556 .headers()
557 .get("content-type")
558 .and_then(|v| v.to_str().ok())
559 .unwrap_or("application/octet-stream");
560 let content_type = super::ContentType::from(content_type);
561
562 if !status.is_client_error() && !status.is_server_error() {
563 let content = resp.text().await?;
564 match content_type {
565 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
566 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchemasClientClientWrappedUser`"))),
567 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SchemasClientClientWrappedUser`")))),
568 }
569 } else {
570 let content = resp.text().await?;
571 let entity: Option<RemovePasswordError> = serde_json::from_str(&content).ok();
572 Err(Error::ResponseError(ResponseContent {
573 status,
574 content,
575 entity,
576 }))
577 }
578}
579
580pub async fn update_profile_image(
582 configuration: &configuration::Configuration,
583 file: super::FileData,
584) -> Result<models::ClientClientWrappedImage, Error<UpdateProfileImageError>> {
585 let p_form_file = file;
587
588 let uri_str = format!("{}/v1/me/profile_image", configuration.base_path);
589 let mut req_builder = configuration
590 .client
591 .request(reqwest::Method::POST, &uri_str);
592
593 if let Some(ref apikey) = configuration.api_key {
594 let key = apikey.key.clone();
595 let value = match apikey.prefix {
596 Some(ref prefix) => format!("{prefix} {key}"),
597 None => key,
598 };
599 req_builder = req_builder.query(&[("__dev_session", value)]);
600 }
601 if let Some(ref user_agent) = configuration.user_agent {
602 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
603 }
604 if let Some(ref apikey) = configuration.api_key {
605 let key = apikey.key.clone();
606 let value = match apikey.prefix {
607 Some(ref prefix) => format!("{prefix} {key}"),
608 None => key,
609 };
610 req_builder = req_builder.header("__session", value);
611 };
612 let multipart_form = reqwest::multipart::Form::new().part(
613 "file",
614 reqwest::multipart::Part::bytes(p_form_file.data)
615 .file_name(p_form_file.name)
616 .mime_str(&p_form_file.mime_type)?,
617 );
618
619 req_builder = req_builder.multipart(multipart_form);
620
621 let req = req_builder.build()?;
622 let resp = configuration.client.execute(req).await?;
623
624 let status = resp.status();
625 let content_type = resp
626 .headers()
627 .get("content-type")
628 .and_then(|v| v.to_str().ok())
629 .unwrap_or("application/octet-stream");
630 let content_type = super::ContentType::from(content_type);
631
632 if !status.is_client_error() && !status.is_server_error() {
633 let content = resp.text().await?;
634 match content_type {
635 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
636 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedImage`"))),
637 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedImage`")))),
638 }
639 } else {
640 let content = resp.text().await?;
641 let entity: Option<UpdateProfileImageError> = serde_json::from_str(&content).ok();
642 Err(Error::ResponseError(ResponseContent {
643 status,
644 content,
645 entity,
646 }))
647 }
648}