module SportsDataApi::Mlb

Constants

API_VERSION
BASE_URL
DIR
SPORT

Public Class Methods

daily_schedule(year, month, day) click to toggle source

Fetches MLB daily schedule for a given date

# File lib/sports_data_api/mlb.rb, line 41
def daily_schedule(year, month, day)
  response = response_json("/games/#{year}/#{month}/#{day}/schedule.json")
  map_model response, 'games', Game
end
daily_summary(year, month, day) click to toggle source

Fetches MLB daily summary

# File lib/sports_data_api/mlb.rb, line 48
def daily_summary(year, month, day)
  response = response_json("/games/#{year}/#{month}/#{day}/summary.json")
  map_model response['league'], 'games', Game, 'game'
end
game(game_id) click to toggle source

Fetches MLB game summary

# File lib/sports_data_api/mlb.rb, line 55
def game(game_id)
  response = response_json("/games/#{game_id}/summary.json")
  Game.new(response['game'])
end
leagues() click to toggle source

Fetches leagues hierachy

# File lib/sports_data_api/mlb.rb, line 21
def leagues
  response = response_json('/league/hierarchy.json')
  map_model response, 'leagues', League
end
season_schedule(year, season) click to toggle source

Fetches MLB season schedule for a given year and season

# File lib/sports_data_api/mlb.rb, line 34
def season_schedule(year, season)
  response = response_json("/games/#{year}/#{season}/schedule.json")
  map_model response, 'games', Game
end
team(team_id) click to toggle source

Fetches MLB team roster

# File lib/sports_data_api/mlb.rb, line 62
def team(team_id)
  Team.new(response_json("/teams/#{team_id}/profile.json"))
end
teams() click to toggle source

Fetches all MLB teams

# File lib/sports_data_api/mlb.rb, line 28
def teams
  leagues.flat_map(&:teams)
end

Private Class Methods

map_model(json, key, klass, data_key = nil) click to toggle source
# File lib/sports_data_api/mlb.rb, line 68
def map_model(json, key, klass, data_key = nil)
  json.fetch(key, []).map do |data|
    klass.new(data_key ? data[data_key] : data)
  end
end