Module: SportsDataApi::Mlb

Extended by:
Request
Defined in:
lib/sports_data_api/mlb.rb,
lib/sports_data_api/mlb/game.rb,
lib/sports_data_api/mlb/team.rb,
lib/sports_data_api/mlb/league.rb,
lib/sports_data_api/mlb/player.rb,
lib/sports_data_api/mlb/division.rb,
lib/sports_data_api/mlb/statistics.rb,
lib/sports_data_api/mlb/merged_stats.rb

Defined Under Namespace

Classes: Division, Exception, Game, League, MergedStats, Player, Statistics, Team

Constant Summary collapse

API_VERSION =
6
BASE_URL =
'https://api.sportradar.us/mlb-%{access_level}%{version}'
DIR =
File.join(File.dirname(__FILE__), 'mlb')
SPORT =
:mlb

Class Method Summary collapse

Methods included from Request

response_json, response_xml, response_xml_xpath

Class Method Details

.daily_schedule(year, month, day) ⇒ Object

Fetches MLB daily schedule for a given date



44
45
46
47
# File 'lib/sports_data_api/mlb.rb', line 44

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) ⇒ Object

Fetches MLB daily summary



51
52
53
54
# File 'lib/sports_data_api/mlb.rb', line 51

def daily_summary(year, month, day)
  response = response_json("/games/#{year}/#{month}/#{day}/summary.json")
  map_model response['league'], 'games', Game
end

.game(game_id) ⇒ Object

Fetches MLB game summary



58
59
60
61
# File 'lib/sports_data_api/mlb.rb', line 58

def game(game_id)
  response = response_json("/games/#{game_id}/summary.json")
  Game.new(response['game'])
end

.leaguesObject

Fetches leagues hierachy



24
25
26
27
# File 'lib/sports_data_api/mlb.rb', line 24

def leagues
  response = response_json('/league/hierarchy.json')
  map_model response, 'leagues', League
end

.season_schedule(year, season) ⇒ Object

Fetches MLB season schedule for a given year and season



37
38
39
40
# File 'lib/sports_data_api/mlb.rb', line 37

def season_schedule(year, season)
  response = response_json("/games/#{year}/#{season}/schedule.json")
  map_model response, 'games', Game
end

.team(team_id) ⇒ Object

Fetches MLB team roster



65
66
67
# File 'lib/sports_data_api/mlb.rb', line 65

def team(team_id)
  Team.new(response_json("/teams/#{team_id}/profile.json"))
end

.teamsObject

Fetches all MLB teams



31
32
33
# File 'lib/sports_data_api/mlb.rb', line 31

def teams
  leagues.flat_map(&:teams)
end