gecko 0.1.6

coin gecko api impl
Documentation
//! # `/derivatives`
//!
//! - [/derivatives](Derivatives)
//! - [/derivatives/exchanges](Exchanges)
//! - [/derivatives/exchanges/{id}](Info)
//! - [/derivatives/exchanges/list](List)
//!
use crate::Route;

pub struct Derivatives {
    endpoint: String,
    pub include_tickers: String, // 'all' or 'expired'
}
pub struct Exchanges {
    endpoint: String,
    pub order: String, // name_asc,name_desc,open_interest_btc_asc,open_interest_btc_desc,trade_volume_24h_btc_asc,trade_volume_24h_btc_desc
    pub per_page: i32,
    pub page: i32,
}
pub struct Info {
    endpoint: String,
    pub id: String,
    pub include_tickers: String, // 'all' or 'expired'
}
pub struct List {
    endpoint: String,
}

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

impl Default for Derivatives {
    fn default() -> Derivatives {
        Derivatives {
            endpoint: String::from("/derivatives"),
            include_tickers: String::from("unexpired"),
        }
    }
}
impl Default for Exchanges {
    fn default() -> Exchanges {
        Exchanges {
            endpoint: String::from("/derivatives/exchanges"),
            order: String::from("name_asc"), // guessed
            per_page: 100,
            page: 1,
        }
    }
}
impl Default for Info {
    fn default() -> Info {
        Info {
            endpoint: String::from("/derivatives/exchanges/ID"),
            id: String::from(""),
            include_tickers: String::from("unexpired"),
        }
    }
}
impl Default for List {
    fn default() -> List {
        List {
            endpoint: String::from("/derivatives/exchanges/list"),
        }
    }
}

impl Route for Derivatives {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        let default: Derivatives = Default::default();
        let include_tickers = self.format_query(
            "include_tickers".to_string(),
            &(self.include_tickers),
            &(default.include_tickers),
        );
        let optional = vec![include_tickers];
        self.collect_query_params(optional)
    }
}
impl Route for Exchanges {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        let default: Exchanges = 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 order = self.format_query("order".to_string(), &(self.order), &(default.order));
        let optional = vec![per_page, page, order];
        self.collect_query_params(optional)
    }
}
impl Route for Info {
    fn api_endpoint(&self) -> String {
        let endpoint = self.endpoint.replace("ID", &(self.id));
        format!("{}", endpoint)
    }
    fn query_string(&self) -> String {
        let default: Info = Default::default();
        let include_tickers = self.format_query(
            "include_tickers".to_string(),
            &(self.include_tickers),
            &(default.include_tickers),
        );
        let optional = vec![include_tickers];
        self.collect_query_params(optional)
    }
}
impl Route for List {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        String::from("")
    }
}