Class: MLB::FreeAgents

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

Overview

Provides methods for fetching free agent data from the API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#free_agentsArray<FreeAgent>

Returns the free agents

Examples:

free_agents.free_agents #=> [#<MLB::FreeAgent>, ...]

Returns:



13
# File 'lib/mlb/free_agents.rb', line 13

attribute :free_agents, FreeAgent, collection: true

Class Method Details

.all(season: nil) ⇒ Array<FreeAgent>

Retrieves all free agents for a season

Examples:

Get free agents for the current season

MLB::FreeAgents.all

Get free agents for a specific season

MLB::FreeAgents.all(season: 2024)

Parameters:

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

    the season year (defaults to current year)

Returns:



28
29
30
31
32
# File 'lib/mlb/free_agents.rb', line 28

def self.all(season: nil)
  season ||= Utils.current_season
  response = CLIENT.get("people/freeAgents?#{Utils.build_query(season:)}")
  from_json(response).free_agents
end