Class: MLB::GameChanges

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/mlb/game_changes.rb

Overview

Fetches games that have been modified since a given timestamp

This endpoint is useful for efficiently polling for game updates rather than fetching all game data repeatedly.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#datesArray<ChangedGameDate>

Returns dates containing changed games

Examples:

response.dates #=> [#<MLB::ChangedGameDate>, ...]

Returns:



56
# File 'lib/mlb/game_changes.rb', line 56

attribute :dates, ChangedGameDate, collection: true

Class Method Details

.since(updated_since:, sport_id: nil, season: nil, game_type: nil) ⇒ Array<ChangedGame>

Retrieves games modified since the given timestamp

Examples:

Basic usage with ISO 8601 timestamp

MLB::GameChanges.since(updated_since: "2024-06-15T12:00:00Z")

Filter by sport (1 = MLB)

MLB::GameChanges.since(updated_since: "2024-06-15T12:00:00Z", sport_id: 1)

Filter by season and game type

MLB::GameChanges.since(updated_since: timestamp, season: 2024, game_type: "R")

Parameters:

  • updated_since (#to_s)

    timestamp to check changes from (ISO 8601 format)

  • sport_id (Integer, nil) (defaults to: nil)

    filter by sport ID

  • season (Integer, nil) (defaults to: nil)

    filter by season year

  • game_type (String, nil) (defaults to: nil)

    filter by game type (R=Regular, P=Postseason, etc.)

Returns:

  • (Array<ChangedGame>)

    games modified since the timestamp



76
77
78
79
80
81
82
83
84
85
# File 'lib/mlb/game_changes.rb', line 76

def self.since(updated_since:, sport_id: nil, season: nil, game_type: nil)
  params = {
    updatedSince: updated_since.to_s,
    sportId: sport_id,
    season: season,
    gameType: game_type
  }.compact
  response = CLIENT.get("game/changes?#{URI.encode_www_form(params)}")
  from_json(response).dates.flat_map(&:games)
end