use crate::internal::api::Api;
use crate::internal::errors::CryptoMktErrorType;
use crate::internal::request::CryptoMktRequest;
use serde::de::DeserializeOwned;
use std::collections::HashMap;
pub enum RequestMethod {
Post,
Get(bool),
}
#[derive(Debug, Clone)]
pub struct CryptoMktApi {
i_api: Box<Api<CryptoMktRequest>>,
}
impl CryptoMktApi {
pub fn new<'a>(api_key: &'a str, secret_key: &'a str) -> Self {
CryptoMktApi {
i_api: Box::new(Api::<CryptoMktRequest>::new(
api_key,
secret_key,
Box::new(CryptoMktRequest::new()),
)),
}
}
pub fn domain(&self) -> String {
self.i_api.domain()
}
pub fn version(&self) -> String {
self.i_api.api_version()
}
pub fn call<'a, T>(
&self,
method: RequestMethod,
endpoint: &'a str,
payload: HashMap<String, String>,
) -> Result<T, CryptoMktErrorType>
where
T: DeserializeOwned,
{
match method {
RequestMethod::Get(is_public) => self.i_api.get_edge(endpoint, payload, is_public),
RequestMethod::Post => self.i_api.post_edge(endpoint, payload),
}
}
}