use async_trait::async_trait;
use crate::error::{Error, Result};
#[async_trait]
pub trait HttpClient {
async fn get_alpha_vantage_provider_output(&self, path: &str) -> Result<String>;
async fn get_rapid_api_provider_output(&self, path: &str, api_key: &str) -> Result<String>;
}
#[cfg(feature = "reqwest-client")]
#[async_trait]
impl HttpClient for reqwest::Client {
async fn get_alpha_vantage_provider_output(&self, path: &str) -> Result<String> {
self.get(path)
.send()
.await
.map_err(|_| Error::GetRequestFailed)?
.text()
.await
.map_err(|_| Error::GetRequestFailed)
}
async fn get_rapid_api_provider_output(&self, path: &str, api_key: &str) -> Result<String> {
self.get(path)
.header("x-rapidapi-host", "alpha-vantage.p.rapidapi.com")
.header("x-rapidapi-key", api_key)
.send()
.await
.map_err(|_| Error::GetRequestFailed)?
.text()
.await
.map_err(|_| Error::GetRequestFailed)
}
}