Skip to content

Commit

Permalink
Add /user endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
dpc committed Oct 15, 2017
1 parent adf34b2 commit 9b758ca
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ use hyper::mime::Mime;
use hyper::status::StatusCode;
use repositories::{Repository, Repositories, UserRepositories, OrganizationRepositories};
use organizations::{Organization, Organizations, UserOrganizations};
use users::Users;
use std::fmt;
use url::Url;
use std::collections::HashMap;
Expand Down Expand Up @@ -253,6 +254,13 @@ impl Github {
Organizations::new(self)
}

/// Return a reference to an interface that provides access
/// to user information.
pub fn users(&self) -> Users
{
Users::new(self)
}

/// Return a reference to the collection of organizations a user
/// is publicly associated with
pub fn user_orgs<U>(&self, user: U) -> UserOrganizations
Expand Down
58 changes: 58 additions & 0 deletions src/users/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Users interface
use {Github, Result};

/// User information
#[derive(Debug, Deserialize)]
pub struct User {
pub login: String,
Expand All @@ -20,3 +23,58 @@ pub struct User {
// type (keyword)
pub site_admin: bool,
}

/// Information about current authenticated user
#[derive(Debug, Deserialize)]
pub struct AuthenticatedUser {
pub login: String,
pub id: u64,
pub avatar_url: String,
pub gravatar_id: String,
pub url: String,
pub html_url: String,
pub followers_url: String,
pub following_url: String,
pub gists_url: String,
pub starred_url: String,
pub subscriptions_url: String,
pub organizations_url: String,
pub repos_url: String,
pub events_url: String,
pub received_events_url: String,
// type (keyword)
pub site_admin: bool,

// extend over `User`:
pub name: String,
pub company: String,
pub blog: String,
pub location: String,
pub email: String,
pub hireable: String,
pub bio: String,
pub public_repos: u64,
pub public_gists: u64,
pub followers: u64,
pub following: u64,
pub created_at: String, // TODO: change to `DateTime`?
pub updated_at: String, // TODO: change to `DateTime`?
}

/// Query user information
pub struct Users<'a> {
github: &'a Github,
}

impl<'a> Users<'a> {
pub fn new(github: &'a Github) -> Users<'a> {
Users {
github: github,
}
}

/// Information about current authenticated user
pub fn authenticated(&self) -> Result<AuthenticatedUser> {
self.github.get::<AuthenticatedUser>(&"/user")
}
}

0 comments on commit 9b758ca

Please sign in to comment.