mlb 0.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/LICENSE.txt +1 -1
- data/README.md +329 -32
- data/lib/mlb/affiliates.rb +28 -0
- data/lib/mlb/alumni.rb +30 -0
- data/lib/mlb/attendance.rb +28 -0
- data/lib/mlb/attendance_record.rb +157 -0
- data/lib/mlb/award.rb +126 -0
- data/lib/mlb/awards.rb +32 -0
- data/lib/mlb/baseball_stat.rb +65 -0
- data/lib/mlb/baseball_stats.rb +12 -0
- data/lib/mlb/boxscore.rb +81 -0
- data/lib/mlb/boxscore_team_stats.rb +210 -0
- data/lib/mlb/client.rb +71 -1
- data/lib/mlb/coaches.rb +28 -0
- data/lib/mlb/code_description_type.rb +45 -0
- data/lib/mlb/collection.rb +48 -0
- data/lib/mlb/comparable_by_attribute.rb +56 -0
- data/lib/mlb/conference.rb +39 -0
- data/lib/mlb/conferences.rb +33 -0
- data/lib/mlb/connection.rb +130 -7
- data/lib/mlb/context_metrics.rb +90 -0
- data/lib/mlb/division.rb +26 -6
- data/lib/mlb/divisions.rb +24 -18
- data/lib/mlb/draft.rb +83 -0
- data/lib/mlb/draft_pick.rb +155 -0
- data/lib/mlb/error_handler.rb +21 -1
- data/lib/mlb/errors/bad_gateway.rb +6 -1
- data/lib/mlb/errors/bad_request.rb +1 -0
- data/lib/mlb/errors/client_error.rb +1 -0
- data/lib/mlb/errors/connection_exception.rb +1 -0
- data/lib/mlb/errors/error.rb +1 -0
- data/lib/mlb/errors/forbidden.rb +1 -0
- data/lib/mlb/errors/gateway_timeout.rb +6 -1
- data/lib/mlb/errors/gone.rb +1 -0
- data/lib/mlb/errors/http_error.rb +22 -2
- data/lib/mlb/errors/internal_server_error.rb +1 -0
- data/lib/mlb/errors/network_error.rb +6 -1
- data/lib/mlb/errors/not_acceptable.rb +1 -0
- data/lib/mlb/errors/not_found.rb +1 -0
- data/lib/mlb/errors/payload_too_large.rb +1 -0
- data/lib/mlb/errors/retryable.rb +15 -0
- data/lib/mlb/errors/server_error.rb +1 -0
- data/lib/mlb/errors/service_unavailable.rb +6 -1
- data/lib/mlb/errors/too_many_redirects.rb +1 -0
- data/lib/mlb/errors/too_many_requests.rb +6 -1
- data/lib/mlb/errors/unauthorized.rb +1 -0
- data/lib/mlb/errors/unprocessable_entity.rb +1 -0
- data/lib/mlb/event_type.rb +61 -0
- data/lib/mlb/event_types.rb +12 -0
- data/lib/mlb/free_agent.rb +78 -0
- data/lib/mlb/free_agents.rb +34 -0
- data/lib/mlb/game_changes.rb +87 -0
- data/lib/mlb/game_content.rb +251 -0
- data/lib/mlb/game_data.rb +155 -0
- data/lib/mlb/game_pace.rb +173 -0
- data/lib/mlb/game_status.rb +94 -0
- data/lib/mlb/game_statuses.rb +12 -0
- data/lib/mlb/game_type.rb +98 -0
- data/lib/mlb/game_types.rb +12 -0
- data/lib/mlb/handedness.rb +30 -9
- data/lib/mlb/high_low.rb +121 -0
- data/lib/mlb/hit_trajectories.rb +12 -0
- data/lib/mlb/hit_trajectory.rb +6 -0
- data/lib/mlb/home_run_derby.rb +285 -0
- data/lib/mlb/id_description_type.rb +44 -0
- data/lib/mlb/inning_score.rb +87 -0
- data/lib/mlb/job.rb +58 -0
- data/lib/mlb/job_type.rb +39 -0
- data/lib/mlb/job_types.rb +12 -0
- data/lib/mlb/jobs.rb +87 -0
- data/lib/mlb/language.rb +48 -0
- data/lib/mlb/languages.rb +12 -0
- data/lib/mlb/leader.rb +79 -0
- data/lib/mlb/leaders.rb +68 -0
- data/lib/mlb/league.rb +97 -14
- data/lib/mlb/league_leader_type.rb +21 -0
- data/lib/mlb/league_leader_types.rb +12 -0
- data/lib/mlb/leagues.rb +24 -18
- data/lib/mlb/linescore.rb +342 -0
- data/lib/mlb/linescore_teams.rb +89 -0
- data/lib/mlb/live_feed.rb +130 -0
- data/lib/mlb/logical_event.rb +17 -0
- data/lib/mlb/logical_events.rb +12 -0
- data/lib/mlb/metric.rb +48 -0
- data/lib/mlb/metrics.rb +12 -0
- data/lib/mlb/people_changes.rb +34 -0
- data/lib/mlb/personnel.rb +28 -0
- data/lib/mlb/pitch_code.rb +90 -0
- data/lib/mlb/pitch_codes.rb +12 -0
- data/lib/mlb/pitch_type.rb +6 -0
- data/lib/mlb/pitch_types.rb +12 -0
- data/lib/mlb/platform.rb +30 -0
- data/lib/mlb/platforms.rb +12 -0
- data/lib/mlb/play.rb +300 -0
- data/lib/mlb/play_by_play.rb +52 -0
- data/lib/mlb/player.rb +186 -0
- data/lib/mlb/player_game_stats.rb +350 -0
- data/lib/mlb/player_stat.rb +70 -0
- data/lib/mlb/players.rb +42 -11
- data/lib/mlb/position.rb +68 -0
- data/lib/mlb/positions.rb +12 -0
- data/lib/mlb/postseason_schedule.rb +41 -0
- data/lib/mlb/postseason_series.rb +54 -0
- data/lib/mlb/redirect_handler.rb +80 -21
- data/lib/mlb/request_builder.rb +33 -2
- data/lib/mlb/review_reason.rb +6 -0
- data/lib/mlb/review_reasons.rb +12 -0
- data/lib/mlb/roster.rb +16 -12
- data/lib/mlb/roster_entry.rb +38 -0
- data/lib/mlb/roster_type.rb +39 -0
- data/lib/mlb/roster_types.rb +12 -0
- data/lib/mlb/schedule.rb +33 -0
- data/lib/mlb/schedule_date.rb +37 -0
- data/lib/mlb/schedule_event_type.rb +25 -0
- data/lib/mlb/schedule_event_types.rb +12 -0
- data/lib/mlb/scheduled_game.rb +321 -0
- data/lib/mlb/season.rb +74 -0
- data/lib/mlb/season_date_info.rb +4 -0
- data/lib/mlb/seasons.rb +36 -0
- data/lib/mlb/single_team_stats.rb +33 -0
- data/lib/mlb/situation_code.rb +116 -0
- data/lib/mlb/situation_codes.rb +12 -0
- data/lib/mlb/skies.rb +12 -0
- data/lib/mlb/sky.rb +6 -0
- data/lib/mlb/sport.rb +18 -5
- data/lib/mlb/sport_players.rb +30 -0
- data/lib/mlb/sports.rb +17 -7
- data/lib/mlb/standings.rb +47 -0
- data/lib/mlb/standings_record.rb +108 -0
- data/lib/mlb/standings_type.rb +25 -0
- data/lib/mlb/standings_types.rb +12 -0
- data/lib/mlb/stat_group.rb +21 -0
- data/lib/mlb/stat_groups.rb +12 -0
- data/lib/mlb/stat_type.rb +21 -0
- data/lib/mlb/stat_types.rb +12 -0
- data/lib/mlb/stat_values.rb +158 -0
- data/lib/mlb/stats.rb +41 -0
- data/lib/mlb/status.rb +17 -0
- data/lib/mlb/streaks.rb +184 -0
- data/lib/mlb/team.rb +66 -7
- data/lib/mlb/team_history.rb +28 -0
- data/lib/mlb/team_leader.rb +59 -0
- data/lib/mlb/team_leaders.rb +45 -0
- data/lib/mlb/team_record.rb +285 -0
- data/lib/mlb/team_stat.rb +50 -0
- data/lib/mlb/team_stats.rb +52 -0
- data/lib/mlb/teams.rb +28 -18
- data/lib/mlb/tied_games.rb +32 -0
- data/lib/mlb/transaction.rb +128 -0
- data/lib/mlb/transactions.rb +11 -6
- data/lib/mlb/uniforms.rb +97 -0
- data/lib/mlb/utils.rb +45 -0
- data/lib/mlb/venue.rb +10 -0
- data/lib/mlb/venues.rb +28 -18
- data/lib/mlb/version.rb +2 -1
- data/lib/mlb/win_probability.rb +64 -0
- data/lib/mlb/wind_direction.rb +6 -0
- data/lib/mlb/wind_directions.rb +12 -0
- data/lib/mlb.rb +64 -0
- data/sig/equalizer.rbs +3 -0
- data/sig/mlb.rbs +1972 -103
- data/sig/shale.rbs +29 -0
- metadata +137 -14
|
@@ -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
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require "shale"
|
|
2
|
+
require_relative "sport"
|
|
3
|
+
|
|
4
|
+
module MLB
|
|
5
|
+
# Represents game pace statistics
|
|
6
|
+
class GamePaceStats < Shale::Mapper
|
|
7
|
+
# @!attribute [rw] hits_per_9inn
|
|
8
|
+
# Returns hits per 9 innings
|
|
9
|
+
# @api public
|
|
10
|
+
# @example
|
|
11
|
+
# stats.hits_per_9inn #=> 16.63
|
|
12
|
+
# @return [Float] the hits per 9 innings
|
|
13
|
+
attribute :hits_per_9inn, Shale::Type::Float
|
|
14
|
+
|
|
15
|
+
# @!attribute [rw] runs_per_9inn
|
|
16
|
+
# Returns runs per 9 innings
|
|
17
|
+
# @api public
|
|
18
|
+
# @example
|
|
19
|
+
# stats.runs_per_9inn #=> 8.91
|
|
20
|
+
# @return [Float] the runs per 9 innings
|
|
21
|
+
attribute :runs_per_9inn, Shale::Type::Float
|
|
22
|
+
|
|
23
|
+
# @!attribute [rw] pitches_per_9inn
|
|
24
|
+
# Returns pitches per 9 innings
|
|
25
|
+
# @api public
|
|
26
|
+
# @example
|
|
27
|
+
# stats.pitches_per_9inn #=> 296.2
|
|
28
|
+
# @return [Float] the pitches per 9 innings
|
|
29
|
+
attribute :pitches_per_9inn, Shale::Type::Float
|
|
30
|
+
|
|
31
|
+
# @!attribute [rw] hits_per_game
|
|
32
|
+
# Returns hits per game
|
|
33
|
+
# @api public
|
|
34
|
+
# @example
|
|
35
|
+
# stats.hits_per_game #=> 16.39
|
|
36
|
+
# @return [Float] the hits per game
|
|
37
|
+
attribute :hits_per_game, Shale::Type::Float
|
|
38
|
+
|
|
39
|
+
# @!attribute [rw] runs_per_game
|
|
40
|
+
# Returns runs per game
|
|
41
|
+
# @api public
|
|
42
|
+
# @example
|
|
43
|
+
# stats.runs_per_game #=> 8.79
|
|
44
|
+
# @return [Float] the runs per game
|
|
45
|
+
attribute :runs_per_game, Shale::Type::Float
|
|
46
|
+
|
|
47
|
+
# @!attribute [rw] pitches_per_game
|
|
48
|
+
# Returns pitches per game
|
|
49
|
+
# @api public
|
|
50
|
+
# @example
|
|
51
|
+
# stats.pitches_per_game #=> 292.1
|
|
52
|
+
# @return [Float] the pitches per game
|
|
53
|
+
attribute :pitches_per_game, Shale::Type::Float
|
|
54
|
+
|
|
55
|
+
# @!attribute [rw] total_games
|
|
56
|
+
# Returns total games
|
|
57
|
+
# @api public
|
|
58
|
+
# @example
|
|
59
|
+
# stats.total_games #=> 2429
|
|
60
|
+
# @return [Integer] the total games
|
|
61
|
+
attribute :total_games, Shale::Type::Integer
|
|
62
|
+
|
|
63
|
+
# @!attribute [rw] total_innings_played
|
|
64
|
+
# Returns total innings played
|
|
65
|
+
# @api public
|
|
66
|
+
# @example
|
|
67
|
+
# stats.total_innings_played #=> 21626.5
|
|
68
|
+
# @return [Float] the total innings
|
|
69
|
+
attribute :total_innings_played, Shale::Type::Float
|
|
70
|
+
|
|
71
|
+
# @!attribute [rw] total_hits
|
|
72
|
+
# Returns total hits
|
|
73
|
+
# @api public
|
|
74
|
+
# @example
|
|
75
|
+
# stats.total_hits #=> 39823
|
|
76
|
+
# @return [Integer] the total hits
|
|
77
|
+
attribute :total_hits, Shale::Type::Integer
|
|
78
|
+
|
|
79
|
+
# @!attribute [rw] total_runs
|
|
80
|
+
# Returns total runs
|
|
81
|
+
# @api public
|
|
82
|
+
# @example
|
|
83
|
+
# stats.total_runs #=> 21343
|
|
84
|
+
# @return [Integer] the total runs
|
|
85
|
+
attribute :total_runs, Shale::Type::Integer
|
|
86
|
+
|
|
87
|
+
# @!attribute [rw] total_pitches
|
|
88
|
+
# Returns total pitches
|
|
89
|
+
# @api public
|
|
90
|
+
# @example
|
|
91
|
+
# stats.total_pitches #=> 709511
|
|
92
|
+
# @return [Integer] the total pitches
|
|
93
|
+
attribute :total_pitches, Shale::Type::Integer
|
|
94
|
+
|
|
95
|
+
# @!attribute [rw] time_per_game
|
|
96
|
+
# Returns average time per game
|
|
97
|
+
# @api public
|
|
98
|
+
# @example
|
|
99
|
+
# stats.time_per_game #=> "02:38:44"
|
|
100
|
+
# @return [String] the time per game
|
|
101
|
+
attribute :time_per_game, Shale::Type::String
|
|
102
|
+
|
|
103
|
+
# @!attribute [rw] time_per_pitch
|
|
104
|
+
# Returns average time per pitch
|
|
105
|
+
# @api public
|
|
106
|
+
# @example
|
|
107
|
+
# stats.time_per_pitch #=> "00:00:32"
|
|
108
|
+
# @return [String] the time per pitch
|
|
109
|
+
attribute :time_per_pitch, Shale::Type::String
|
|
110
|
+
|
|
111
|
+
# @!attribute [rw] season
|
|
112
|
+
# Returns the season
|
|
113
|
+
# @api public
|
|
114
|
+
# @example
|
|
115
|
+
# stats.season #=> "2024"
|
|
116
|
+
# @return [String] the season
|
|
117
|
+
attribute :season, Shale::Type::String
|
|
118
|
+
|
|
119
|
+
# @!attribute [rw] sport
|
|
120
|
+
# Returns the sport
|
|
121
|
+
# @api public
|
|
122
|
+
# @example
|
|
123
|
+
# stats.sport #=> #<MLB::Sport>
|
|
124
|
+
# @return [Sport] the sport
|
|
125
|
+
attribute :sport, Sport
|
|
126
|
+
|
|
127
|
+
json do
|
|
128
|
+
map "hitsPer9Inn", to: :hits_per_9inn
|
|
129
|
+
map "runsPer9Inn", to: :runs_per_9inn
|
|
130
|
+
map "pitchesPer9Inn", to: :pitches_per_9inn
|
|
131
|
+
map "hitsPerGame", to: :hits_per_game
|
|
132
|
+
map "runsPerGame", to: :runs_per_game
|
|
133
|
+
map "pitchesPerGame", to: :pitches_per_game
|
|
134
|
+
map "totalGames", to: :total_games
|
|
135
|
+
map "totalInningsPlayed", to: :total_innings_played
|
|
136
|
+
map "totalHits", to: :total_hits
|
|
137
|
+
map "totalRuns", to: :total_runs
|
|
138
|
+
map "totalPitches", to: :total_pitches
|
|
139
|
+
map "timePerGame", to: :time_per_game
|
|
140
|
+
map "timePerPitch", to: :time_per_pitch
|
|
141
|
+
map "season", to: :season
|
|
142
|
+
map "sport", to: :sport
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Provides methods for fetching game pace data from the API
|
|
147
|
+
class GamePace < Shale::Mapper
|
|
148
|
+
# @!attribute [rw] sports
|
|
149
|
+
# Returns the sports game pace data
|
|
150
|
+
# @api public
|
|
151
|
+
# @example
|
|
152
|
+
# game_pace.sports #=> [#<MLB::GamePaceStats>, ...]
|
|
153
|
+
# @return [Array<GamePaceStats>] the sports data
|
|
154
|
+
attribute :sports, GamePaceStats, collection: true
|
|
155
|
+
|
|
156
|
+
json do
|
|
157
|
+
map "sports", to: :sports
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Retrieves game pace statistics for a season
|
|
161
|
+
#
|
|
162
|
+
# @api public
|
|
163
|
+
# @example Get game pace for 2024
|
|
164
|
+
# MLB::GamePace.find(season: 2024)
|
|
165
|
+
# @param season [Integer, nil] the season year (defaults to current year)
|
|
166
|
+
# @return [GamePaceStats] the game pace stats for MLB
|
|
167
|
+
def self.find(season: nil)
|
|
168
|
+
season ||= Utils.current_season
|
|
169
|
+
response = CLIENT.get("gamePace?#{Utils.build_query(season:)}")
|
|
170
|
+
from_json(response).sports.first
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|