mlb_api/endpoints/teams/history/
mod.rs

1use std::fmt::{Display, Formatter};
2use crate::endpoints::StatsAPIUrl;
3use crate::endpoints::teams::team::TeamId;
4use crate::endpoints::teams::TeamsResponse;
5use crate::gen_params;
6
7/// History of a [`TeamId`] throughout the years.
8/// For example, the team history of the Los Angeles Dodgers would include those of the Brooklyn Dodgers.
9pub struct TeamHistoryEndpointUrl {
10	pub team_id: TeamId,
11	pub start_season: Option<u16>,
12	pub end_season: Option<u16>,
13}
14
15impl Display for TeamHistoryEndpointUrl {
16	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17		write!(f, "http://statsapi.mlb.com/api/v1/teams/{}/history{params}", self.team_id, params = gen_params! { "startSeason"?: self.start_season, "endSeason"?: self.end_season })
18	}
19}
20
21impl StatsAPIUrl for TeamHistoryEndpointUrl {
22	type Response = TeamsResponse;
23}
24
25#[cfg(test)]
26mod tests {
27	use crate::endpoints::sports::SportId;
28	use crate::endpoints::StatsAPIUrl;
29	use crate::endpoints::teams::history::TeamHistoryEndpointUrl;
30	use crate::endpoints::teams::TeamsEndpointUrl;
31
32	#[tokio::test]
33	async fn all_mlb_teams() {
34		for team in (TeamsEndpointUrl { sport_id: Some(SportId::MLB), season: None }).get().await.unwrap().teams {
35			let _history = TeamHistoryEndpointUrl { team_id: team.id, start_season: None, end_season: None }.get().await.unwrap();
36		}
37	}
38}