mod api;
mod scrape;
#[cfg(feature = "debug-dumps")]
pub(crate) mod debug;
use crate::{YfClient, YfError};
mod model;
pub use model::{Address, Company, Fund, Profile};
async fn load_with_fallback(client: &YfClient, symbol: &str) -> Result<Profile, YfError> {
client.ensure_credentials().await?;
match api::load_from_quote_summary_api(client, symbol).await {
Ok(p) => Ok(p),
Err(e) => {
if std::env::var("YF_DEBUG").ok().as_deref() == Some("1") {
eprintln!("YF_DEBUG: API call failed ({e}), falling back to scrape.");
}
scrape::load_from_scrape(client, symbol).await
}
}
}
pub async fn load_profile(client: &YfClient, symbol: &str) -> Result<Profile, YfError> {
#[cfg(not(feature = "test-mode"))]
{
load_with_fallback(client, symbol).await
}
#[cfg(feature = "test-mode")]
{
use crate::core::client::ApiPreference;
match client.api_preference() {
ApiPreference::ApiThenScrape => load_with_fallback(client, symbol).await,
ApiPreference::ApiOnly => {
client.ensure_credentials().await?;
api::load_from_quote_summary_api(client, symbol).await
}
ApiPreference::ScrapeOnly => scrape::load_from_scrape(client, symbol).await,
}
}
}