Class: MLB::Leagues

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

Class Method Summary collapse

Class Method Details

.all(sport: Sport.new(id: 1)) ⇒ Object



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

def self.all(sport: Sport.new(id: 1))
  sport_id = sport.respond_to?(:id) ? sport.id : sport
  params = {sportId: sport_id}
  query_string = URI.encode_www_form(params)
  response = CLIENT.get("leagues?#{query_string}")
  leagues = from_json(response)
  leagues.leagues.sort!
end

.find(league, sport: Sport.new(id: 1)) ⇒ Object



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

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