mlb 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +329 -108
  4. data/lib/mlb/affiliates.rb +28 -0
  5. data/lib/mlb/alumni.rb +30 -0
  6. data/lib/mlb/attendance.rb +28 -0
  7. data/lib/mlb/attendance_record.rb +157 -0
  8. data/lib/mlb/award.rb +89 -11
  9. data/lib/mlb/awards.rb +17 -7
  10. data/lib/mlb/baseball_stat.rb +65 -0
  11. data/lib/mlb/baseball_stats.rb +12 -0
  12. data/lib/mlb/boxscore.rb +81 -0
  13. data/lib/mlb/boxscore_team_stats.rb +210 -0
  14. data/lib/mlb/client.rb +71 -0
  15. data/lib/mlb/coaches.rb +28 -0
  16. data/lib/mlb/code_description_type.rb +45 -0
  17. data/lib/mlb/collection.rb +48 -0
  18. data/lib/mlb/comparable_by_attribute.rb +56 -0
  19. data/lib/mlb/conference.rb +8 -1
  20. data/lib/mlb/conferences.rb +18 -10
  21. data/lib/mlb/connection.rb +130 -7
  22. data/lib/mlb/context_metrics.rb +90 -0
  23. data/lib/mlb/division.rb +24 -6
  24. data/lib/mlb/divisions.rb +24 -18
  25. data/lib/mlb/draft.rb +83 -0
  26. data/lib/mlb/draft_pick.rb +155 -0
  27. data/lib/mlb/error_handler.rb +21 -1
  28. data/lib/mlb/errors/bad_gateway.rb +6 -1
  29. data/lib/mlb/errors/bad_request.rb +1 -0
  30. data/lib/mlb/errors/client_error.rb +1 -0
  31. data/lib/mlb/errors/connection_exception.rb +1 -0
  32. data/lib/mlb/errors/error.rb +1 -0
  33. data/lib/mlb/errors/forbidden.rb +1 -0
  34. data/lib/mlb/errors/gateway_timeout.rb +6 -1
  35. data/lib/mlb/errors/gone.rb +1 -0
  36. data/lib/mlb/errors/http_error.rb +22 -2
  37. data/lib/mlb/errors/internal_server_error.rb +1 -0
  38. data/lib/mlb/errors/network_error.rb +6 -1
  39. data/lib/mlb/errors/not_acceptable.rb +1 -0
  40. data/lib/mlb/errors/not_found.rb +1 -0
  41. data/lib/mlb/errors/payload_too_large.rb +1 -0
  42. data/lib/mlb/errors/retryable.rb +15 -0
  43. data/lib/mlb/errors/server_error.rb +1 -0
  44. data/lib/mlb/errors/service_unavailable.rb +6 -1
  45. data/lib/mlb/errors/too_many_redirects.rb +1 -0
  46. data/lib/mlb/errors/too_many_requests.rb +6 -1
  47. data/lib/mlb/errors/unauthorized.rb +1 -0
  48. data/lib/mlb/errors/unprocessable_entity.rb +1 -0
  49. data/lib/mlb/event_type.rb +61 -0
  50. data/lib/mlb/event_types.rb +12 -0
  51. data/lib/mlb/free_agent.rb +78 -0
  52. data/lib/mlb/free_agents.rb +34 -0
  53. data/lib/mlb/game_changes.rb +87 -0
  54. data/lib/mlb/game_content.rb +251 -0
  55. data/lib/mlb/game_data.rb +155 -0
  56. data/lib/mlb/game_pace.rb +173 -0
  57. data/lib/mlb/game_status.rb +94 -0
  58. data/lib/mlb/game_statuses.rb +12 -0
  59. data/lib/mlb/game_type.rb +98 -0
  60. data/lib/mlb/game_types.rb +12 -0
  61. data/lib/mlb/handedness.rb +28 -10
  62. data/lib/mlb/high_low.rb +121 -0
  63. data/lib/mlb/hit_trajectories.rb +12 -0
  64. data/lib/mlb/hit_trajectory.rb +6 -0
  65. data/lib/mlb/home_run_derby.rb +285 -0
  66. data/lib/mlb/id_description_type.rb +44 -0
  67. data/lib/mlb/inning_score.rb +87 -0
  68. data/lib/mlb/job.rb +58 -0
  69. data/lib/mlb/job_type.rb +39 -0
  70. data/lib/mlb/job_types.rb +12 -0
  71. data/lib/mlb/jobs.rb +87 -0
  72. data/lib/mlb/language.rb +48 -0
  73. data/lib/mlb/languages.rb +12 -0
  74. data/lib/mlb/leader.rb +79 -0
  75. data/lib/mlb/leaders.rb +68 -0
  76. data/lib/mlb/league.rb +95 -14
  77. data/lib/mlb/league_leader_type.rb +21 -0
  78. data/lib/mlb/league_leader_types.rb +12 -0
  79. data/lib/mlb/leagues.rb +24 -18
  80. data/lib/mlb/linescore.rb +342 -0
  81. data/lib/mlb/linescore_teams.rb +89 -0
  82. data/lib/mlb/live_feed.rb +130 -0
  83. data/lib/mlb/logical_event.rb +17 -0
  84. data/lib/mlb/logical_events.rb +12 -0
  85. data/lib/mlb/metric.rb +48 -0
  86. data/lib/mlb/metrics.rb +12 -0
  87. data/lib/mlb/people_changes.rb +34 -0
  88. data/lib/mlb/personnel.rb +28 -0
  89. data/lib/mlb/pitch_code.rb +90 -0
  90. data/lib/mlb/pitch_codes.rb +12 -0
  91. data/lib/mlb/pitch_type.rb +6 -0
  92. data/lib/mlb/pitch_types.rb +12 -0
  93. data/lib/mlb/platform.rb +30 -0
  94. data/lib/mlb/platforms.rb +12 -0
  95. data/lib/mlb/play.rb +300 -0
  96. data/lib/mlb/play_by_play.rb +52 -0
  97. data/lib/mlb/player.rb +182 -0
  98. data/lib/mlb/player_game_stats.rb +350 -0
  99. data/lib/mlb/player_stat.rb +70 -0
  100. data/lib/mlb/players.rb +34 -23
  101. data/lib/mlb/position.rb +65 -0
  102. data/lib/mlb/positions.rb +12 -0
  103. data/lib/mlb/postseason_schedule.rb +41 -0
  104. data/lib/mlb/postseason_series.rb +54 -0
  105. data/lib/mlb/redirect_handler.rb +80 -21
  106. data/lib/mlb/request_builder.rb +33 -2
  107. data/lib/mlb/review_reason.rb +6 -0
  108. data/lib/mlb/review_reasons.rb +12 -0
  109. data/lib/mlb/roster.rb +16 -12
  110. data/lib/mlb/roster_entry.rb +35 -0
  111. data/lib/mlb/roster_type.rb +39 -0
  112. data/lib/mlb/roster_types.rb +12 -0
  113. data/lib/mlb/schedule.rb +33 -0
  114. data/lib/mlb/schedule_date.rb +37 -0
  115. data/lib/mlb/schedule_event_type.rb +25 -0
  116. data/lib/mlb/schedule_event_types.rb +12 -0
  117. data/lib/mlb/scheduled_game.rb +321 -0
  118. data/lib/mlb/season.rb +15 -4
  119. data/lib/mlb/season_date_info.rb +1 -0
  120. data/lib/mlb/seasons.rb +24 -18
  121. data/lib/mlb/single_team_stats.rb +33 -0
  122. data/lib/mlb/situation_code.rb +116 -0
  123. data/lib/mlb/situation_codes.rb +12 -0
  124. data/lib/mlb/skies.rb +12 -0
  125. data/lib/mlb/sky.rb +3 -8
  126. data/lib/mlb/sport.rb +16 -5
  127. data/lib/mlb/sport_players.rb +30 -0
  128. data/lib/mlb/sports.rb +17 -7
  129. data/lib/mlb/standings.rb +47 -0
  130. data/lib/mlb/standings_record.rb +108 -0
  131. data/lib/mlb/standings_type.rb +25 -0
  132. data/lib/mlb/standings_types.rb +12 -0
  133. data/lib/mlb/stat_group.rb +21 -0
  134. data/lib/mlb/stat_groups.rb +12 -0
  135. data/lib/mlb/stat_type.rb +21 -0
  136. data/lib/mlb/stat_types.rb +12 -0
  137. data/lib/mlb/stat_values.rb +158 -0
  138. data/lib/mlb/stats.rb +41 -0
  139. data/lib/mlb/status.rb +14 -0
  140. data/lib/mlb/streaks.rb +184 -0
  141. data/lib/mlb/team.rb +62 -7
  142. data/lib/mlb/team_history.rb +28 -0
  143. data/lib/mlb/team_leader.rb +59 -0
  144. data/lib/mlb/team_leaders.rb +45 -0
  145. data/lib/mlb/team_record.rb +285 -0
  146. data/lib/mlb/team_stat.rb +50 -0
  147. data/lib/mlb/team_stats.rb +52 -0
  148. data/lib/mlb/teams.rb +28 -18
  149. data/lib/mlb/tied_games.rb +32 -0
  150. data/lib/mlb/transaction.rb +125 -0
  151. data/lib/mlb/transactions.rb +11 -6
  152. data/lib/mlb/uniforms.rb +97 -0
  153. data/lib/mlb/utils.rb +45 -0
  154. data/lib/mlb/venue.rb +7 -0
  155. data/lib/mlb/venues.rb +28 -18
  156. data/lib/mlb/version.rb +2 -1
  157. data/lib/mlb/win_probability.rb +64 -0
  158. data/lib/mlb/wind_direction.rb +3 -8
  159. data/lib/mlb/wind_directions.rb +12 -0
  160. data/lib/mlb.rb +61 -0
  161. data/sig/equalizer.rbs +3 -0
  162. data/sig/mlb.rbs +2055 -0
  163. data/sig/shale.rbs +29 -0
  164. metadata +107 -2
@@ -0,0 +1,61 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a baseball event type
6
+ class EventType < Shale::Mapper
7
+ include Equalizer.new(:code)
8
+
9
+ # @!attribute [rw] code
10
+ # Returns the event code
11
+ # @api public
12
+ # @example
13
+ # event_type.code #=> "single"
14
+ # @return [String] the event code
15
+ attribute :code, Shale::Type::String
16
+
17
+ # @!attribute [rw] description
18
+ # Returns the event description
19
+ # @api public
20
+ # @example
21
+ # event_type.description #=> "Single"
22
+ # @return [String] the event description
23
+ attribute :description, Shale::Type::String
24
+
25
+ # @!attribute [rw] plate_appearance
26
+ # Returns whether this event counts as a plate appearance
27
+ # @api public
28
+ # @example
29
+ # event_type.plate_appearance #=> true
30
+ # @return [Boolean] whether this event counts as a plate appearance
31
+ attribute :plate_appearance, Shale::Type::Boolean
32
+
33
+ # @!attribute [rw] hit
34
+ # Returns whether this event is a hit
35
+ # @api public
36
+ # @example
37
+ # event_type.hit #=> true
38
+ # @return [Boolean] whether this event is a hit
39
+ attribute :hit, Shale::Type::Boolean
40
+
41
+ # @!attribute [rw] base_running_event
42
+ # Returns whether this event involves base running
43
+ # @api public
44
+ # @example
45
+ # event_type.base_running_event #=> false
46
+ # @return [Boolean] whether this event involves base running
47
+ attribute :base_running_event, Shale::Type::Boolean
48
+
49
+ alias_method :plate_appearance?, :plate_appearance
50
+ alias_method :hit?, :hit
51
+ alias_method :base_running_event?, :base_running_event
52
+
53
+ json do
54
+ map "code", to: :code
55
+ map "description", to: :description
56
+ map "plateAppearance", to: :plate_appearance
57
+ map "hit", to: :hit
58
+ map "baseRunningEvent", to: :base_running_event
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "event_type"
3
+
4
+ module MLB
5
+ # Provides methods for fetching event types from the API
6
+ #
7
+ # @example Fetch all event types
8
+ # MLB::EventTypes.all #=> [#<MLB::EventType>, ...]
9
+ class EventTypes < Collection
10
+ collection endpoint: "eventTypes", item_type: EventType, collection_name: :event_types
11
+ end
12
+ end
@@ -0,0 +1,78 @@
1
+ require "equalizer"
2
+ require "shale"
3
+ require_relative "player"
4
+ require_relative "team"
5
+ require_relative "position"
6
+
7
+ module MLB
8
+ # Represents a free agent
9
+ class FreeAgent < Shale::Mapper
10
+ include Equalizer.new(:player)
11
+
12
+ # @!attribute [rw] player
13
+ # Returns the player
14
+ # @api public
15
+ # @example
16
+ # free_agent.player #=> #<MLB::Player>
17
+ # @return [Player] the player
18
+ attribute :player, Player
19
+
20
+ # @!attribute [rw] original_team
21
+ # Returns the team the player left
22
+ # @api public
23
+ # @example
24
+ # free_agent.original_team #=> #<MLB::Team>
25
+ # @return [Team] the original team
26
+ attribute :original_team, Team
27
+
28
+ # @!attribute [rw] new_team
29
+ # Returns the team the player signed with
30
+ # @api public
31
+ # @example
32
+ # free_agent.new_team #=> #<MLB::Team>
33
+ # @return [Team] the new team
34
+ attribute :new_team, Team
35
+
36
+ # @!attribute [rw] notes
37
+ # Returns signing notes
38
+ # @api public
39
+ # @example
40
+ # free_agent.notes #=> "Seven-Year Contract"
41
+ # @return [String] the notes
42
+ attribute :notes, Shale::Type::String
43
+
44
+ # @!attribute [rw] date_signed
45
+ # Returns the date the player signed
46
+ # @api public
47
+ # @example
48
+ # free_agent.date_signed #=> #<Date: 2024-12-10>
49
+ # @return [Date] the date signed
50
+ attribute :date_signed, Shale::Type::Date
51
+
52
+ # @!attribute [rw] date_declared
53
+ # Returns the date the player declared free agency
54
+ # @api public
55
+ # @example
56
+ # free_agent.date_declared #=> #<Date: 2024-10-31>
57
+ # @return [Date] the date declared
58
+ attribute :date_declared, Shale::Type::Date
59
+
60
+ # @!attribute [rw] position
61
+ # Returns the player's position
62
+ # @api public
63
+ # @example
64
+ # free_agent.position #=> #<MLB::Position>
65
+ # @return [Position] the position
66
+ attribute :position, Position
67
+
68
+ json do
69
+ map "player", to: :player
70
+ map "originalTeam", to: :original_team
71
+ map "newTeam", to: :new_team
72
+ map "notes", to: :notes
73
+ map "dateSigned", to: :date_signed
74
+ map "dateDeclared", to: :date_declared
75
+ map "position", to: :position
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,34 @@
1
+ require "shale"
2
+ require_relative "free_agent"
3
+
4
+ module MLB
5
+ # Provides methods for fetching free agent data from the API
6
+ class FreeAgents < Shale::Mapper
7
+ # @!attribute [rw] free_agents
8
+ # Returns the free agents
9
+ # @api public
10
+ # @example
11
+ # free_agents.free_agents #=> [#<MLB::FreeAgent>, ...]
12
+ # @return [Array<FreeAgent>] the free agents
13
+ attribute :free_agents, FreeAgent, collection: true
14
+
15
+ json do
16
+ map "freeAgents", to: :free_agents
17
+ end
18
+
19
+ # Retrieves all free agents for a season
20
+ #
21
+ # @api public
22
+ # @example Get free agents for the current season
23
+ # MLB::FreeAgents.all
24
+ # @example Get free agents for a specific season
25
+ # MLB::FreeAgents.all(season: 2024)
26
+ # @param season [Integer, nil] the season year (defaults to current year)
27
+ # @return [Array<FreeAgent>] the free agents
28
+ def self.all(season: nil)
29
+ season ||= Utils.current_season
30
+ response = CLIENT.get("people/freeAgents?#{Utils.build_query(season:)}")
31
+ from_json(response).free_agents
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,87 @@
1
+ require "shale"
2
+
3
+ module MLB
4
+ # Represents a game that has been modified since a given timestamp
5
+ class ChangedGame < Shale::Mapper
6
+ include Equalizer.new(:game_pk)
7
+
8
+ # @!attribute [rw] game_pk
9
+ # Returns the unique game identifier
10
+ # @api public
11
+ # @example
12
+ # game.game_pk #=> 745571
13
+ # @return [Integer] the game primary key
14
+ attribute :game_pk, Shale::Type::Integer
15
+
16
+ json do
17
+ map "gamePk", to: :game_pk
18
+ end
19
+ end
20
+
21
+ # Groups changed games by date
22
+ class ChangedGameDate < Shale::Mapper
23
+ # @!attribute [rw] date
24
+ # Returns the date string
25
+ # @api public
26
+ # @example
27
+ # date_entry.date #=> "2024-06-15"
28
+ # @return [String] the date in YYYY-MM-DD format
29
+ attribute :date, Shale::Type::String
30
+
31
+ # @!attribute [rw] games
32
+ # Returns the games that changed on this date
33
+ # @api public
34
+ # @example
35
+ # date_entry.games #=> [#<MLB::ChangedGame>, ...]
36
+ # @return [Array<ChangedGame>] the changed games
37
+ attribute :games, ChangedGame, collection: true
38
+
39
+ json do
40
+ map "date", to: :date
41
+ map "games", to: :games
42
+ end
43
+ end
44
+
45
+ # Fetches games that have been modified since a given timestamp
46
+ #
47
+ # This endpoint is useful for efficiently polling for game updates
48
+ # rather than fetching all game data repeatedly.
49
+ class GameChanges < Shale::Mapper
50
+ # @!attribute [rw] dates
51
+ # Returns dates containing changed games
52
+ # @api public
53
+ # @example
54
+ # response.dates #=> [#<MLB::ChangedGameDate>, ...]
55
+ # @return [Array<ChangedGameDate>] the dates with changes
56
+ attribute :dates, ChangedGameDate, collection: true
57
+
58
+ json do
59
+ map "dates", to: :dates
60
+ end
61
+
62
+ # Retrieves games modified since the given timestamp
63
+ #
64
+ # @api public
65
+ # @example Basic usage with ISO 8601 timestamp
66
+ # MLB::GameChanges.since(updated_since: "2024-06-15T12:00:00Z")
67
+ # @example Filter by sport (1 = MLB)
68
+ # MLB::GameChanges.since(updated_since: "2024-06-15T12:00:00Z", sport_id: 1)
69
+ # @example Filter by season and game type
70
+ # MLB::GameChanges.since(updated_since: timestamp, season: 2024, game_type: "R")
71
+ # @param updated_since [#to_s] timestamp to check changes from (ISO 8601 format)
72
+ # @param sport_id [Integer, nil] filter by sport ID
73
+ # @param season [Integer, nil] filter by season year
74
+ # @param game_type [String, nil] filter by game type (R=Regular, P=Postseason, etc.)
75
+ # @return [Array<ChangedGame>] games modified since the timestamp
76
+ def self.since(updated_since:, sport_id: nil, season: nil, game_type: nil)
77
+ params = {
78
+ updatedSince: updated_since.to_s,
79
+ sportId: sport_id,
80
+ season: season,
81
+ gameType: game_type
82
+ }.compact
83
+ response = CLIENT.get("game/changes?#{URI.encode_www_form(params)}")
84
+ from_json(response).dates.flat_map(&:games)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,251 @@
1
+ require "shale"
2
+
3
+ module MLB
4
+ # Represents a media playback option
5
+ class MediaPlayback < Shale::Mapper
6
+ # @!attribute [rw] name
7
+ # Returns the playback name
8
+ # @api public
9
+ # @example
10
+ # playback.name #=> "mp4Avc"
11
+ # @return [String] the name
12
+ attribute :name, Shale::Type::String
13
+
14
+ # @!attribute [rw] url
15
+ # Returns the playback URL
16
+ # @api public
17
+ # @example
18
+ # playback.url #=> "https://..."
19
+ # @return [String] the URL
20
+ attribute :url, Shale::Type::String
21
+
22
+ json do
23
+ map "name", to: :name
24
+ map "url", to: :url
25
+ end
26
+ end
27
+
28
+ # Represents a media image cut
29
+ class MediaCut < Shale::Mapper
30
+ # @!attribute [rw] aspect_ratio
31
+ # Returns the aspect ratio
32
+ # @api public
33
+ # @example
34
+ # cut.aspect_ratio #=> "16:9"
35
+ # @return [String] the aspect ratio
36
+ attribute :aspect_ratio, Shale::Type::String
37
+
38
+ # @!attribute [rw] width
39
+ # Returns the width
40
+ # @api public
41
+ # @example
42
+ # cut.width #=> 1920
43
+ # @return [Integer] the width
44
+ attribute :width, Shale::Type::Integer
45
+
46
+ # @!attribute [rw] height
47
+ # Returns the height
48
+ # @api public
49
+ # @example
50
+ # cut.height #=> 1080
51
+ # @return [Integer] the height
52
+ attribute :height, Shale::Type::Integer
53
+
54
+ # @!attribute [rw] src
55
+ # Returns the image source URL
56
+ # @api public
57
+ # @example
58
+ # cut.src #=> "https://..."
59
+ # @return [String] the source URL
60
+ attribute :src, Shale::Type::String
61
+
62
+ json do
63
+ map "aspectRatio", to: :aspect_ratio
64
+ map "width", to: :width
65
+ map "height", to: :height
66
+ map "src", to: :src
67
+ end
68
+ end
69
+
70
+ # Represents media image information
71
+ class MediaImage < Shale::Mapper
72
+ # @!attribute [rw] title
73
+ # Returns the image title
74
+ # @api public
75
+ # @example
76
+ # image.title #=> "Highlight Image"
77
+ # @return [String] the title
78
+ attribute :title, Shale::Type::String
79
+
80
+ # @!attribute [rw] cuts
81
+ # Returns the image cuts
82
+ # @api public
83
+ # @example
84
+ # image.cuts #=> [#<MLB::MediaCut>, ...]
85
+ # @return [Array<MediaCut>] the cuts
86
+ attribute :cuts, MediaCut, collection: true
87
+
88
+ json do
89
+ map "title", to: :title
90
+ map "cuts", to: :cuts
91
+ end
92
+ end
93
+
94
+ # Represents a game highlight
95
+ class Highlight < Shale::Mapper
96
+ include Equalizer.new(:id, :headline)
97
+
98
+ # @!attribute [rw] id
99
+ # Returns the highlight ID
100
+ # @api public
101
+ # @example
102
+ # highlight.id #=> "12345"
103
+ # @return [String] the ID
104
+ attribute :id, Shale::Type::String
105
+
106
+ # @!attribute [rw] type
107
+ # Returns the content type
108
+ # @api public
109
+ # @example
110
+ # highlight.type #=> "video"
111
+ # @return [String] the type
112
+ attribute :type, Shale::Type::String
113
+
114
+ # @!attribute [rw] headline
115
+ # Returns the headline
116
+ # @api public
117
+ # @example
118
+ # highlight.headline #=> "Player hits home run"
119
+ # @return [String] the headline
120
+ attribute :headline, Shale::Type::String
121
+
122
+ # @!attribute [rw] description
123
+ # Returns the description
124
+ # @api public
125
+ # @example
126
+ # highlight.description #=> "Player crushes a 3-run homer"
127
+ # @return [String] the description
128
+ attribute :description, Shale::Type::String
129
+
130
+ # @!attribute [rw] duration
131
+ # Returns the duration in seconds
132
+ # @api public
133
+ # @example
134
+ # highlight.duration #=> "00:00:45"
135
+ # @return [String] the duration
136
+ attribute :duration, Shale::Type::String
137
+
138
+ # @!attribute [rw] playbacks
139
+ # Returns the playback options
140
+ # @api public
141
+ # @example
142
+ # highlight.playbacks #=> [#<MLB::MediaPlayback>, ...]
143
+ # @return [Array<MediaPlayback>] the playbacks
144
+ attribute :playbacks, MediaPlayback, collection: true
145
+
146
+ # @!attribute [rw] image
147
+ # Returns the thumbnail image
148
+ # @api public
149
+ # @example
150
+ # highlight.image #=> #<MLB::MediaImage>
151
+ # @return [MediaImage] the image
152
+ attribute :image, MediaImage
153
+
154
+ json do
155
+ map "id", to: :id
156
+ map "type", to: :type
157
+ map "headline", to: :headline
158
+ map "description", to: :description
159
+ map "duration", to: :duration
160
+ map "playbacks", to: :playbacks
161
+ map "image", to: :image
162
+ end
163
+ end
164
+
165
+ # Represents the highlights section
166
+ class HighlightsSection < Shale::Mapper
167
+ # @!attribute [rw] highlights
168
+ # Returns the highlights
169
+ # @api public
170
+ # @example
171
+ # section.highlights #=> [#<MLB::Highlight>, ...]
172
+ # @return [Array<Highlight>] the highlights
173
+ attribute :highlights, Highlight, collection: true
174
+
175
+ json do
176
+ map "items", to: :highlights
177
+ end
178
+ end
179
+
180
+ # Represents the game content media
181
+ class GameContentMedia < Shale::Mapper
182
+ # @!attribute [rw] free_game
183
+ # Returns whether this is a free game
184
+ # @api public
185
+ # @example
186
+ # media.free_game #=> true
187
+ # @return [Boolean] whether free game
188
+ attribute :free_game, Shale::Type::Boolean
189
+
190
+ # @!attribute [rw] enhanced_game
191
+ # Returns whether this is an enhanced game
192
+ # @api public
193
+ # @example
194
+ # media.enhanced_game #=> false
195
+ # @return [Boolean] whether enhanced game
196
+ attribute :enhanced_game, Shale::Type::Boolean
197
+
198
+ json do
199
+ map "freeGame", to: :free_game
200
+ map "enhancedGame", to: :enhanced_game
201
+ end
202
+ end
203
+
204
+ # Represents the game content
205
+ class GameContent < Shale::Mapper
206
+ # @!attribute [rw] link
207
+ # Returns the API link
208
+ # @api public
209
+ # @example
210
+ # content.link #=> "/api/v1/game/745571/content"
211
+ # @return [String] the link
212
+ attribute :link, Shale::Type::String
213
+
214
+ # @!attribute [rw] media
215
+ # Returns the media info
216
+ # @api public
217
+ # @example
218
+ # content.media #=> #<MLB::GameContentMedia>
219
+ # @return [GameContentMedia] the media
220
+ attribute :media, GameContentMedia
221
+
222
+ # @!attribute [rw] highlights
223
+ # Returns the highlights
224
+ # @api public
225
+ # @example
226
+ # content.highlights #=> #<MLB::HighlightsSection>
227
+ # @return [HighlightsSection] the highlights
228
+ attribute :highlights, HighlightsSection
229
+
230
+ json do
231
+ map "link", to: :link
232
+ map "media", to: :media
233
+ map "highlights", to: :highlights
234
+ end
235
+
236
+ # Retrieves the content for a game
237
+ #
238
+ # @api public
239
+ # @example Get content for a game
240
+ # MLB::GameContent.find(game: 745571)
241
+ # @example Get content using a ScheduledGame object
242
+ # MLB::GameContent.find(game: scheduled_game)
243
+ # @param game [Integer, ScheduledGame] the game ID or game object
244
+ # @return [GameContent] the game content
245
+ def self.find(game:)
246
+ game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
247
+ response = CLIENT.get("game/#{game_pk}/content")
248
+ from_json(response)
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,155 @@
1
+ require "shale"
2
+ require_relative "team"
3
+ require_relative "venue"
4
+ require_relative "player"
5
+
6
+ module MLB
7
+ # Represents game date/time information
8
+ class GameDateTime < Shale::Mapper
9
+ # @!attribute [rw] date_time
10
+ # Returns the game date and time
11
+ # @api public
12
+ # @example
13
+ # datetime.date_time #=> "2024-10-01T23:08:00Z"
14
+ # @return [String] the game date and time
15
+ attribute :date_time, Shale::Type::String
16
+
17
+ # @!attribute [rw] original_date
18
+ # Returns the original scheduled date
19
+ # @api public
20
+ # @example
21
+ # datetime.original_date #=> "2024-10-01"
22
+ # @return [String] the original date
23
+ attribute :original_date, Shale::Type::String
24
+
25
+ # @!attribute [rw] day_night
26
+ # Returns day or night game indicator
27
+ # @api public
28
+ # @example
29
+ # datetime.day_night #=> "night"
30
+ # @return [String] day or night
31
+ attribute :day_night, Shale::Type::String
32
+
33
+ # @!attribute [rw] time
34
+ # Returns the game time
35
+ # @api public
36
+ # @example
37
+ # datetime.time #=> "7:08"
38
+ # @return [String] the time
39
+ attribute :time, Shale::Type::String
40
+
41
+ # @!attribute [rw] am_pm
42
+ # Returns AM or PM indicator
43
+ # @api public
44
+ # @example
45
+ # datetime.am_pm #=> "PM"
46
+ # @return [String] AM or PM
47
+ attribute :am_pm, Shale::Type::String
48
+
49
+ # Day game indicator value
50
+ DAY = "day".freeze
51
+ # Night game indicator value
52
+ NIGHT = "night".freeze
53
+ # AM indicator value
54
+ AM = "AM".freeze
55
+ # PM indicator value
56
+ PM = "PM".freeze
57
+
58
+ # Returns whether this is a day game
59
+ #
60
+ # @api public
61
+ # @example
62
+ # datetime.day? #=> false
63
+ # @return [Boolean] true if the game is a day game
64
+ def day? = day_night.eql?(DAY)
65
+
66
+ # Returns whether this is a night game
67
+ #
68
+ # @api public
69
+ # @example
70
+ # datetime.night? #=> true
71
+ # @return [Boolean] true if the game is a night game
72
+ def night? = day_night.eql?(NIGHT)
73
+
74
+ # Returns whether this game starts in the morning (AM)
75
+ #
76
+ # @api public
77
+ # @example
78
+ # datetime.am? #=> false
79
+ # @return [Boolean] true if the game starts in the morning
80
+ def am? = am_pm.eql?(AM)
81
+
82
+ # Returns whether this game starts in the afternoon/evening (PM)
83
+ #
84
+ # @api public
85
+ # @example
86
+ # datetime.pm? #=> true
87
+ # @return [Boolean] true if the game starts in the afternoon/evening
88
+ def pm? = am_pm.eql?(PM)
89
+
90
+ json do
91
+ map "dateTime", to: :date_time
92
+ map "originalDate", to: :original_date
93
+ map "dayNight", to: :day_night
94
+ map "time", to: :time
95
+ map "ampm", to: :am_pm
96
+ end
97
+ end
98
+
99
+ # Represents the teams playing in a game
100
+ class GameTeams < Shale::Mapper
101
+ # @!attribute [rw] away
102
+ # Returns the away team
103
+ # @api public
104
+ # @example
105
+ # teams.away #=> #<MLB::Team>
106
+ # @return [Team] the away team
107
+ attribute :away, Team
108
+
109
+ # @!attribute [rw] home
110
+ # Returns the home team
111
+ # @api public
112
+ # @example
113
+ # teams.home #=> #<MLB::Team>
114
+ # @return [Team] the home team
115
+ attribute :home, Team
116
+
117
+ json do
118
+ map "away", to: :away
119
+ map "home", to: :home
120
+ end
121
+ end
122
+
123
+ # Represents the game metadata
124
+ class GameData < Shale::Mapper
125
+ # @!attribute [rw] datetime
126
+ # Returns the game date/time info
127
+ # @api public
128
+ # @example
129
+ # data.datetime #=> #<MLB::GameDateTime>
130
+ # @return [GameDateTime] the date/time info
131
+ attribute :datetime, GameDateTime
132
+
133
+ # @!attribute [rw] teams
134
+ # Returns the teams
135
+ # @api public
136
+ # @example
137
+ # data.teams #=> #<MLB::GameTeams>
138
+ # @return [GameTeams] the teams
139
+ attribute :teams, GameTeams
140
+
141
+ # @!attribute [rw] venue
142
+ # Returns the venue
143
+ # @api public
144
+ # @example
145
+ # data.venue #=> #<MLB::Venue>
146
+ # @return [Venue] the venue
147
+ attribute :venue, Venue
148
+
149
+ json do
150
+ map "datetime", to: :datetime
151
+ map "teams", to: :teams
152
+ map "venue", to: :venue
153
+ end
154
+ end
155
+ end