1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::errors::Result;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct User {
pub id: String,
pub resource: String,
pub resource_path: String,
pub name: Option<String>,
pub username: Option<String>,
pub profile_location: Option<String>,
pub profile_bio: Option<String>,
pub profile_url: Option<String>,
pub avatar_url: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Auth {
pub method: String,
pub scopes: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserUpdate<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub time_zone: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub native_currency: Option<&'a str>,
}
impl Client {
pub async fn get_user(&self, user_id: &str) -> Result<Response<User>> {
self.send_request(Method::GET, &format!("users/{}", user_id), None::<&()>)
.await
}
pub async fn get_current_user(&self) -> Result<Response<User>> {
self.send_request(Method::GET, "user", None::<&()>).await
}
pub async fn get_auth_info(&self) -> Result<Response<Auth>> {
self.send_request(Method::GET, "user/auth", None::<&()>)
.await
}
pub async fn update_user<'a>(&self, update: &'a UserUpdate<'a>) -> Result<Response<User>> {
self.send_request(Method::PUT, "user", Some(update)).await
}
}