Class: MLB::Venues

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

Overview

Collection of venues from the MLB Stats API

Class Method Summary collapse

Class Method Details

.all(season: nil, sport: Utils::DEFAULT_SPORT_ID) ⇒ Array<Venue>

Retrieves all venues

Examples:

MLB::Venues.all


17
18
19
20
21
22
# File 'lib/mlb/venues.rb', line 17

def self.all(season: nil, sport: Utils::DEFAULT_SPORT_ID)
  season ||= Utils.current_season
  params = {sportId: Utils.extract_id(sport), season:}
  response = CLIENT.get("venues?#{Utils.build_query(params)}")
  from_json(response).venues
end

.find(venue, season: nil, sport: Utils::DEFAULT_SPORT_ID) ⇒ Venue?

Finds a venue by ID

Examples:

MLB::Venues.find(15)


33
34
35
36
37
38
# File 'lib/mlb/venues.rb', line 33

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