use crate::BootstrapStatic;
use crate::client::FplApiClient;
use crate::models::bootstrap_static::{Event, Team};
use anyhow::Result;
use std::collections::HashSet;
impl FplApiClient {
pub async fn get_bootstrap(&self) -> Result<BootstrapStatic> {
let all: BootstrapStatic = self.gets("bootstrap-static/").await?;
Ok(all)
}
pub async fn get_events(&self) -> Result<Vec<Event>> {
let events: Vec<Event> = self.gets("events/").await?;
Ok(events)
}
pub async fn get_team_info<I>(&self, team_id: I) -> Result<Vec<Team>>
where
I: IntoIterator<Item = i32>,
{
let all: BootstrapStatic = self.get_bootstrap().await?;
let id_set: HashSet<i32> = team_id.into_iter().collect();
let teams: Vec<Team> = all
.teams
.into_iter()
.filter(|t| id_set.contains(&t.id))
.collect();
Ok(teams)
}
}