hubcaps_ex/
users.rs

1//! Users interface
2use crate::{Future, Github, Stream};
3use serde::{Deserialize, Serialize};
4
5/// User information
6#[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    // type (keyword)
24    pub site_admin: bool,
25}
26
27/// Information about current authenticated user
28#[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    // type (keyword)
46    pub site_admin: bool,
47
48    // extend over `User`:
49    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, // TODO: change to `DateTime`?
61    pub updated_at: String, // TODO: change to `DateTime`?
62}
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
72/// Query user information
73pub struct Users {
74    github: Github,
75}
76
77impl Users {
78    pub fn new(github: Github) -> Self {
79        Users { github }
80    }
81
82    /// Information about current authenticated user
83    pub fn authenticated(&self) -> Future<AuthenticatedUser> {
84        self.github.get("/user")
85    }
86
87    /// Get current authenticated user's email list
88    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
101/// reference to contributors associated with a github repo
102pub 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    /// list of contributors for this repo
123    pub fn list(&self) -> Future<Vec<User>> {
124        self.github
125            .get(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
126    }
127
128    /// provides a stream over all pages of teams
129    pub fn iter(&self) -> Stream<User> {
130        self.github
131            .get_stream(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
132    }
133}