use super::urls::api;
use crate::client::YahooClient;
use crate::error::Result;
use tracing::info;
pub async fn fetch(client: &YahooClient) -> Result<serde_json::Value> {
let config = client.config();
info!(
"Fetching currencies (lang={}, region={})",
config.lang, config.region
);
let params = [
("lang", config.lang.as_str()),
("region", config.region.as_str()),
];
let response = client.request_with_params(api::CURRENCIES, ¶ms).await?;
Ok(response.json().await?)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::ClientConfig;
#[tokio::test]
#[ignore] async fn test_fetch_currencies() {
let client = YahooClient::new(ClientConfig::default()).await.unwrap();
let result = fetch(&client).await;
assert!(result.is_ok());
let json = result.unwrap();
assert!(json.get("currencies").is_some());
}
}