Skip to main content

mlbt_api/
live.rs

1use crate::boxscore::Boxscore;
2use crate::plays::Plays;
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Default, Debug, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct LiveResponse {
10    pub game_pk: u64,
11    pub link: String,
12    pub meta_data: MetaData,
13    pub game_data: GameData,
14    pub live_data: LiveData,
15}
16
17#[derive(Default, Debug, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct MetaData {
20    pub wait: i64,
21    pub time_stamp: String,
22    pub game_events: Vec<String>,
23    pub logical_events: Vec<String>,
24}
25
26#[derive(Default, Debug, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct GameData {
29    pub game: Game,
30    pub teams: Teams,
31    pub players: HashMap<String, FullPlayer>,
32    pub abs_challenges: Option<AbsChallenges>,
33}
34
35#[derive(Default, Debug, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct LiveData {
38    pub plays: Plays,
39    pub linescore: Linescore,
40    pub boxscore: Boxscore,
41}
42
43#[derive(Default, Debug, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Linescore {
46    pub current_inning: Option<u8>,
47    pub current_inning_ordinal: Option<String>,
48    pub inning_state: Option<String>,
49    pub inning_half: Option<String>,
50    pub is_top_inning: Option<bool>,
51    pub scheduled_innings: Option<u8>,
52    pub innings: Vec<Inning>,
53    // pub teams:
54    // pub defense:
55    pub offense: Offense,
56    pub balls: Option<u8>,
57    pub strikes: Option<u8>,
58    pub outs: Option<u8>,
59}
60
61#[derive(Default, Debug, Serialize, Deserialize)]
62#[serde(rename_all = "camelCase")]
63pub struct Inning {
64    pub num: u8,
65    pub ordinal_num: String,
66    pub home: TeamInningDetail,
67    pub away: TeamInningDetail,
68}
69
70#[derive(Default, Debug, Serialize, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct TeamInningDetail {
73    pub runs: Option<u8>,
74    pub hits: u8,
75    pub errors: u8,
76    pub left_on_base: u8,
77}
78
79#[derive(Default, Debug, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct Offense {
82    pub on_deck: Option<PlayerIdName>,
83    pub in_hole: Option<PlayerIdName>,
84}
85
86#[derive(Default, Debug, Serialize, Deserialize)]
87pub struct PlayerIdName {
88    pub id: u64,
89    #[serde(rename = "fullName")]
90    pub full_name: String,
91}
92
93#[derive(Default, Debug, Serialize, Deserialize)]
94#[serde(rename_all = "camelCase")]
95pub struct Game {
96    pub pk: i64,
97    #[serde(rename = "type")]
98    pub type_field: String,
99    pub double_header: String,
100    pub id: String,
101    pub gameday_type: String,
102    pub tiebreaker: String,
103    pub game_number: i64,
104    #[serde(rename = "calendarEventID")]
105    pub calendar_event_id: String,
106    pub season: String,
107    pub season_display: String,
108}
109
110#[derive(Default, Debug, Serialize, Deserialize)]
111#[serde(rename_all = "camelCase")]
112pub struct PerTeamChallenges {
113    pub used_successful: u8,
114    pub used_failed: u8,
115    pub remaining: u8,
116}
117
118#[derive(Default, Debug, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120pub struct AbsChallenges {
121    pub has_challenges: bool,
122    pub away: PerTeamChallenges,
123    pub home: PerTeamChallenges,
124}
125
126#[derive(Default, Debug, Serialize, Deserialize)]
127#[serde(rename_all = "camelCase")]
128pub struct Teams {
129    pub away: Team,
130    pub home: Team,
131}
132
133#[derive(Default, Debug, Serialize, Deserialize)]
134#[serde(rename_all = "camelCase")]
135pub struct Team {
136    pub id: u16,
137    pub name: String,
138    pub team_name: String,
139    pub short_name: String,
140    pub season: u16,
141    pub team_code: String,
142    pub abbreviation: String,
143}
144
145#[derive(Default, Debug, Serialize, Deserialize)]
146pub struct Person {
147    pub id: u64,
148    #[serde(rename = "fullName")]
149    pub full_name: String,
150    pub link: Option<String>,
151}
152
153#[derive(Debug, Serialize, Deserialize)]
154pub struct Side {
155    pub code: String,
156    pub description: String,
157}
158
159#[derive(Debug, Serialize, Deserialize)]
160pub struct PrimaryPosition {
161    pub code: String,
162    pub name: String,
163    #[serde(rename = "type")]
164    pub r#type: String,
165    pub abbreviation: String,
166}
167
168#[derive(Debug, Serialize, Deserialize)]
169#[serde(rename_all = "camelCase")]
170pub struct FullPlayer {
171    pub id: u64,
172    pub full_name: String,
173    pub link: Option<String>,
174    pub first_name: String,
175    pub last_name: String,
176    pub primary_number: Option<String>,
177    pub birth_date: Option<String>,
178    pub current_age: Option<i64>,
179    pub birth_city: Option<String>,
180    pub birth_state_province: Option<String>,
181    pub birth_country: Option<String>,
182    pub height: Option<String>,
183    pub weight: Option<u16>,
184    pub active: Option<bool>,
185    pub primary_position: Option<PrimaryPosition>,
186    pub use_name: Option<String>,
187    pub use_last_name: Option<String>,
188    pub middle_name: Option<String>,
189    pub boxscore_name: Option<String>,
190    pub gender: Option<String>,
191    pub is_player: Option<bool>,
192    pub is_verified: Option<bool>,
193    pub draft_year: Option<i64>,
194    pub mlb_debut_date: Option<String>,
195    pub bat_side: Option<Side>,
196    pub pitch_hand: Option<Side>,
197    pub name_first_last: Option<String>,
198    pub name_slug: Option<String>,
199    pub first_last_name: Option<String>,
200    pub last_first_name: Option<String>,
201    pub last_init_name: Option<String>,
202    pub init_last_name: String,
203    #[serde(rename = "fullFMLName")]
204    pub full_fmlname: Option<String>,
205    #[serde(rename = "fullLFMName")]
206    pub full_lfmname: Option<String>,
207    pub strike_zone_top: Option<f64>,
208    pub strike_zone_bottom: Option<f64>,
209}