Module: MLBStatsAPI::Games

Included in:
Client
Defined in:
lib/mlb_stats_api/games.rb

Constant Summary collapse

PREGAME_STATUSES =
/
  Preview|Warmup|Pre-Game|Delayed Start|Scheduled
/x.freeze
POSTGAME_STATUSES =
/Final|Game Over|Postponed|Completed Early/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.postgame_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mlb_stats_api/games.rb', line 15

def self.postgame_status?(status)
  POSTGAME_STATUSES.match?(status)
end

.pregame_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mlb_stats_api/games.rb', line 11

def self.pregame_status?(status)
  PREGAME_STATUSES.match?(status)
end

Instance Method Details

#boxscore(game_id) ⇒ Object



19
20
21
# File 'lib/mlb_stats_api/games.rb', line 19

def boxscore(game_id)
  get "/game/#{game_id}/boxscore"
end

#color_feed(game_id, timecode: nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/mlb_stats_api/games.rb', line 58

def color_feed(game_id, timecode: nil)
  MLBStatsAPI::ColorFeed.new(
    self,
    game_id,
    get("/game/#{game_id}/feed/color", timecode: timecode)
  )
end

#content(game_id, limit: nil) ⇒ Object



23
24
25
# File 'lib/mlb_stats_api/games.rb', line 23

def content(game_id, limit: nil)
  get "/game/#{game_id}/content", highlightLimit: limit
end

#context_metrics(game_id, timecode: nil) ⇒ Object



27
28
29
# File 'lib/mlb_stats_api/games.rb', line 27

def context_metrics(game_id, timecode: nil)
  get "/game/#{game_id}/contextMetrics", timecode: timecode
end

#linescore(game_id) ⇒ Object

def color_feed_timestamps(game_id)

get "/game/#{game_id}/feed/color/timestamps"

end



84
85
86
# File 'lib/mlb_stats_api/games.rb', line 84

def linescore(game_id)
  get "/game/#{game_id}/linescore"
end

#live_feed(game_id, timecode: nil) ⇒ Object

This endpoint can return very large payloads. It is STRONGLY recommended that clients ask for diffs and use “Accept-Encoding: gzip” header.



33
34
35
36
37
38
# File 'lib/mlb_stats_api/games.rb', line 33

def live_feed(game_id, timecode: nil)
  MLBStatsAPI::LiveFeed.new(
    self,
    get("/game/#{game_id}/feed/live", version: '1.1', timecode: timecode)
  )
end

#live_feed_diff(game_id, timecode: nil, snapshot_at: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mlb_stats_api/games.rb', line 40

def live_feed_diff(game_id, timecode: nil, snapshot_at: nil)
  query = { version: '1.1' }

  if timecode
    query[:startTimecode] = timecode
  elsif snapshot_at
    query[:endTimecode] = snapshot_at
  else
    raise ArgumentError, 'Please pass either a timecode or a snapshot.'
  end

  get "/game/#{game_id}/feed/live/diffPatch", query
end

#live_feed_timestamps(game_id) ⇒ Object



54
55
56
# File 'lib/mlb_stats_api/games.rb', line 54

def live_feed_timestamps(game_id)
  get "/game/#{game_id}/feed/live/timestamps", version: '1.1'
end

#play_by_play(game_id, timecode: nil) ⇒ Object



88
89
90
# File 'lib/mlb_stats_api/games.rb', line 88

def play_by_play(game_id, timecode: nil)
  get "/game/#{game_id}/playByPlay", timecode: timecode
end

#win_probability(game_id, timecode: nil) ⇒ Object



92
93
94
# File 'lib/mlb_stats_api/games.rb', line 92

def win_probability(game_id, timecode: nil)
  get "/game/#{game_id}/winProbability", timecode: timecode
end