mlb_stats_api 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0310afaf13567d04d2278cdc02d32b92325007372f495667c8a07b84ed91f352
4
- data.tar.gz: e4591473135877957ae3d65e761a60844ca37bbdb48a957cde3f7d42b5a464ac
3
+ metadata.gz: c4a7b94d68493363d447c18a5e8d56994508b1a1b6e77a7136e83e07193b6e2b
4
+ data.tar.gz: 8baf4f5bae5b634f50bbe3bb0c08ec93fd7ad87bd003b645185dc8e36b1da090
5
5
  SHA512:
6
- metadata.gz: eb93edf79ea1fc1f808cfb77dc7a8726902583f1b9dd9382dbe3dec471ec18d4d2059cb2045cc6ab358162a3f97a34a4634ce522aab8a68317c9ab4a591f724b
7
- data.tar.gz: 49d68238ec47bba5c7edf2ca62cab4279b7383520a911e2ffb0bcd0eb7c0dd0b0a784f075b6408c3263dda111f7a35db64eee9a0fc0ee7b6bfac433c21d93a26
6
+ metadata.gz: c183c8ba29eac57b6c8487dce7300f547db057c0e33873a831d6d8c365d3493e26f8c8236a9f80efef401be73b88504695ebe9b9a51b566caeb3aad613efca80
7
+ data.tar.gz: 4ec7c69b0d19650a42629bd4d914a4c24d5574fa325f4285fa953def77d7e320a09464a2a9e4dbbb44836841b135070e15f19ba2f963b7a0bfe39795d7ae1aed
@@ -1,23 +1,9 @@
1
1
  AllCops:
2
- Include:
3
- - Rakefile
4
- - Gemfile
5
2
  TargetRubyVersion: 2.5
6
3
 
7
4
  Layout/MultilineMethodCallIndentation:
8
5
  EnforcedStyle: indented
9
6
 
10
- Metrics/AbcSize:
11
- Enabled: false
12
-
13
- Metrics/ClassLength:
14
- Max: 100
15
-
16
- Metrics/CyclomaticComplexity:
17
- Enabled: false
18
-
19
- Metrics/MethodLength:
20
- Max: 15
21
-
22
- Style/Documentation:
23
- Enabled: false
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*'
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ script: bundle exec rake
3
4
  rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1
5
+ - 2.5.1
6
+ before_install: gem install bundler -v 1.16.6
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # MlbStatsApi
1
+ [![Build Status](https://travis-ci.com/Fustrate/mlb_stats_api.svg?branch=master)](https://travis-ci.com/Fustrate/mlb_stats_api)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mlb_stats_api`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ # MLBStatsAPI
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A ruby gem to interact with the [MLB Stats API](http://statsapi.mlb.com/docs/).
6
6
 
7
7
  ## Installation
8
8
 
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mlb_stats_api.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fustrate/mlb_stats_api.
36
36
 
37
37
  ## License
38
38
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'mlb_stats_api'
@@ -8,9 +8,9 @@ require 'mlb_stats_api/errors'
8
8
  require 'mlb_stats_api/version'
9
9
 
10
10
  require 'mlb_stats_api/base'
11
+ require 'mlb_stats_api/color_feed'
11
12
  require 'mlb_stats_api/live_feed'
12
13
  require 'mlb_stats_api/team'
13
- require 'mlb_stats_api/venue'
14
14
 
15
15
  require 'mlb_stats_api/conferences'
16
16
  require 'mlb_stats_api/config'
@@ -47,17 +47,24 @@ module MLBStatsAPI
47
47
  def get(endpoint, query = {})
48
48
  url = "/api/v#{query.delete(:version) || DEFAULT_VERSION}#{endpoint}"
49
49
 
50
- query.reject! { |_, v| v.nil? }
50
+ args = normalize_query_args(query)
51
51
 
52
- @logger.info("Fetching URL: #{url} Query: #{query.inspect}")
52
+ @logger.info "Fetching URL: #{url} Query: #{args.inspect}"
53
53
 
54
- response = self.class.get url, query: query.merge(t: Time.now.to_i)
54
+ response = self.class.get url, query: args.merge(t: Time.now.to_i)
55
55
 
56
56
  raise_exception(response) unless response.code == 200
57
57
 
58
58
  response.parsed_response
59
59
  end
60
60
 
61
+ def normalize_query_args(query)
62
+ query
63
+ .reject { |_, v| v.nil? }
64
+ .map { |key, val| [key, val.is_a?(Array) ? val.join(',') : val] }
65
+ .to_h
66
+ end
67
+
61
68
  def load(key, options = {})
62
69
  value = @cache.load(key)
63
70
 
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ class ColorFeed < Base
5
+ attr_reader :id
6
+
7
+ def initialize(api, data)
8
+ @api = api
9
+ @data = data
10
+
11
+ # If we need to nuke and start over, keep this piece
12
+ @id = data['game_pk']
13
+ end
14
+
15
+ def items
16
+ @data['items']
17
+ end
18
+
19
+ def reload!
20
+ @data = @api.get("/game/#{@id}/feed/color")
21
+
22
+ true
23
+ rescue Net::OpenTimeout
24
+ false
25
+ end
26
+
27
+ # The color feed doesn't use diffs, even though there's an endpoint for it.
28
+ alias update! reload!
29
+
30
+ # def timestamps
31
+ # @api.color_feed_timestamps(@id)
32
+ # end
33
+
34
+ # def update!
35
+ # return reload! unless @data
36
+
37
+ # diffs = @api.color_feed_diff(
38
+ # @data['game_pk'],
39
+ # timecode: @data['timecode']
40
+ # )
41
+
42
+ # return process_diffs(diffs) if diffs.is_a?(Array)
43
+
44
+ # # If the diff is too large or too old, a new feed is returned
45
+ # @data = diffs if diffs.is_a?(Hash)
46
+
47
+ # true
48
+ # rescue Net::OpenTimeout
49
+ # false
50
+ # end
51
+
52
+ # def process_diffs(diffs)
53
+ # diffs.each do |diff_set|
54
+ # Hana::Patch.new(diff_set['diff']).apply(@data)
55
+ # end
56
+
57
+ # @api.logger&.info 'Successfully processed color feed diff'
58
+
59
+ # true
60
+ # rescue Hana::Patch::Exception
61
+ # @api.logger&.info 'Failed to process color feed diff; nuking'
62
+
63
+ # # Nuke it!
64
+ # @data = nil
65
+
66
+ # reload!
67
+
68
+ # false
69
+ # end
70
+ end
71
+ end
@@ -1,6 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Only the Pacific Coast League uses conferences
5
+ # @see https://statsapi.mlb.com/docs/#tag/conference
4
6
  module Conferences
7
+ # View all PCL conferences.
8
+ # @see https://statsapi.mlb.com/docs/#operation/conferences
9
+ def conferences(options = {})
10
+ get '/conferences', options
11
+ end
12
+
13
+ # View PCL conferences by conferenceId.
14
+ # @see https://statsapi.mlb.com/docs/#operation/conferences
15
+ def conference(conference_id, options = {})
16
+ get "/conferences/#{conference_id}", options
17
+ end
5
18
  end
6
19
  end
@@ -1,57 +1,77 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # These methods all return lists of possible values
5
+ # @see https://statsapi.mlb.com/docs/#tag/config
4
6
  module Config
7
+ # @see https://statsapi.mlb.com/docs/#operation/gameStatus
5
8
  def game_status
6
- get('/gameStatus')
9
+ get '/gameStatus'
7
10
  end
8
11
 
12
+ # @see https://statsapi.mlb.com/docs/#operation/baseballStats
13
+ def baseball_stats
14
+ get '/baseballStats'
15
+ end
16
+
17
+ # @see https://statsapi.mlb.com/docs/#operation/gameTypes
9
18
  def game_types
10
- get('/gameTypes')
19
+ get '/gameTypes'
11
20
  end
12
21
 
22
+ # @see https://statsapi.mlb.com/docs/#operation/languages
13
23
  def languages
14
- get('/languages')
24
+ get '/languages'
15
25
  end
16
26
 
27
+ # @see https://statsapi.mlb.com/docs/#operation/leagueLeaderTypes
17
28
  def league_leader_types
18
- get('/leagueLeaderTypes')
29
+ get '/leagueLeaderTypes'
19
30
  end
20
31
 
32
+ # @see https://statsapi.mlb.com/docs/#operation/metrics
21
33
  def metrics
22
- get('/metrics')
34
+ get '/metrics'
23
35
  end
24
36
 
37
+ # @see https://statsapi.mlb.com/docs/#operation/platforms
25
38
  def platforms
26
- get('/platforms')
39
+ get '/platforms'
27
40
  end
28
41
 
42
+ # @see https://statsapi.mlb.com/docs/#operation/positions
29
43
  def positions
30
- get('/positions')
44
+ get '/positions'
31
45
  end
32
46
 
47
+ # @see https://statsapi.mlb.com/docs/#operation/rosterTypes
33
48
  def roster_types
34
- get('/rosterTypes')
49
+ get '/rosterTypes'
35
50
  end
36
51
 
52
+ # @see https://statsapi.mlb.com/docs/#operation/scheduleEventTypes
37
53
  def schedule_event_types
38
- get('/scheduleEventTypes')
54
+ get '/scheduleEventTypes'
39
55
  end
40
56
 
57
+ # @see https://statsapi.mlb.com/docs/#operation/sitCodes
41
58
  def situation_codes
42
- get('/situationCodes')
59
+ get '/situationCodes'
43
60
  end
44
61
 
62
+ # @see https://statsapi.mlb.com/docs/#operation/standingsTypes
45
63
  def standings_types
46
- get('/standingsTypes')
64
+ get '/standingsTypes'
47
65
  end
48
66
 
67
+ # @see https://statsapi.mlb.com/docs/#operation/statGroups
49
68
  def stat_groups
50
- get('/statGroups')
69
+ get '/statGroups'
51
70
  end
52
71
 
72
+ # @see https://statsapi.mlb.com/docs/#operation/statTypes
53
73
  def stat_types
54
- get('/statTypes')
74
+ get '/statTypes'
55
75
  end
56
76
  end
57
77
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # @see https://statsapi.mlb.com/docs/#tag/division
4
5
  module Divisions
5
6
  # There are actually far more divisions from other leagues in the API.
6
7
  # I don't think I'll add them until necessary.
@@ -12,5 +13,11 @@ module MLBStatsAPI
12
13
  nl_central: 205,
13
14
  nl_west: 203
14
15
  }.freeze
16
+
17
+ # View league division directorial information.
18
+ # @see https://statsapi.mlb.com/docs/#operation/divisions
19
+ def divisions(options = {})
20
+ get '/divisions', options
21
+ end
15
22
  end
16
23
  end
@@ -1,6 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to MLB Rule 4 Draft (First-Year Player Draft)
5
+ # @see https://statsapi.mlb.com/docs/#tag/draft
4
6
  module Drafts
7
+ # View drafted players by year.
8
+ # @see https://statsapi.mlb.com/docs/#operation/draft
9
+ def draft(year, options = {})
10
+ get "/draft/#{year}", options
11
+ end
12
+
13
+ # View draft eligible prospects by year.
14
+ # @see https://statsapi.mlb.com/docs/#operation/draftProspects
15
+ def draft_prospects(year, options = {})
16
+ get "/draft/#{year}/prospects", options
17
+ end
18
+
19
+ # View latest player drafted, endpoint best used when draft is currently
20
+ # open.
21
+ # @see https://statsapi.mlb.com/docs/#operation/latestDraftPicks
22
+ def draft_latest(year, options = {})
23
+ get "/draft/#{year}/latest", options
24
+ end
5
25
  end
6
26
  end
@@ -3,15 +3,15 @@
3
3
  module MLBStatsAPI
4
4
  module Games
5
5
  def boxscore(game_id)
6
- get("/game/#{game_id}/boxscore")
6
+ get "/game/#{game_id}/boxscore"
7
7
  end
8
8
 
9
9
  def content(game_id, limit: nil)
10
- get("/game/#{game_id}/content", highlightLimit: limit)
10
+ get "/game/#{game_id}/content", highlightLimit: limit
11
11
  end
12
12
 
13
13
  def context_metrics(game_id, timecode: nil)
14
- get("/game/#{game_id}/contextMetrics", timecode: timecode)
14
+ get "/game/#{game_id}/contextMetrics", timecode: timecode
15
15
  end
16
16
 
17
17
  # This endpoint can return very large payloads. It is STRONGLY recommended
@@ -34,23 +34,48 @@ module MLBStatsAPI
34
34
  raise ArgumentError, 'Please pass either a timecode or a snapshot.'
35
35
  end
36
36
 
37
- get("/game/#{game_id}/feed/live/diffPatch", query)
37
+ get "/game/#{game_id}/feed/live/diffPatch", query
38
38
  end
39
39
 
40
40
  def live_feed_timestamps(game_id)
41
- get("/game/#{game_id}/feed/live/timestamps", version: '1.1')
41
+ get "/game/#{game_id}/feed/live/timestamps", version: '1.1'
42
42
  end
43
43
 
44
+ def color_feed(game_id, timecode: nil)
45
+ MLBStatsAPI::ColorFeed.new(
46
+ self,
47
+ get("/game/#{game_id}/feed/color", timecode: timecode)
48
+ )
49
+ end
50
+
51
+ # def color_feed_diff(game_id, timecode: nil, snapshot_at: nil)
52
+ # query = {}
53
+
54
+ # if timecode
55
+ # query[:startTimecode] = timecode
56
+ # elsif snapshot_at
57
+ # query[:endTimecode] = snapshot_at
58
+ # else
59
+ # raise ArgumentError, 'Please pass either a timecode or a snapshot.'
60
+ # end
61
+
62
+ # get "/game/#{game_id}/feed/color/diffPatch", query
63
+ # end
64
+
65
+ # def color_feed_timestamps(game_id)
66
+ # get "/game/#{game_id}/feed/color/timestamps"
67
+ # end
68
+
44
69
  def linescore(game_id)
45
- get("/game/#{game_id}/linescore")
70
+ get "/game/#{game_id}/linescore"
46
71
  end
47
72
 
48
73
  def play_by_play(game_id, timecode: nil)
49
- get("/game/#{game_id}/playByPlay", timecode: timecode)
74
+ get "/game/#{game_id}/playByPlay", timecode: timecode
50
75
  end
51
76
 
52
77
  def win_probability(game_id, timecode: nil)
53
- get("/game/#{game_id}/winProbability", timecode: timecode)
78
+ get "/game/#{game_id}/winProbability", timecode: timecode
54
79
  end
55
80
  end
56
81
  end
@@ -1,6 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # @see https://statsapi.mlb.com/docs/#tag/homerunderby
4
5
  module HomeRunDerby
6
+ # View a home run derby object based on gamePk.
7
+ # @see https://statsapi.mlb.com/docs/#operation/homeRunDerbyBracket
8
+ def home_run_derby(game_pk, options = {})
9
+ get "/homeRunDerby/#{game_pk}", options
10
+ end
11
+
12
+ # View a home run derby object based on bracket.
13
+ # @see https://statsapi.mlb.com/docs/#operation/homeRunDerbyBracket
14
+ def home_run_derby_bracket(game_pk, options = {})
15
+ get "/homeRunDerby/#{game_pk}/bracket", options
16
+ end
17
+
18
+ # View a home run derby object based on pool.
19
+ # @see https://statsapi.mlb.com/docs/#operation/homeRunDerbyPool
20
+ def home_run_derby_pool(game_pk, options = {})
21
+ get "/homeRunDerby/#{game_pk}/pool", options
22
+ end
5
23
  end
6
24
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to leagues
5
+ # @see https://statsapi.mlb.com/docs/#tag/league
4
6
  module Leagues
5
7
  LEAGUES = {
6
8
  american: 103,
@@ -20,5 +22,39 @@ module MLBStatsAPI
20
22
  international: 117,
21
23
  midwest: 118
22
24
  }.freeze
25
+
26
+ # View league information.
27
+ # @see https://statsapi.mlb.com/docs/#operation/league
28
+ def leagues(options = {})
29
+ unless options[:sportId] || options[:leagueIds]
30
+ raise ArgumentError, '#leagues requires a sportId or leagueIds'
31
+ end
32
+
33
+ get '/league', options
34
+ end
35
+
36
+ # View All-Star Ballots per league.
37
+ # @see https://statsapi.mlb.com/docs/#operation/allStarBallot
38
+ def all_star_ballot(league_id, season = nil, options = {})
39
+ options[:season] = season || Time.now.year
40
+
41
+ get "/league/#{league_id}/allStarBallot", options
42
+ end
43
+
44
+ # View All-Star Write-ins per league.
45
+ # @see https://statsapi.mlb.com/docs/#operation/allStarWriteIns
46
+ def all_star_write_ins(league_id, season = nil, options = {})
47
+ options[:season] = season || Time.now.year
48
+
49
+ get "/league/#{league_id}/allStarWriteIns", options
50
+ end
51
+
52
+ # View All-Star Final Vote per league.
53
+ # @see https://statsapi.mlb.com/docs/#operation/allStarFinalVote
54
+ def all_star_final_vote(league_id, season = nil, options = {})
55
+ options[:season] = season || Time.now.year
56
+
57
+ get "/league/#{league_id}/allStarFinalVote", options
58
+ end
23
59
  end
24
60
  end
@@ -1,10 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to players, umpires, and coaches
5
+ # @see https://statsapi.mlb.com/docs/#tag/person
4
6
  module People
5
- # This can find a player, coach, or umpire by ID
6
- def person(person_id)
7
- get("/people/#{person_id}")['people'].first
7
+ # View one or more person's stats and biographical information.
8
+ # @see https://statsapi.mlb.com/docs/#operation/person
9
+ def person(person_ids, options = {})
10
+ ids = Array(person_ids)
11
+
12
+ result = get('/people', options.merge(personIds: ids)).dig('people')
13
+
14
+ return result.first if ids.length == 1
15
+
16
+ result
17
+ end
18
+ alias people person
19
+
20
+ # View a player's stats for a specific game.
21
+ # @see https://statsapi.mlb.com/docs/#operation/currentGameStats
22
+ def person_game_stats(person_id, options = {})
23
+ game = options.delete(:gamePk) || 'current'
24
+
25
+ get("/people/#{person_id}/stats/game/#{game}", options).dig('stats')
8
26
  end
9
27
  end
10
28
  end
@@ -18,7 +18,7 @@ module MLBStatsAPI
18
18
 
19
19
  raise ArgumentError, 'invalid schedule type' unless SCHEDULE_TYPES[type]
20
20
 
21
- get(SCHEDULE_TYPES[type], options)
21
+ get SCHEDULE_TYPES[type], { sportId: 1 }.merge(options)
22
22
  end
23
23
  end
24
24
  end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Although this group has two endpoints, they both have the same function.
4
- #
5
- # /v1/seasons/{seasonId} is the same as /v1/seasons?season={seasonId}
6
3
  module MLBStatsAPI
4
+ # Operations pertaining to seasons
5
+ # @see https://statsapi.mlb.com/docs/#tag/season
7
6
  module Seasons
8
- # Fetch one or more seasons' start and end dates
9
- #
10
- # @param year [String] comma-separated list of years
11
- #
12
- # @return [Array<Hash>] a list of matching seasons
13
- def seasons(year: nil)
14
- get('/seasons', sportId: 1, season: year)
7
+ # View current season info.
8
+ # @see https://statsapi.mlb.com/docs/#operation/seasons
9
+ def seasons(options = {})
10
+ get '/seasons', { sportId: 1 }.merge(options)
11
+ end
12
+
13
+ # View information on an individual season.
14
+ # @see https://statsapi.mlb.com/docs/#operation/seasons
15
+ def season(year, options = {})
16
+ get "/seasons/#{year}", { sportId: 1 }.merge(options)
15
17
  end
16
- alias season seasons
17
18
  end
18
19
  end
@@ -1,13 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to sports
5
+ # @see https://statsapi.mlb.com/docs/#tag/sports
4
6
  module Sports
7
+ # View information for all sportIds.
8
+ # @see https://statsapi.mlb.com/docs/#operation/sports
5
9
  def sports
6
- get('/sports')
10
+ get '/sports'
7
11
  end
8
12
 
9
- def sport(sport_id)
10
- get("/sports/#{sport_id}")
13
+ # View information for any given sportId.
14
+ # @see https://statsapi.mlb.com/docs/#operation/sports
15
+ def sport(sport_id, options = {})
16
+ get "/sports/#{sport_id}", options
17
+ end
18
+
19
+ # View information on a players for a given sportId.
20
+ # @see https://statsapi.mlb.com/docs/#operation/sportPlayers
21
+ def sport_players(sport_id, season, options = {})
22
+ options[:season] = season
23
+
24
+ get "/sports/#{sport_id}/players", options
11
25
  end
12
26
  end
13
27
  end
@@ -1,36 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to standings
5
+ # @see https://statsapi.mlb.com/docs/#tag/standings
4
6
  module Standings
5
- TYPES = {
6
- regular_season: 'regularSeason',
7
- wild_card: 'wildCard',
8
- division_leaders: 'divisionLeaders',
9
- wild_card_with_leaders: 'wildCardWithLeaders',
10
- first_half: 'firstHalf',
11
- second_half: 'secondHalf',
12
- spring_training: 'springTraining',
13
- post_season: 'postseason',
14
- by_division: 'byDivision',
15
- by_conference: 'byConference',
16
- by_league: 'byLeague'
17
- }.freeze
7
+ # View standings for a league.
8
+ # @see https://statsapi.mlb.com/docs/#operation/standings
9
+ def standings(options = {})
10
+ options[:hydrate] = 'team' unless options.key?(:hydrate)
18
11
 
19
- def standings(leagues:, type: :regular_season, season: nil, hydrate: 'team')
20
- raise 'Invalid standings type.' unless TYPES[type]
12
+ if options[:leagues] && !options[:leagueId]
13
+ league_ids = Leagues::LEAGUES.values_at(*options.delete(:leagues))
21
14
 
22
- league_ids = Leagues::LEAGUES.values_at(*leagues)
23
-
24
- if league_ids.none?
25
- raise 'Invalid league(s) - see Leagues::LEAGUES for available names.'
15
+ options[:leagueId] = league_ids
26
16
  end
27
17
 
28
- get(
29
- "/standings/#{TYPES[type]}",
30
- leagueId: league_ids.join(','),
31
- season: (season || Date.today.year),
32
- hydrate: hydrate
33
- )
18
+ options[:leagueId] = [103, 104] unless Array(options[:leagueId])&.any?
19
+
20
+ get '/standings', options
34
21
  end
35
22
  end
36
23
  end
@@ -1,6 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to stats
5
+ # @see https://statsapi.mlb.com/docs/#tag/stats
4
6
  module Stats
7
+ # View statistics based on statType, group, season, and organization.
8
+ # @see https://statsapi.mlb.com/docs/#operation/stats
9
+ def stats(options = {})
10
+ raise ArgumentError, '#stats requires a stats arg' unless options[:stats]
11
+ raise ArgumentError, '#stats requires a group arg' unless options[:group]
12
+
13
+ get '/stats', options
14
+ end
15
+
16
+ # View leaders for a statistic.
17
+ # @see https://statsapi.mlb.com/docs/#operation/leaders
18
+ def stats_leaders(options = {})
19
+ unless options[:leaderCategories]
20
+ raise ArgumentError, '#stats_leaders requires a leaderCategories arg'
21
+ end
22
+
23
+ get '/stats/leaders', options
24
+ end
5
25
  end
6
26
  end
@@ -11,8 +11,7 @@ module MLBStatsAPI
11
11
  end
12
12
 
13
13
  def teams(*team_ids)
14
- teams = []
15
- ids = []
14
+ teams = ids = []
16
15
 
17
16
  team_ids.each do |team_id|
18
17
  value = @cache.load("mlb_stats_api:teams:#{team_id}")
@@ -28,13 +27,13 @@ module MLBStatsAPI
28
27
  end
29
28
 
30
29
  def affiliates(team_id, season: nil)
31
- get("/teams/#{team_id}/affiliates", season: season)
30
+ get "/teams/#{team_id}/affiliates", season: season
32
31
  end
33
32
 
34
33
  def coaches(team_id, date: nil)
35
34
  date ||= Date.today
36
35
 
37
- get("/teams/#{team_id}/coaches", date: date.strftime('%m/%d/%Y'))
36
+ get "/teams/#{team_id}/coaches", date: date.strftime('%m/%d/%Y')
38
37
  end
39
38
 
40
39
  # def leaders(team_id)
@@ -42,7 +41,7 @@ module MLBStatsAPI
42
41
  # end
43
42
 
44
43
  def roster(team_id, type:, date: nil)
45
- get("/teams/#{team_id}/roster/#{type}", date: date.strftime('%m/%d/%Y'))
44
+ get "/teams/#{team_id}/roster/#{type}", date: date.strftime('%m/%d/%Y')
46
45
  end
47
46
 
48
47
  protected
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
+ # Operations pertaining to venues
5
+ # @see https://statsapi.mlb.com/docs/#tag/venue
4
6
  module Venues
7
+ # View information for a venue based on venueId.
8
+ # @see https://statsapi.mlb.com/docs/#operation/venues
5
9
  def venue(venue_id)
6
- MLBStatsAPI::Venue.new get("/venues/#{venue_id}").dig('venues', 0)
10
+ get("/venues/#{venue_id}").dig('venues', 0)
7
11
  end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBStatsAPI
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_stats_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Hoffman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-02 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,6 +128,7 @@ files:
128
128
  - lib/mlb_stats_api.rb
129
129
  - lib/mlb_stats_api/base.rb
130
130
  - lib/mlb_stats_api/client.rb
131
+ - lib/mlb_stats_api/color_feed.rb
131
132
  - lib/mlb_stats_api/conferences.rb
132
133
  - lib/mlb_stats_api/config.rb
133
134
  - lib/mlb_stats_api/divisions.rb
@@ -145,7 +146,6 @@ files:
145
146
  - lib/mlb_stats_api/stats.rb
146
147
  - lib/mlb_stats_api/team.rb
147
148
  - lib/mlb_stats_api/teams.rb
148
- - lib/mlb_stats_api/venue.rb
149
149
  - lib/mlb_stats_api/venues.rb
150
150
  - lib/mlb_stats_api/version.rb
151
151
  - mlb_stats_api.gemspec
@@ -168,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.7.6
171
+ rubygems_version: 3.0.3
173
172
  signing_key:
174
173
  specification_version: 4
175
174
  summary: MLB has a new Stats API!
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MLBStatsAPI
4
- class Venue < Base
5
- def id
6
- @data['id']
7
- end
8
-
9
- def name
10
- @data['name']
11
- end
12
- end
13
- end