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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use serde::Deserialize;
use crate::Result;
#[derive(Debug, Deserialize)]
pub struct User {
login: String,
id: u64,
node_id: String,
avatar_url: String,
gravatar_id: String,
html_url: String,
url: String,
followers_url: String,
following_url: String,
gists_url: String,
starred_url: String,
subscriptions_url: String,
organizations_url: String,
repos_url: String,
events_url: String,
received_events_url: String,
r#type: String,
site_admin: bool,
}
impl User {
pub async fn new(user: &str, user_agent: &str) -> Result<Self> {
const URL: &str = "https://api.github.com/users";
let url = format!("{}/{}", URL, user);
let user: User = reqwest::Client::builder()
.user_agent(user_agent)
.build()?
.get(&url)
.send()
.await?
.json()
.await?;
Ok(user)
}
pub fn login(&self) -> &str {
&self.login
}
pub fn id(&self) -> u64 {
self.id
}
pub fn node_id(&self) -> &str {
&self.node_id
}
pub fn avatar_url(&self) -> &str {
&self.avatar_url
}
pub fn gravatar_id(&self) -> &str {
&self.gravatar_id
}
pub fn html_url(&self) -> &str {
&self.html_url
}
pub fn url(&self) -> &str {
&self.url
}
pub fn followers_url(&self) -> &str {
&self.followers_url
}
pub fn following_url(&self) -> &str {
&self.following_url
}
pub fn gists_url(&self) -> &str {
&self.gists_url
}
pub fn starred_url(&self) -> &str {
&self.starred_url
}
pub fn subscriptions_url(&self) -> &str {
&self.subscriptions_url
}
pub fn organizations_url(&self) -> &str {
&self.organizations_url
}
pub fn repos_url(&self) -> &str {
&self.repos_url
}
pub fn events_url(&self) -> &str {
&self.events_url
}
pub fn received_events_url(&self) -> &str {
&self.received_events_url
}
pub fn r#type(&self) -> &str {
&self.r#type
}
pub fn site_admin(&self) -> bool {
self.site_admin
}
}