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
use self::super::{Github, Result};
use rep::Org;

pub struct Organizations<'a> {
    github: &'a Github<'a>,
}

impl<'a> Organizations<'a> {
    pub fn new(github: &'a Github<'a>) -> Organizations<'a> {
        Organizations { github: 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) -> Result<Vec<Org>> {
        self.github.get::<Vec<Org>>(&self.path(""))
    }
}

pub struct UserOrganizations<'a> {
    github: &'a Github<'a>,
    user: String,
}

impl<'a> UserOrganizations<'a> {
    pub fn new<U>(github: &'a Github<'a>, user: U) -> UserOrganizations<'a>
        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) -> Result<Vec<Org>> {
        self.github.get::<Vec<Org>>(&self.path(""))
    }
}