Skip to content

Commit

Permalink
add user emails struct and api to fetch them
Browse files Browse the repository at this point in the history
  • Loading branch information
dt665m committed Oct 5, 2020
1 parent 4f992af commit d11001b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/users.rs
Expand Up @@ -27,5 +27,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
Ok(user) => println!("{:#?}", user),
Err(err) => println!("err {:#?}", err),
}

match github.users().authenticated_emails().await {
Ok(emails) => println!("{:#?}", emails),
Err(err) => println!("err {:#?}", err),
}

Ok(())
}
12 changes: 12 additions & 0 deletions src/users.rs
Expand Up @@ -61,6 +61,13 @@ pub struct AuthenticatedUser {
pub updated_at: String, // TODO: change to `DateTime`?
}

#[derive(Debug, Deserialize)]
pub struct UserEmail {
pub email: String,
pub primary: bool,
pub verified: bool,
}

/// Query user information
pub struct Users {
github: Github,
Expand All @@ -76,6 +83,11 @@ impl Users {
self.github.get("/user")
}

/// Get current authenticated user's email list
pub fn authenticated_emails(&self) -> Future<Vec<UserEmail>> {
self.github.get("/user/emails")
}

pub fn get<U>(&self, username: U) -> Future<User>
where
U: Into<String>,
Expand Down

0 comments on commit d11001b

Please sign in to comment.