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
use client;
use errors::*;
use reqwest::Method;

/// An organization
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct Organization {
    pub name: String,
}

#[cfg(test)]
mod tests {
    use organization::*;
    use serde_json;

    fn organization_example() -> Organization {
        Organization {
            name: "FooOrganization".to_string(),
        }
    }

    fn json_example() -> serde_json::Value {
        json!({
            "name": "FooOrganization"
        })
    }

    #[test]
    fn serialize_organization() {
        assert_eq!(
            json_example(),
            serde_json::to_value(&organization_example()).unwrap()
        );
    }

    #[test]
    fn deserialize_organization() {
        assert_eq!(
            organization_example(),
            serde_json::from_value(json_example()).unwrap()
        );
    }
}

impl client::Client {
    /// Retrieve the information on the organization.
    ///
    /// See https://mackerel.io/api-docs/entry/organizations#get.
    pub fn get_organization(&self) -> Result<Organization> {
        self.request(
            Method::GET,
            "/api/v0/org",
            vec![],
            client::empty_body(),
            |org| org,
        )
    }
}