gecko/
contract.rs

1//! # `/contract`
2//!
3//! - [/coins/{id}/contract/{contract_address}](Info)
4//! - [/coins/{id}/contract/{contract_address}/market_chart](MarketChart)
5//! - [/coins/{id}/contract/{contract_address}/market_chart/range](MarketChartRange)
6//!
7use crate::Route;
8
9pub struct Info {
10    endpoint: String,
11    pub id: String,
12    pub contract_address: String,
13}
14pub struct MarketChart {
15    endpoint: String,
16    pub id: String,
17    pub contract_address: String,
18    pub vs_currency: String,
19    pub days: String,
20}
21pub struct MarketChartRange {
22    endpoint: String,
23    pub id: String,
24    pub contract_address: String,
25    pub vs_currency: String,
26    pub from: i64,
27    pub to: i64,
28}
29
30impl Info {
31    pub fn required(id: String, contract_address: String) -> Info {
32        Info {
33            id,
34            contract_address,
35            ..Default::default()
36        }
37    }
38}
39impl MarketChart {
40    pub fn required(
41        id: String,
42        contract_address: String,
43        vs_currency: String,
44        days: String,
45    ) -> MarketChart {
46        MarketChart {
47            id,
48            contract_address,
49            vs_currency,
50            days,
51            ..Default::default()
52        }
53    }
54}
55impl MarketChartRange {
56    pub fn required(
57        id: String,
58        contract_address: String,
59        vs_currency: String,
60        from: i64,
61        to: i64,
62    ) -> MarketChartRange {
63        MarketChartRange {
64            id,
65            contract_address,
66            vs_currency,
67            from,
68            to,
69            ..Default::default()
70        }
71    }
72}
73
74impl Default for Info {
75    fn default() -> Info {
76        Info {
77            endpoint: String::from("/coins/ID/contract/CONTRACT"),
78            id: String::from(""),
79            contract_address: String::from(""),
80        }
81    }
82}
83impl Default for MarketChart {
84    fn default() -> MarketChart {
85        MarketChart {
86            endpoint: String::from("/coins/ID/contract/CONTRACT/market_chart"),
87            id: String::from(""),
88            contract_address: String::from(""),
89            vs_currency: String::from(""),
90            days: String::from(""),
91        }
92    }
93}
94impl Default for MarketChartRange {
95    fn default() -> MarketChartRange {
96        MarketChartRange {
97            endpoint: String::from("/coins/ID/contract/CONTRACT/market_chart/range"),
98            id: String::from(""),
99            contract_address: String::from(""),
100            vs_currency: String::from(""),
101            from: 0,
102            to: 0,
103        }
104    }
105}
106
107impl Route for Info {
108    fn api_endpoint(&self) -> String {
109        let endpoint = self
110            .endpoint
111            .replace("ID", &(self.id))
112            .replace("CONTRACT", &(self.contract_address));
113        format!("{}", endpoint)
114    }
115    fn query_string(&self) -> String {
116        String::from("")
117    }
118}
119impl Route for MarketChart {
120    fn api_endpoint(&self) -> String {
121        let endpoint = self
122            .endpoint
123            .replace("ID", &(self.id))
124            .replace("CONTRACT", &(self.contract_address));
125        format!("{}", endpoint)
126    }
127    fn query_string(&self) -> String {
128        let default: MarketChart = Default::default();
129        let vs_currency = self.format_query(
130            "vs_currency".to_string(),
131            &(self.vs_currency),
132            &(default.vs_currency),
133        );
134        let days = self.format_query("days".to_string(), &(self.days), &(default.days));
135        let optional = vec![vs_currency, days];
136        self.collect_query_params(optional)
137    }
138}
139impl Route for MarketChartRange {
140    fn api_endpoint(&self) -> String {
141        let endpoint = self
142            .endpoint
143            .replace("ID", &(self.id))
144            .replace("CONTRACT", &(self.contract_address));
145        format!("{}", endpoint)
146    }
147    fn query_string(&self) -> String {
148        let default: MarketChartRange = Default::default();
149        let vs_currency = self.format_query(
150            "vs_currency".to_string(),
151            &(self.vs_currency),
152            &(default.vs_currency),
153        );
154        let from = self.format_query("from".to_string(), self.from, default.from);
155        let to = self.format_query("to".to_string(), self.to, default.to);
156        let optional = vec![vs_currency, from, to];
157        self.collect_query_params(optional)
158    }
159}