Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /user endpoint support #90

Merged
merged 1 commit into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}