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
use super::Client;
// use std::borrow::Cow;
use serde_json;

// use prettytable::format;
// use prettytable::row::Row;
// use prettytable::cell::Cell;
// use std::io::Read;


#[derive(Clone, Debug, Deserialize)]
pub struct Project {
    pub url: String,
    pub description: Option<String>,
    pub name: String
}

// fn compile_filters(filters: Vec<&str>) -> Vec<String> {
//     filters
//         .iter()
//         .map(|x|{
//             let mut z = x.to_string();

//             if z.starts_with("name") {
//                 z = format!("jobFilter={}", z.split("=").collect::<Vec<&str>>()[1]);
//             } else if z.starts_with("group") {
//                 z = format!("groupPath={}", z.split("=").collect::<Vec<&str>>()[1]);
//             }

//             z
//         })
//         .collect::<Vec<String>>()
// }

#[derive(Clone)]
pub struct ProjectService<'a> {
    client: &'a Client<'a>
}

impl<'a> ProjectService<'a> {
    pub fn from_client(client: &'a Client) -> Result<Self, ()> 
    {
        Ok(Self {
            client
        })
    }

    pub fn list(&self) -> Vec<Project> {
        let mut filters: Vec<&str> = Vec::new();
        let ret = self.client.perform_get("projects", &mut filters);

        serde_json::from_str(&ret).unwrap()
    }
}