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
96
97
98
99
//! # `/indexes`
//!
//! - [/indexes](Indexes)
//! - [/indexes/{market_id}/{id}](Info)
//! - [/indexes/list](List)
//!
use crate::Route;

pub struct Indexes {
    endpoint: String,
    pub per_page: i32,
    pub page: i32,
}
pub struct Info {
    endpoint: String,
    pub id: String,
    pub market_id: String,
}
pub struct List {
    endpoint: String,
}

impl Indexes {
    pub fn required() -> Indexes {
        Indexes::default()
    }
}
impl Info {
    pub fn required(id: String, market_id: String) -> Info {
        Info {
            id,
            market_id,
            ..Default::default()
        }
    }
}
impl List {
    pub fn required() -> List {
        List::default()
    }
}

impl Default for Indexes {
    fn default() -> Indexes {
        Indexes {
            endpoint: String::from("/indexes"),
            per_page: 100,
            page: 1,
        }
    }
}
impl Default for Info {
    fn default() -> Info {
        Info {
            endpoint: String::from("/indexes/MARKET_ID/ID"),
            id: String::from(""),
            market_id: String::from(""),
        }
    }
}
impl Default for List {
    fn default() -> List {
        List {
            endpoint: String::from("/indexes/list"),
        }
    }
}
impl Route for Indexes {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        let default: Indexes = Default::default();
        let per_page = self.format_query("per_page".to_string(), self.per_page, default.per_page);
        let page = self.format_query("page".to_string(), self.page, default.page);
        let optional = vec![per_page, page];
        self.collect_query_params(optional)
    }
}
impl Route for Info {
    fn api_endpoint(&self) -> String {
        let endpoint = self
            .endpoint
            .replace("MARKET_ID", &(self.market_id))
            .replace("ID", &(self.id));
        format!("{}", endpoint)
    }
    fn query_string(&self) -> String {
        String::from("")
    }
}
impl Route for List {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        String::from("")
    }
}