use crate::{Future, Github, Stream};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
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,
pub site_admin: bool,
}
#[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,
pub site_admin: bool,
pub name: Option<String>,
pub company: Option<String>,
pub blog: String,
pub location: Option<String>,
pub email: Option<String>,
pub hireable: Option<bool>,
pub bio: Option<String>,
pub public_repos: u64,
pub public_gists: u64,
pub followers: u64,
pub following: u64,
pub created_at: String, pub updated_at: String, }
#[derive(Debug, Deserialize)]
pub struct UserEmail {
pub email: String,
pub primary: bool,
pub verified: bool,
pub visibility: Option<String>,
}
pub struct Users {
github: Github,
}
impl Users {
pub fn new(github: Github) -> Self {
Users { github }
}
pub fn authenticated(&self) -> Future<AuthenticatedUser> {
self.github.get("/user")
}
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>,
{
self.github
.get(&format!("/users/{username}", username = username.into()))
}
}
pub struct Contributors {
github: Github,
owner: String,
repo: String,
}
impl Contributors {
#[doc(hidden)]
pub fn new<O, R>(github: Github, owner: O, repo: R) -> Self
where
O: Into<String>,
R: Into<String>,
{
Contributors {
github,
owner: owner.into(),
repo: repo.into(),
}
}
pub fn list(&self) -> Future<Vec<User>> {
self.github
.get(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
}
pub fn iter(&self) -> Stream<User> {
self.github
.get_stream(&format!("/repos/{}/{}/contributors", self.owner, self.repo))
}
}