Class: MLB::Roster

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

Overview

Provides methods for fetching team rosters from the API

Class Method Summary collapse

Class Method Details

.find(team:, season: nil, sport: Utils::DEFAULT_SPORT_ID) ⇒ Array<RosterEntry>

Finds a team’s roster for a given season and sport

Examples:

MLB::Roster.find(team: 119) #=> [#<MLB::RosterEntry>, ...]

Parameters:

  • team (Team, Integer)

    the team or team ID

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

    the season year (defaults to current year)

  • sport (Sport, Integer) (defaults to: Utils::DEFAULT_SPORT_ID)

    the sport or sport ID

Returns:



18
19
20
21
22
23
24
# File 'lib/mlb/roster.rb', line 18

def self.find(team:, season: nil, sport: Utils::DEFAULT_SPORT_ID)
  season ||= Utils.current_season
  team_id = Utils.extract_id(team)
  params = {season:, sportId: Utils.extract_id(sport)}
  response = CLIENT.get("teams/#{team_id}/roster?#{Utils.build_query(params)}")
  from_json(response).roster
end