Class: MLB::Teams

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/mlb/teams.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/teams.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("teams?#{query_string}")
  teams = from_json(response)
  teams.teams
end

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



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

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