1pub(crate) mod gecko {
2
3 use crate::types::Response;
4 use serde::de::DeserializeOwned;
5
6 const ORIGIN: &str = "https://api.coingecko.com/api/v3";
7
8 pub fn vec_str_2_comma_str(vector: Vec<&str>) -> String {
9 let vec_len = vector.len();
10 let mut i = 0;
11 let mut vector_str = String::new();
12
13 for item in vector {
14 i += 1;
15 vector_str.push_str(item);
16 if i < vec_len {
17 vector_str.push_str(",");
18 }
19 }
20 vector_str
21 }
22
23 pub fn get_request<T: DeserializeOwned>(endpoint: &str, params: &str) -> Response<T> {
24 let url = [ORIGIN, endpoint, params].join("");
25 dbg!("{}", &url);
26 let resp = reqwest::blocking::get(url);
27
28 match resp {
29 Ok(res) => {
30 let status = res.status();
31 let payload = res.json::<T>(); match payload {
34 Ok(json) => Response {
35 is_success: true,
36 status: status,
37 json: Some(json),
38 error: None,
39 },
40
41 Err(e) => Response {
42 is_success: false,
43 status: status,
44 json: None,
45 error: Some(e),
46 },
47 }
48 }
49 Err(e) => Response {
50 is_success: false,
51 status: reqwest::StatusCode::EXPECTATION_FAILED,
52 json: None,
53 error: Some(e),
54 },
55 }
56 }
57
58 pub fn append_if(
59 params: &str,
60 check: bool,
61 append_true: Option<&str>,
62 append_false: Option<&str>,
63 ) -> String {
64 let mut output = params.to_string();
65 if check {
66 if !append_true.is_none() {
67 output = [params, append_true.unwrap()].join("&");
68 }
69 } else {
70 if !append_false.is_none() {
71 output = [params, append_false.unwrap()].join("&");
72 }
73 }
74 output
75 }
76}
77
78pub mod asset_platforms;
79pub mod categories;
80pub mod coins;
81pub mod companies;
82pub mod contract;
83pub mod derivatives;
84pub mod exchange_rates;
85pub mod exchanges;
86pub mod global;
87pub mod indexes;
88pub mod search;
89pub mod server;
90pub mod simple;
91pub mod trending;
92pub mod types;
93
94mod macros;