mlb_api/endpoints/teams/
mod.rs1pub mod affiliates;
2pub mod history;
3pub mod stats;
4pub mod team;
5
6use crate::endpoints::StatsAPIUrl;
7use crate::endpoints::sports::SportId;
8use crate::endpoints::teams::team::Team;
9use crate::gen_params;
10use crate::types::Copyright;
11use serde::Deserialize;
12use std::fmt::{Display, Formatter};
13
14#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
34#[serde(rename_all = "camelCase")]
35pub struct TeamsResponse {
36 pub copyright: Copyright,
37 pub teams: Vec<Team>,
38}
39
40pub struct TeamsEndpointUrl {
41 pub sport_id: Option<SportId>,
42 pub season: Option<u16>,
43}
44
45impl Display for TeamsEndpointUrl {
46 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
47 write!(f, "http://statsapi.mlb.com/api/v1/teams{}", gen_params! { "sportId"?: self.sport_id, "season"?: self.season })
48 }
49}
50
51impl StatsAPIUrl for TeamsEndpointUrl {
52 type Response = TeamsResponse;
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58 use chrono::{Datelike, Local};
59
60 #[tokio::test]
61 #[cfg_attr(not(feature = "_heavy_tests"), ignore)]
62 async fn parse_all_teams_all_seasons() {
63 for season in 1871..=Local::now().year() as _ {
67 let _response = TeamsEndpointUrl { sport_id: None, season: Some(season) }.get().await.unwrap();
68 }
69 }
70
71 #[tokio::test]
72 async fn parse_all_mlb_teams_this_season() {
73 let _response = TeamsEndpointUrl {
74 sport_id: Some(SportId::default()),
75 season: None,
76 }
77 .get()
78 .await
79 .unwrap();
80 }
81}