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,285 @@
1
+ require "shale"
2
+ require_relative "player"
3
+
4
+ module MLB
5
+ # Represents a home run in the derby
6
+ class DerbyHomeRun < Shale::Mapper
7
+ # @!attribute [rw] total_distance
8
+ # Returns the total distance of the home run
9
+ # @api public
10
+ # @example
11
+ # hr.total_distance #=> 450
12
+ # @return [Integer] the distance in feet
13
+ attribute :total_distance, Shale::Type::Integer
14
+
15
+ # @!attribute [rw] launch_speed
16
+ # Returns the launch speed
17
+ # @api public
18
+ # @example
19
+ # hr.launch_speed #=> 112.5
20
+ # @return [Float] the launch speed in mph
21
+ attribute :launch_speed, Shale::Type::Float
22
+
23
+ # @!attribute [rw] launch_angle
24
+ # Returns the launch angle
25
+ # @api public
26
+ # @example
27
+ # hr.launch_angle #=> 28.5
28
+ # @return [Float] the launch angle in degrees
29
+ attribute :launch_angle, Shale::Type::Float
30
+
31
+ # @!attribute [rw] is_bonus_time
32
+ # Returns whether this was hit during bonus time
33
+ # @api public
34
+ # @example
35
+ # hr.bonus_time? #=> false
36
+ # @return [Boolean] whether bonus time
37
+ attribute :is_bonus_time, Shale::Type::Boolean
38
+
39
+ # Returns whether this home run was during bonus time
40
+ #
41
+ # @api public
42
+ # @example
43
+ # hr.bonus_time? #=> false
44
+ # @return [Boolean] whether bonus time
45
+ def bonus_time?
46
+ is_bonus_time
47
+ end
48
+
49
+ json do
50
+ map "totalDistance", to: :total_distance
51
+ map "launchSpeed", to: :launch_speed
52
+ map "launchAngle", to: :launch_angle
53
+ map "isBonusTime", to: :is_bonus_time
54
+ end
55
+ end
56
+
57
+ # Represents a batter's derby performance
58
+ class DerbyBatter < Shale::Mapper
59
+ include Equalizer.new(:id, :seed)
60
+
61
+ # @!attribute [rw] id
62
+ # Returns the player ID
63
+ # @api public
64
+ # @example
65
+ # batter.id #=> 660271
66
+ # @return [Integer] the player ID
67
+ attribute :id, Shale::Type::Integer
68
+
69
+ # @!attribute [rw] full_name
70
+ # Returns the player's full name
71
+ # @api public
72
+ # @example
73
+ # batter.full_name #=> "Shohei Ohtani"
74
+ # @return [String] the full name
75
+ attribute :full_name, Shale::Type::String
76
+
77
+ # @!attribute [rw] link
78
+ # Returns the API link to the player
79
+ # @api public
80
+ # @example
81
+ # batter.link #=> "/api/v1/people/660271"
82
+ # @return [String] the link
83
+ attribute :link, Shale::Type::String
84
+
85
+ # @!attribute [rw] seed
86
+ # Returns the batter's seed
87
+ # @api public
88
+ # @example
89
+ # batter.seed #=> 1
90
+ # @return [Integer] the seed
91
+ attribute :seed, Shale::Type::Integer
92
+
93
+ # @!attribute [rw] home_runs
94
+ # Returns the number of home runs
95
+ # @api public
96
+ # @example
97
+ # batter.home_runs #=> 24
98
+ # @return [Integer] the home run count
99
+ attribute :home_runs, Shale::Type::Integer
100
+
101
+ # @!attribute [rw] is_winner
102
+ # Returns whether this batter won their matchup
103
+ # @api public
104
+ # @example
105
+ # batter.winner? #=> true
106
+ # @return [Boolean] whether winner
107
+ attribute :is_winner, Shale::Type::Boolean
108
+
109
+ # @!attribute [rw] is_bonus
110
+ # Returns whether batter earned bonus time
111
+ # @api public
112
+ # @example
113
+ # batter.bonus? #=> true
114
+ # @return [Boolean] whether bonus earned
115
+ attribute :is_bonus, Shale::Type::Boolean
116
+
117
+ # @!attribute [rw] hits
118
+ # Returns the home run details
119
+ # @api public
120
+ # @example
121
+ # batter.hits #=> [#<MLB::DerbyHomeRun>, ...]
122
+ # @return [Array<DerbyHomeRun>] the home runs
123
+ attribute :hits, DerbyHomeRun, collection: true
124
+
125
+ # Returns whether this batter won their matchup
126
+ #
127
+ # @api public
128
+ # @example
129
+ # batter.winner? #=> true
130
+ # @return [Boolean] whether winner
131
+ def winner?
132
+ is_winner
133
+ end
134
+
135
+ # Returns whether this batter earned bonus time
136
+ #
137
+ # @api public
138
+ # @example
139
+ # batter.bonus? #=> true
140
+ # @return [Boolean] whether bonus earned
141
+ def bonus?
142
+ is_bonus
143
+ end
144
+
145
+ json do
146
+ map "id", to: :id
147
+ map "fullName", to: :full_name
148
+ map "link", to: :link
149
+ map "seed", to: :seed
150
+ map "homeRuns", to: :home_runs
151
+ map "isWinner", to: :is_winner
152
+ map "isBonus", to: :is_bonus
153
+ map "hits", to: :hits
154
+ end
155
+ end
156
+
157
+ # Represents a matchup in the derby round
158
+ class DerbyMatchup < Shale::Mapper
159
+ # @!attribute [rw] matchup_id
160
+ # Returns the matchup ID
161
+ # @api public
162
+ # @example
163
+ # matchup.matchup_id #=> 1
164
+ # @return [Integer] the matchup ID
165
+ attribute :matchup_id, Shale::Type::Integer
166
+
167
+ # @!attribute [rw] top_seed
168
+ # Returns the top seed batter
169
+ # @api public
170
+ # @example
171
+ # matchup.top_seed #=> #<MLB::DerbyBatter>
172
+ # @return [DerbyBatter] the top seed
173
+ attribute :top_seed, DerbyBatter
174
+
175
+ # @!attribute [rw] bottom_seed
176
+ # Returns the bottom seed batter
177
+ # @api public
178
+ # @example
179
+ # matchup.bottom_seed #=> #<MLB::DerbyBatter>
180
+ # @return [DerbyBatter] the bottom seed
181
+ attribute :bottom_seed, DerbyBatter
182
+
183
+ json do
184
+ map "matchupId", to: :matchup_id
185
+ map "topSeed", to: :top_seed
186
+ map "bottomSeed", to: :bottom_seed
187
+ end
188
+ end
189
+
190
+ # Represents a round in the derby
191
+ class DerbyRound < Shale::Mapper
192
+ # @!attribute [rw] round
193
+ # Returns the round number
194
+ # @api public
195
+ # @example
196
+ # round.round #=> 1
197
+ # @return [Integer] the round number
198
+ attribute :round, Shale::Type::Integer
199
+
200
+ # @!attribute [rw] num_batters
201
+ # Returns the number of batters
202
+ # @api public
203
+ # @example
204
+ # round.num_batters #=> 8
205
+ # @return [Integer] the number of batters
206
+ attribute :num_batters, Shale::Type::Integer
207
+
208
+ # @!attribute [rw] matchups
209
+ # Returns the matchups
210
+ # @api public
211
+ # @example
212
+ # round.matchups #=> [#<MLB::DerbyMatchup>, ...]
213
+ # @return [Array<DerbyMatchup>] the matchups
214
+ attribute :matchups, DerbyMatchup, collection: true
215
+
216
+ json do
217
+ map "round", to: :round
218
+ map "numBatters", to: :num_batters
219
+ map "matchups", to: :matchups
220
+ end
221
+ end
222
+
223
+ # Represents home run derby info
224
+ class DerbyInfo < Shale::Mapper
225
+ # @!attribute [rw] id
226
+ # Returns the derby ID
227
+ # @api public
228
+ # @example
229
+ # info.id #=> 511101
230
+ # @return [Integer] the ID
231
+ attribute :id, Shale::Type::Integer
232
+
233
+ # @!attribute [rw] name
234
+ # Returns the derby name
235
+ # @api public
236
+ # @example
237
+ # info.name #=> "2024 Home Run Derby"
238
+ # @return [String] the name
239
+ attribute :name, Shale::Type::String
240
+
241
+ json do
242
+ map "id", to: :id
243
+ map "name", to: :name
244
+ end
245
+ end
246
+
247
+ # Represents home run derby data
248
+ class HomeRunDerby < Shale::Mapper
249
+ # @!attribute [rw] info
250
+ # Returns the derby info
251
+ # @api public
252
+ # @example
253
+ # derby.info #=> #<MLB::DerbyInfo>
254
+ # @return [DerbyInfo] the info
255
+ attribute :info, DerbyInfo
256
+
257
+ # @!attribute [rw] rounds
258
+ # Returns the rounds
259
+ # @api public
260
+ # @example
261
+ # derby.rounds #=> [#<MLB::DerbyRound>, ...]
262
+ # @return [Array<DerbyRound>] the rounds
263
+ attribute :rounds, DerbyRound, collection: true
264
+
265
+ json do
266
+ map "info", to: :info
267
+ map "rounds", to: :rounds
268
+ end
269
+
270
+ # Retrieves home run derby data for a game
271
+ #
272
+ # @api public
273
+ # @example Get derby data for a game
274
+ # MLB::HomeRunDerby.find(game: 511101)
275
+ # @example Get derby data using a ScheduledGame object
276
+ # MLB::HomeRunDerby.find(game: scheduled_game)
277
+ # @param game [Integer, ScheduledGame] the game ID or game object
278
+ # @return [HomeRunDerby] the derby data
279
+ def self.find(game:)
280
+ game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
281
+ response = CLIENT.get("homeRunDerby/#{game_pk}")
282
+ from_json(response)
283
+ end
284
+ end
285
+ end
@@ -0,0 +1,44 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Base class for simple id/description value objects from the MLB Stats API.
6
+ # Similar to CodeDescriptionType but uses 'id' as the identifier field.
7
+ #
8
+ # @api private
9
+ # @abstract Subclass and define specific domain semantics
10
+ class IdDescriptionType < Shale::Mapper
11
+ include Equalizer.new(:id)
12
+
13
+ # @!attribute [rw] id
14
+ # Returns the type identifier
15
+ # @api public
16
+ # @example
17
+ # instance.id #=> "R"
18
+ # @return [String] the type identifier
19
+ attribute :id, Shale::Type::String
20
+
21
+ # @!attribute [rw] description
22
+ # Returns the human-readable description
23
+ # @api public
24
+ # @example
25
+ # instance.description #=> "Regular Season"
26
+ # @return [String] the human-readable description
27
+ attribute :description, Shale::Type::String
28
+
29
+ json do
30
+ map "id", to: :id
31
+ map "description", to: :description
32
+ end
33
+
34
+ # Returns a string representation of the object
35
+ #
36
+ # @api public
37
+ # @example
38
+ # game_type.to_s #=> "R (Regular Season)"
39
+ # @return [String] string representation
40
+ def to_s
41
+ "#{id} (#{description})"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,87 @@
1
+ require "shale"
2
+
3
+ module MLB
4
+ # Represents the score for one side of an inning
5
+ class InningHalfScore < Shale::Mapper
6
+ # @!attribute [rw] runs
7
+ # Returns the runs scored
8
+ # @api public
9
+ # @example
10
+ # inning_half_score.runs #=> 2
11
+ # @return [Integer] the runs
12
+ attribute :runs, Shale::Type::Integer
13
+
14
+ # @!attribute [rw] hits
15
+ # Returns the hits
16
+ # @api public
17
+ # @example
18
+ # inning_half_score.hits #=> 3
19
+ # @return [Integer] the hits
20
+ attribute :hits, Shale::Type::Integer
21
+
22
+ # @!attribute [rw] errors
23
+ # Returns the errors
24
+ # @api public
25
+ # @example
26
+ # inning_half_score.errors #=> 0
27
+ # @return [Integer] the errors
28
+ attribute :errors, Shale::Type::Integer
29
+
30
+ # @!attribute [rw] left_on_base
31
+ # Returns runners left on base
32
+ # @api public
33
+ # @example
34
+ # inning_half_score.left_on_base #=> 1
35
+ # @return [Integer] the left on base
36
+ attribute :left_on_base, Shale::Type::Integer
37
+
38
+ json do
39
+ map "runs", to: :runs
40
+ map "hits", to: :hits
41
+ map "errors", to: :errors
42
+ map "leftOnBase", to: :left_on_base
43
+ end
44
+ end
45
+
46
+ # Represents the score for one inning
47
+ class InningScore < Shale::Mapper
48
+ # @!attribute [rw] num
49
+ # Returns the inning number
50
+ # @api public
51
+ # @example
52
+ # inning_score.num #=> 1
53
+ # @return [Integer] the inning number
54
+ attribute :num, Shale::Type::Integer
55
+
56
+ # @!attribute [rw] ordinal_num
57
+ # Returns the ordinal inning number
58
+ # @api public
59
+ # @example
60
+ # inning_score.ordinal_num #=> "1st"
61
+ # @return [String] the ordinal number
62
+ attribute :ordinal_num, Shale::Type::String
63
+
64
+ # @!attribute [rw] home
65
+ # Returns the home team's score
66
+ # @api public
67
+ # @example
68
+ # inning_score.home #=> #<MLB::InningHalfScore>
69
+ # @return [InningHalfScore] the home score
70
+ attribute :home, InningHalfScore
71
+
72
+ # @!attribute [rw] away
73
+ # Returns the away team's score
74
+ # @api public
75
+ # @example
76
+ # inning_score.away #=> #<MLB::InningHalfScore>
77
+ # @return [InningHalfScore] the away score
78
+ attribute :away, InningHalfScore
79
+
80
+ json do
81
+ map "num", to: :num
82
+ map "ordinalNum", to: :ordinal_num
83
+ map "home", to: :home
84
+ map "away", to: :away
85
+ end
86
+ end
87
+ end
data/lib/mlb/job.rb ADDED
@@ -0,0 +1,58 @@
1
+ require "equalizer"
2
+ require "shale"
3
+ require_relative "player"
4
+
5
+ module MLB
6
+ # Represents a job/role (umpire, datacaster, etc.)
7
+ class Job < Shale::Mapper
8
+ include Equalizer.new(:person)
9
+
10
+ # @!attribute [rw] person
11
+ # Returns the person holding the job
12
+ # @api public
13
+ # @example
14
+ # job.person #=> #<MLB::Player>
15
+ # @return [Player] the person
16
+ attribute :person, Player
17
+
18
+ # @!attribute [rw] jersey_number
19
+ # Returns the jersey number
20
+ # @api public
21
+ # @example
22
+ # job.jersey_number #=> "67"
23
+ # @return [String] the jersey number
24
+ attribute :jersey_number, Shale::Type::String
25
+
26
+ # @!attribute [rw] job
27
+ # Returns the job title
28
+ # @api public
29
+ # @example
30
+ # job.job #=> "Umpire"
31
+ # @return [String] the job title
32
+ attribute :job, Shale::Type::String
33
+
34
+ # @!attribute [rw] job_id
35
+ # Returns the job identifier
36
+ # @api public
37
+ # @example
38
+ # job.job_id #=> "UMPR"
39
+ # @return [String] the job identifier
40
+ attribute :job_id, Shale::Type::String
41
+
42
+ # @!attribute [rw] title
43
+ # Returns the title
44
+ # @api public
45
+ # @example
46
+ # job.title #=> "Umpire"
47
+ # @return [String] the title
48
+ attribute :title, Shale::Type::String
49
+
50
+ json do
51
+ map "person", to: :person
52
+ map "jerseyNumber", to: :jersey_number
53
+ map "job", to: :job
54
+ map "jobId", to: :job_id
55
+ map "title", to: :title
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,39 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a job type
6
+ class JobType < Shale::Mapper
7
+ include Equalizer.new(:code)
8
+
9
+ # @!attribute [rw] code
10
+ # Returns the job type code
11
+ # @api public
12
+ # @example
13
+ # job_type.code #=> "UMPR"
14
+ # @return [String] the job type code
15
+ attribute :code, Shale::Type::String
16
+
17
+ # @!attribute [rw] job
18
+ # Returns the job title
19
+ # @api public
20
+ # @example
21
+ # job_type.job #=> "Umpire"
22
+ # @return [String] the job title
23
+ attribute :job, Shale::Type::String
24
+
25
+ # @!attribute [rw] sort_order
26
+ # Returns the sort order
27
+ # @api public
28
+ # @example
29
+ # job_type.sort_order #=> 1
30
+ # @return [Integer] the sort order
31
+ attribute :sort_order, Shale::Type::Integer
32
+
33
+ json do
34
+ map "code", to: :code
35
+ map "job", to: :job
36
+ map "sortOrder", to: :sort_order
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "job_type"
3
+
4
+ module MLB
5
+ # Provides methods for fetching job types from the API
6
+ #
7
+ # @example Fetch all job types
8
+ # MLB::JobTypes.all #=> [#<MLB::JobType>, ...]
9
+ class JobTypes < Collection
10
+ collection endpoint: "jobTypes", item_type: JobType, collection_name: :job_types
11
+ end
12
+ end
data/lib/mlb/jobs.rb ADDED
@@ -0,0 +1,87 @@
1
+ require "shale"
2
+ require_relative "job"
3
+
4
+ module MLB
5
+ # Provides methods for fetching job data from the API
6
+ class Jobs < Shale::Mapper
7
+ # @!attribute [rw] roster
8
+ # Returns the job roster
9
+ # @api public
10
+ # @example
11
+ # jobs.roster #=> [#<MLB::Job>, ...]
12
+ # @return [Array<Job>] the job roster
13
+ attribute :roster, Job, collection: true
14
+
15
+ json do
16
+ map "roster", to: :roster
17
+ end
18
+
19
+ # Retrieves all umpires
20
+ #
21
+ # @api public
22
+ # @example Get all umpires for the current season
23
+ # MLB::Jobs.umpires
24
+ # @example Get umpires for a specific season
25
+ # MLB::Jobs.umpires(season: 2024)
26
+ # @param season [Integer, nil] the season year (defaults to current year)
27
+ # @return [Array<Job>] the umpires
28
+ def self.umpires(season: nil)
29
+ fetch_jobs("jobs/umpires", season:)
30
+ end
31
+
32
+ # Retrieves all datacasters
33
+ #
34
+ # @api public
35
+ # @example Get all datacasters for the current season
36
+ # MLB::Jobs.datacasters
37
+ # @example Get datacasters for a specific season
38
+ # MLB::Jobs.datacasters(season: 2024)
39
+ # @param season [Integer, nil] the season year (defaults to current year)
40
+ # @return [Array<Job>] the datacasters
41
+ def self.datacasters(season: nil)
42
+ fetch_jobs("jobs/datacasters", season:)
43
+ end
44
+
45
+ # Retrieves all official scorers
46
+ #
47
+ # @api public
48
+ # @example Get all official scorers for the current season
49
+ # MLB::Jobs.official_scorers
50
+ # @example Get official scorers for a specific season
51
+ # MLB::Jobs.official_scorers(season: 2024)
52
+ # @param season [Integer, nil] the season year (defaults to current year)
53
+ # @return [Array<Job>] the official scorers
54
+ def self.official_scorers(season: nil)
55
+ fetch_jobs("jobs/officialScorers", season:)
56
+ end
57
+
58
+ # Retrieves games for a specific umpire
59
+ #
60
+ # @api public
61
+ # @example Get games for an umpire
62
+ # MLB::Jobs.umpire_games(umpire: 427127, season: 2024)
63
+ # @param umpire [Job, Integer] the umpire or umpire ID
64
+ # @param season [Integer, nil] the season year (defaults to current year)
65
+ # @return [Array<Job>] the umpire's game assignments
66
+ def self.umpire_games(umpire:, season: nil)
67
+ umpire_id = umpire.respond_to?(:person) ? umpire.person.id : umpire
68
+ fetch_jobs("jobs/umpires/games/#{umpire_id}", season:)
69
+ end
70
+
71
+ class << self
72
+ private
73
+
74
+ # Fetches jobs from the specified endpoint
75
+ #
76
+ # @api private
77
+ # @param endpoint [String] the API endpoint path
78
+ # @param season [Integer, nil] the season year
79
+ # @return [Array<Job>] the jobs
80
+ def fetch_jobs(endpoint, season:)
81
+ season ||= Utils.current_season
82
+ response = CLIENT.get("#{endpoint}?#{Utils.build_query(season:)}")
83
+ from_json(response).roster
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,48 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a language
6
+ class Language < Shale::Mapper
7
+ include Equalizer.new(:language_id)
8
+
9
+ # @!attribute [rw] language_id
10
+ # Returns the unique language identifier
11
+ # @api public
12
+ # @example
13
+ # language.language_id #=> 1
14
+ # @return [Integer] the unique language identifier
15
+ attribute :language_id, Shale::Type::Integer
16
+
17
+ # @!attribute [rw] language_code
18
+ # Returns the language code
19
+ # @api public
20
+ # @example
21
+ # language.language_code #=> "en"
22
+ # @return [String] the language code
23
+ attribute :language_code, Shale::Type::String
24
+
25
+ # @!attribute [rw] name
26
+ # Returns the language name
27
+ # @api public
28
+ # @example
29
+ # language.name #=> "English"
30
+ # @return [String] the language name
31
+ attribute :name, Shale::Type::String
32
+
33
+ # @!attribute [rw] locale
34
+ # Returns the locale identifier
35
+ # @api public
36
+ # @example
37
+ # language.locale #=> "en_US"
38
+ # @return [String] the locale identifier
39
+ attribute :locale, Shale::Type::String
40
+
41
+ json do
42
+ map "languageId", to: :language_id
43
+ map "languageCode", to: :language_code
44
+ map "name", to: :name
45
+ map "locale", to: :locale
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "language"
3
+
4
+ module MLB
5
+ # Provides methods for fetching languages from the API
6
+ #
7
+ # @example Fetch all languages
8
+ # MLB::Languages.all #=> [#<MLB::Language>, ...]
9
+ class Languages < Collection
10
+ collection endpoint: "languages", item_type: Language, collection_name: :languages
11
+ end
12
+ end