1use crate::{Future, Github, Stream};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize)]
7pub struct User {
8 pub login: String,
9 pub id: u64,
10 pub avatar_url: String,
11 pub gravatar_id: String,
12 pub url: String,
13 pub html_url: String,
14 pub followers_url: String,
15 pub following_url: String,
16 pub gists_url: String,
17 pub starred_url: String,
18 pub subscriptions_url: String,
19 pub organizations_url: String,
20 pub repos_url: String,
21 pub events_url: String,
22 pub received_events_url: String,
23 pub site_admin: bool,
25}
26
27#[derive(Debug, Deserialize)]
29pub struct AuthenticatedUser {
30 pub login: String,
31 pub id: u64,
32 pub avatar_url: String,
33 pub gravatar_id: String,
34 pub url: String,
35 pub html_url: String,
36 pub followers_url: String,
37 pub following_url: String,
38 pub gists_url: String,
39 pub starred_url: String,
40 pub subscriptions_url: String,
41 pub organizations_url: String,
42 pub repos_url: String,
43 pub events_url: String,
44 pub received_events_url: String,
45 pub site_admin: bool,
47
48 pub name: Option<String>,
50 pub company: Option<String>,
51 pub blog: String,
52 pub location: Option<String>,
53 pub email: Option<String>,
54 pub hireable: Option<bool>,
55 pub bio: Option<String>,
56 pub public_repos: u64,
57 pub public_gists: u64,
58 pub followers: u64,
59 pub following: u64,
60 pub created_at: String, pub updated_at: String, }
63
64#[derive(Debug, Deserialize)]
65pub struct UserEmail {
66 pub email: String,
67 pub primary: bool,
68 pub verified: bool,
69 pub visibility: Option<String>,
70}
71
72pub struct Users {
74 github: Github,
75}
76
77impl Users {
78 pub fn new(github: Github) -> Self {
79 Users { github }
80 }
81
82 pub fn authenticated(&self) -> Future<AuthenticatedUser> {
84 self.github.get("/user")
85 }
86
87 pub fn authenticated_emails(&self) -> Future<Vec<UserEmail>> {
89 self.github.get("/user/emails")
90 }
91
92 pub fn get<U>(&self, username: U) -> Future<User>
93 where
94 U: Into<String>,
95 {
96 self.github
97 .get(&format!("/users/{username}", username = username.into()))
98 }
99}
100
101pub struct Contributors {
103 github: Github,
104 owner: String,
105 repo: String,
106}
107
108impl Contributors {
109 #[doc(hidden)]
110 pub fn new<O, R>(github: Github, owner: O, repo: R) -> Self
111 where
112 O: Into<String>,
113 R: Into<String>,
114 {
115 Contributors {
116 github,
117 owner: owner.into(),
118 repo: repo.into(),
119 }
120 }
121
122 pub fn list(&self) -> Future<Vec<User>> {
124 self.github
125 .get(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
126 }
127
128 pub fn iter(&self) -> Stream<User> {
130 self.github
131 .get_stream(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
132 }
133}