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
use url::Url;

#[derive(Debug, Clone)]
pub struct RestPathBuilder {
    address: Url,
    root: String,
}

impl RestPathBuilder {
    pub fn new(address: Url) -> Self {
        RestPathBuilder {
            root: "api/v0/".to_string(),
            address,
        }
    }

    pub fn admin(self) -> Self {
        Self {
            address: self.address,
            root: self.root + "admin/",
        }
    }

    pub fn proposals(&self) -> String {
        self.path("proposals")
    }

    pub fn proposals_with_group(&self, group: &str) -> String {
        self.path(&format!("proposals/{}", group))
    }

    pub fn funds(&self) -> String {
        self.path("fund")
    }

    pub fn challenges(&self) -> String {
        self.path("challenges")
    }

    pub fn snapshot_info(&self, tag: &str) -> String {
        self.path(&format!("snapshot/snapshot_info/{}", tag))
    }

    pub fn raw_snapshot(&self, tag: &str) -> String {
        self.path(&format!("snapshot/raw_snapshot/{}", tag))
    }

    pub fn snapshot_tags(&self) -> String {
        self.path("snapshot")
    }

    pub fn snapshot_voter_info(&self, tag: &str, key: &str) -> String {
        self.path(&format!("snapshot/voter/{}/{}", tag, key))
    }

    pub fn snapshot_delegator_info(&self, tag: &str, key: &str) -> String {
        self.path(&format!("snapshot/delegator/{}/{}", tag, key))
    }

    pub fn proposal(&self, id: &str, group: &str) -> String {
        self.path(&format!("proposal/{}/{}", id, group))
    }

    pub fn fund(&self, id: &str) -> String {
        self.path(&format!("fund/{}", id))
    }

    pub fn advisor_reviews(&self, id: &str) -> String {
        self.path(&format!("reviews/{}", id))
    }

    pub fn genesis(&self) -> String {
        self.path("block0")
    }

    pub fn health(&self) -> String {
        self.path("health")
    }

    pub fn service_version(&self) -> String {
        format!("{}{}{}", self.address, "api/", "vit-version")
    }

    pub fn search(&self) -> String {
        self.path("search")
    }

    pub fn search_count(&self) -> String {
        self.path("search_count")
    }

    pub fn path(&self, path: &str) -> String {
        format!("{}{}{}", self.address, self.root, path)
    }
}