module MLBStatsAPI::Games

Constants

POSTGAME_STATUSES
PREGAME_STATUSES

Public Class Methods

postgame_status?(status) click to toggle source
# File lib/mlb_stats_api/games.rb, line 15
def self.postgame_status?(status)
  POSTGAME_STATUSES.match?(status)
end
pregame_status?(status) click to toggle source
# File lib/mlb_stats_api/games.rb, line 11
def self.pregame_status?(status)
  PREGAME_STATUSES.match?(status)
end

Public Instance Methods

boxscore(game_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

def color_feed_timestamps(game_id)

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

end

# 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) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/mlb_stats_api/games.rb, line 92
def win_probability(game_id, timecode: nil)
  get "/game/#{game_id}/winProbability", timecode: timecode
end