use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "dataframe", derive(crate::ToDataFrame))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct TrendingQuote {
pub symbol: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RawTrendingResponse {
pub finance: Option<TrendingFinance>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TrendingFinance {
pub result: Option<Vec<TrendingResult>>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TrendingResult {
pub quotes: Option<Vec<TrendingQuote>>,
}
impl TrendingQuote {
pub(crate) fn from_response(value: serde_json::Value) -> Result<Vec<Self>, serde_json::Error> {
let raw: RawTrendingResponse = serde_json::from_value(value)?;
Ok(raw
.finance
.and_then(|f| f.result)
.and_then(|r| r.into_iter().next())
.and_then(|r| r.quotes)
.unwrap_or_default())
}
}