Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 3.5 KB

README.rdoc

File metadata and controls

77 lines (55 loc) · 3.5 KB

Gameday API

The Gameday API allows you to fetch live statistical data from MLB.com servers. This is the same data that is used by the Gameday application available on MLB.com. Another project on GitHub uses the Gameday API to create an application that allows users to view linescore, boxscore, and play-by-play data for any selected game. That project is called Baseball Tracker. There is a hosted version of Baseball Tracker available at baseballstatz.heroku.com

Also, be sure to check out my latest related project, the PitchFX Analyzer at fisherbaseball.com

Requirements

Usage

You can verify that you have a working version of Gameday API with proper Internet connectivity by running the included unit tests. After downloading Gameday API, navigate to the test/unit_tests directory and open a command shell there. Run all of the tests by running the all_tests.rb suite:

ruby all_tests.rb

This should run the unit tests and report 0 failures and 0 errors.

Below are some examples of how you might use Gameday API. However this shows only a very small percentage of the API’s functionality. You can access a very deep set of live statistics through Gameday API. There are additional examples of its usage available in the test directory of Gameday API.

For each of these examples you should be in an IRB session opened in the lib directory of Gameday API.

Create a ‘boxscore.html’ file containing the boxscore for the Detroit Tigers game played on 9/15/2009.

require 'team'
team = Team.new('det')
games = team.games_for_date('2009', '09', '15')
games[0].get_boxscore.dump_to_file

Print linescores for all games played on 9/15/2009

require 'game'
games = Game.find_by_date('2009','09','15')
games.each do |game| 
   puts game.print_linescore
   puts
end

Print all starting pitchers used by Detroit in 2009

require 'team'
team = Team.new('det')
games = team.all_games('2009')
games.each do |game|
   starters = game.get_starting_pitchers
   if game.home_team_abbrev == 'det'
      puts 'Home: ' + starters[1]['name']
   else
      puts 'Visitors: ' + starters[0]['name']
   end
end

Print the names of all hitters that Detroit used in the leadoff spot during 2009.

require 'team'
team = Team.new('det')
hitters = team.get_leadoff_hitters_by_year('2009')
hitters.each do |hitter|
   puts hitter.batter_name
end

Download all Gameday files for a specified year and month

require 'data_downloader'
downloader = DataDownloader.new
downloader.download_all_for_month(2009,5)

Usage Restriction

All documents fetched by this API clearly state: Copyright 2009 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here gdx.mlb.com/components/copyright.txt

Which furthermore states: The accounts, descriptions, data and presentation in the referring page (the “Materials”) are proprietary content of MLB Advanced Media, L.P (“MLBAM”).<br />Only individual, non-commercial, non-bulk use of the Materials is permitted and any other use of the Materials is prohibited without prior written authorization from MLBAM.<br />Authorized users of the Materials are prohibited from using the Materials in any commercial manner other than as expressly authorized by MLBAM.

Naturally, these terms are passed on to any who use this API. It is your responsibility to abide by them.