Class: MLB::Venues

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

Class Method Summary collapse

Class Method Details

.all(season: Time.now.year, sport: Sport.new(id: 1)) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/mlb/venues.rb', line 11

def self.all(season: Time.now.year, sport: Sport.new(id: 1))
  sport_id = sport.respond_to?(:id) ? sport.id : sport
  params = {sportId: sport_id, season:}
  query_string = URI.encode_www_form(params)
  response = CLIENT.get("venues?#{query_string}")
  venues = from_json(response)
  venues.venues
end

.find(venue, season: Time.now.year, sport: Sport.new(id: 1)) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/mlb/venues.rb', line 20

def self.find(venue, season: Time.now.year, sport: Sport.new(id: 1))
  id = venue.respond_to?(:id) ? venue.id : venue
  sport_id = sport.respond_to?(:id) ? sport.id : sport
  params = {sportId: sport_id, season:}
  query_string = URI.encode_www_form(params)
  response = CLIENT.get("venues/#{id}?#{query_string}")
  venues = from_json(response)
  venues.venues.first
end