Project

mlb

0.03
Low commit activity in last 3 years
A long-lived project that still receives updates
A Ruby interface to the MLB Stats API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.1
 Project Readme

Tests Test Coverage Mutant Linter Maintainability Gem Version

A Ruby interface to the MLB Stats API

Follow

For updates and announcements, follow @sferik.

Installation

Install the gem and add to the application's Gemfile:

bundle add mlb

Or, if Bundler is not being used to manage dependencies:

gem install mlb

Usage

require "mlb"

mets = MLB::Teams.all(season: 2024).last
mets.name                   # => "New York Mets"
mets.short_name             # => "NY Mets"
mets.abbreviation           # => "NYM"
mets.league.name            # => "National League"
mets.spring_league.name     # => "Grapefruit League"
mets.division.name          # => "National League East"
mets.first_year_of_play     # => 1962
mets.location_name          # => "Flushing"
mets.venue.name             # => "Citi Field"

adam = MLB::Players.find(mets.roster.first.player)

adam.full_name              # => "Adam Ottavino"
adam.primary_number         # => 0
adam.primary_position.name  # => "Pitcher"
adam.pitch_hand.description # => "Right"
adam.bat_side.description   # => "Switch"
adam.current_age            # => 38
adam.birth_date.to_s        # => "1985-11-22"
adam.birth_city             # => "New York"
adam.birth_state_province   # => "NY"
adam.birth_country          # => "USA"
adam.draft_year             # => 2006
adam.mlb_debut_date.to_s    # => "2010-05-29"
adam.height                 # => "6' 5\""
adam.weight                 # => 246
adam.active?                # => true

Sponsorship

By contributing to the project, you help:

  1. Maintain the library: Keeping it up-to-date and secure.
  2. Add new features: Enhancements that make your life easier.
  3. Provide support: Faster responses to issues and feature requests.

⭐️ Bonus: Sponsors will get priority support and influence over the project roadmap. We will also list your name or your company's logo on our GitHub page.

Building and maintaining an open-source project like this takes a considerable amount of time and effort. Your sponsorship can help sustain this project. Even a small monthly donation makes a huge difference!

Click here to sponsor this project.

TODO

Many of the MLB Stats API endpoints have not yet been implemented in this library. You can contribute to this library by implementing one or more of these endpoinds. If you are financially unable to sponsor this project, you can contribute code instead.

  • /attendance
  • /baseballStats
  • /draft{prospects}{year}{latest}
  • /eventTypes
  • /game/changes
  • /game/{gamePk}/boxscore
  • /game/{gamePk}/content
  • /game/{gamePk}/contextMetrics
  • /game/{gamePk}/feed/color
  • /game/{gamePk}/feed/color/diffPatch
  • /game/{gamePk}/feed/color/timestamps
  • /game/{gamePk}/feed/live
  • /game/{gamePk}/feed/live/diffPatch
  • /game/{gamePk}/feed/live/timestamps
  • /game/{gamePk}/linescore
  • /game/{gamePk}/playByPlay
  • /game/{gamePk}/winProbability
  • /gamePace
  • /gameStatus
  • /gameTypes
  • /highLow/{orgType}
  • /hitTrajectories
  • /homeRunDerby/{gamePk}{bracket}{pool}
  • /jobTypes
  • /jobs
  • /jobs/datacasters
  • /jobs/officialScorers
  • /jobs/umpires
  • /jobs/umpires/games/{umpireId}
  • /languages
  • /league/{leagueId}/allStarBallot
  • /league/{leagueId}/allStarFinalVote
  • /league/{leagueId}/allStarWriteIns
  • /leagueLeaderTypes
  • /logicalEvents
  • /metrics
  • /people/changes
  • /people/freeAgents
  • /people/{personId}
  • /people/{personId}/stats/game/{gamePk}
  • /pitchCodes
  • /pitchTypes
  • /platforms
  • /positions
  • /reviewReasons
  • /rosterTypes
  • /schedule
  • /schedule/games/tied
  • /schedule/postseason
  • /schedule/postseason/series
  • /schedule/postseason/tuneIn
  • /scheduleEventTypes
  • /situationCodes
  • /sky
  • /standings
  • /standingsTypes
  • /statGroups
  • /statTypes
  • /stats
  • /stats/leaders
  • /stats/streaks
  • /teams/affiliates
  • /teams/history
  • /teams/stats
  • /teams/{teamId}/alumni
  • /teams/{teamId}/coaches
  • /teams/{teamId}/leaders
  • /teams/{teamId}/personnel
  • /teams/{teamId}/roster
  • /teams/{teamId}/stats
  • /windDirection

Development

  1. Checkout and repo:

    git checkout git@github.com:sferik/mlb-ruby.git
    
  2. Enter the repo’s directory:

    cd mlb-ruby
    
  3. Install dependencies via Bundler:

    bin/setup
    
  4. Run the default Rake task to ensure all tests pass:

    bundle exec rake
    
  5. Create a new branch for your feature or bug fix:

    git checkout -b my-new-branch
    

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sferik/mlb-ruby.

Pull requests will only be accepted if they meet all the following criteria:

  1. Code must conform to Standard Ruby. This can be verified with:

    bundle exec rake standard
    
  2. Code must conform to the RuboCop rules. This can be verified with:

    bundle exec rake rubocop
    
  3. 100% C0 code coverage. This can be verified with:

    bundle exec rake test
    
  4. 100% mutation coverage. This can be verified with:

    bundle exec rake mutant
    

License

The gem is available as open source under the terms of the MIT License.