thrash/
project.rs

1use client::Client;
2use failure::Error;
3use std::fmt;
4
5#[derive(Deserialize, Serialize, Debug, PartialEq)]
6#[serde(rename_all = "camelCase")]
7pub struct Project {
8    key: String,
9    id: u64,
10    name: String,
11    description: Option<String>,
12    public: bool,
13    #[serde(rename = "type")]
14    _type: String,
15    //repositories: Vec<Repository>,
16    //auth: Authorization,
17}
18
19impl fmt::Display for Project {
20    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21        write!(f, "{} ({})", self.name, self.key)
22    }
23}
24
25#[derive(Deserialize, Serialize, Debug)]
26#[serde(rename_all = "camelCase")]
27pub struct ProjectRef {
28    pub key: String,
29}
30
31impl Client {
32    pub fn projects(&mut self) -> Result<Vec<Project>, Error> {
33        let url = "rest/api/1.0/projects";
34
35        self.get_paged(&url)
36    }
37
38    pub fn project(&mut self, project_key: &str) -> Result<Project, Error> {
39        let url = format!("rest/api/1.0/projects/{}", project_key);
40
41        self.get(&url)
42    }
43}
44
45impl Project {
46    pub fn name(&self) -> &str {
47        &self.name
48    }
49
50    pub fn key(&self) -> &str {
51        &self.key
52    }
53}