1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
//! Organizations interface

use hyper::client::Connect;

use {Github, Future};
use repositories::OrgRepositories;
use teams::OrgTeams;

/// Provides access to label operations available for an individual organization
pub struct Organization<C>
where
    C: Clone + Connect,
{
    github: Github<C>,
    org: String,
}

impl<C: Clone + Connect> Organization<C> {
    #[doc(hidden)]
    pub fn new<O>(github: Github<C>, org: O) -> Self
    where
        O: Into<String>,
    {
        Organization {
            github: github,
            org: org.into(),
        }
    }

    /// returns a reference to an interface for team operations
    pub fn teams(&self) -> OrgTeams<C> {
        OrgTeams::new(self.github.clone(), self.org.clone())
    }

    /// returns a reference to an interface for repo operations
    pub fn repos(&self) -> OrgRepositories<C> {
        OrgRepositories::new(self.github.clone(), self.org.clone())
    }
}


pub struct Organizations<C>
where
    C: Connect + Clone,
{
    github: Github<C>,
}

impl<C: Connect + Clone> Organizations<C> {
    #[doc(hidden)]
    pub fn new(github: Github<C>) -> Self {
        Self { github }
    }

    fn path(&self, more: &str) -> String {
        format!("/user/orgs{}", more)
    }

    /// list the authenticated user's organizations
    /// https://developer.github.com/v3/orgs/#list-your-organizations
    pub fn list(&self) -> Future<Vec<Org>> {
        self.github.get(&self.path(""))
    }
}

pub struct UserOrganizations<C>
where
    C: Clone + Connect,
{
    github: Github<C>,
    user: String,
}

impl<C: Clone + Connect> UserOrganizations<C> {
    pub fn new<U>(github: Github<C>, user: U) -> Self
    where
        U: Into<String>,
    {
        UserOrganizations {
            github: github,
            user: user.into(),
        }
    }

    fn path(&self, more: &str) -> String {
        format!("/users/{}/orgs{}", self.user, more)
    }

    /// list the organizations this user is publicly associated with
    /// https://developer.github.com/v3/orgs/#list-user-organizations
    pub fn list(&self) -> Future<Vec<Org>> {
        self.github.get(&self.path(""))
    }
}

// representations

#[derive(Debug, Deserialize)]
pub struct Org {
    pub login: String,
    pub id: u64,
    pub url: String,
    pub repos_url: String,
    pub events_url: String,
    pub hooks_url: String,
    pub issues_url: String,
    pub members_url: String,
    pub public_members_url: String,
    pub avatar_url: String,
    pub description: Option<String>,
}