use std::sync::Arc;
use serde_json::Value;
use crate::error::Error;
use crate::transport::HttpTransport;
use crate::types::TrendingResponse;
pub struct TrendingClient {
transport: Arc<HttpTransport>,
}
impl TrendingClient {
pub fn new(transport: Arc<HttpTransport>) -> Self {
Self { transport }
}
pub async fn get(
&self,
window: Option<&str>,
limit: Option<u32>,
) -> Result<TrendingResponse, Error> {
let window_str = window.unwrap_or("24h").to_string();
let limit_str = limit.unwrap_or(50).to_string();
let params: Vec<(&str, &str)> = vec![("window", &window_str), ("limit", &limit_str)];
let response: Value = self
.transport
.unsigned_request::<Value>("GET", "/v1/repos/trending", Some(¶ms), None::<&()>)
.await?;
let data = response
.get("data")
.ok_or_else(|| Error::Http("Missing data in response".to_string()))?;
serde_json::from_value(data.clone()).map_err(Error::from)
}
}