mlb_stats_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4fb55223ca20c3bc92a9dfa12ef15391f187a415d7eb325555e1a9e51389e4cb
4
+ data.tar.gz: 0af7c7ede687640ee38e156bdeaf93879c7cb380029c096090eb3faf8d207cd3
5
+ SHA512:
6
+ metadata.gz: bdf7ea98998777f391f6d721833a317ecd545ca1e7e18a955ef85d7bd57a764f071589e3a56510c582afab9fe113d1569ed5e6350d97db6aa9b91f19cfbebb39
7
+ data.tar.gz: a0747d2cf69a6a0678ef73ff5c495ac859054cdb729bd6930b2b1834c850a58d1136ea85de71f83ed6c0461065d6dca50c9020447daa5f2e8cb37fe0df709186
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ - Gemfile
5
+ TargetRubyVersion: 2.5
6
+
7
+ Layout/MultilineMethodCallIndentation:
8
+ EnforcedStyle: indented
9
+
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
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in mlb_stats_api.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Steven Hoffman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MlbStatsApi
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mlb_stats_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mlb_stats_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mlb_stats_api.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mlb_stats_api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ @client = MLBStatsAPI::Client.new
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
8
+
9
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hana'
4
+ require 'httparty'
5
+ require 'json'
6
+
7
+ require 'mlb_stats_api/errors'
8
+ require 'mlb_stats_api/version'
9
+
10
+ require 'mlb_stats_api/base'
11
+ require 'mlb_stats_api/live_feed'
12
+ require 'mlb_stats_api/team'
13
+ require 'mlb_stats_api/venue'
14
+
15
+ require 'mlb_stats_api/conferences'
16
+ require 'mlb_stats_api/config'
17
+ require 'mlb_stats_api/divisions'
18
+ require 'mlb_stats_api/drafts'
19
+ require 'mlb_stats_api/games'
20
+ require 'mlb_stats_api/home_run_derby'
21
+ require 'mlb_stats_api/leagues'
22
+ require 'mlb_stats_api/people'
23
+ require 'mlb_stats_api/schedules'
24
+ require 'mlb_stats_api/seasons'
25
+ require 'mlb_stats_api/sports'
26
+ require 'mlb_stats_api/standings'
27
+ require 'mlb_stats_api/stats'
28
+ require 'mlb_stats_api/teams'
29
+ require 'mlb_stats_api/venues'
30
+
31
+ require 'mlb_stats_api/client'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ class Base
5
+ attr_reader :data
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+
11
+ def [](key)
12
+ @data[key]
13
+ end
14
+
15
+ def dig(*path)
16
+ @data.dig(*path)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'moneta'
5
+
6
+ module MLBStatsAPI
7
+ class Client
8
+ include HTTParty
9
+
10
+ include MLBStatsAPI::Conferences
11
+ include MLBStatsAPI::Config
12
+ include MLBStatsAPI::Divisions
13
+ include MLBStatsAPI::Drafts
14
+ include MLBStatsAPI::Games
15
+ include MLBStatsAPI::HomeRunDerby
16
+ include MLBStatsAPI::Leagues
17
+ include MLBStatsAPI::People
18
+ include MLBStatsAPI::Schedules
19
+ include MLBStatsAPI::Seasons
20
+ include MLBStatsAPI::Sports
21
+ include MLBStatsAPI::Standings
22
+ include MLBStatsAPI::Stats
23
+ include MLBStatsAPI::Teams
24
+ include MLBStatsAPI::Venues
25
+
26
+ DEFAULT_VERSION = '1'
27
+
28
+ headers 'Content-Type' => 'application/json'
29
+ # , 'Accept-Encoding' => 'gzip, deflate'
30
+
31
+ base_uri 'http://statsapi-default-elb-prod-876255662.us-east-1.elb.amazonaws.com/'
32
+
33
+ format :json
34
+
35
+ attr_accessor :logger, :cache
36
+
37
+ def initialize(logger: false, cache: nil)
38
+ @cache = if cache
39
+ Moneta.new(cache.class.to_s.to_sym, backend: cache)
40
+ else
41
+ Moneta.new(:Null)
42
+ end
43
+
44
+ return if logger == false
45
+
46
+ @logger = logger.is_a?(::Logger) ? logger : ::Logger.new(logger)
47
+ end
48
+
49
+ def get(endpoint, query = {})
50
+ url = "/api/v#{query.delete(:version) || DEFAULT_VERSION}#{endpoint}"
51
+
52
+ query.reject! { |_, v| v.nil? }
53
+
54
+ @logger&.info("Fetching URL: #{url} Query: #{query.inspect}")
55
+
56
+ response = self.class.get url, query: query.merge(t: Time.now.to_i)
57
+
58
+ raise_exception(response) unless response.code == 200
59
+
60
+ response.parsed_response
61
+ end
62
+
63
+ def fetch(key)
64
+ value = @cache[key]
65
+
66
+ return value if value
67
+
68
+ value = yield
69
+
70
+ @cache[key] = value
71
+
72
+ value
73
+ end
74
+
75
+ protected
76
+
77
+ def raise_exception(response)
78
+ case response.code
79
+ when 401
80
+ raise MLBStatsAPI::UnauthorizedError, response
81
+ when 403
82
+ raise MLBStatsAPI::ForbiddenError, response
83
+ when 404
84
+ raise MLBStatsAPI::NotFoundError, response
85
+ else
86
+ raise MLBStatsAPI::Error, response
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Conferences
5
+ end
6
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Config
5
+ def game_status
6
+ get('/gameStatus')
7
+ end
8
+
9
+ def game_types
10
+ get('/gameTypes')
11
+ end
12
+
13
+ def languages
14
+ get('/languages')
15
+ end
16
+
17
+ def league_leader_types
18
+ get('/leagueLeaderTypes')
19
+ end
20
+
21
+ def metrics
22
+ get('/metrics')
23
+ end
24
+
25
+ def platforms
26
+ get('/platforms')
27
+ end
28
+
29
+ def positions
30
+ get('/positions')
31
+ end
32
+
33
+ def roster_types
34
+ get('/rosterTypes')
35
+ end
36
+
37
+ def schedule_event_types
38
+ get('/scheduleEventTypes')
39
+ end
40
+
41
+ def situation_codes
42
+ get('/situationCodes')
43
+ end
44
+
45
+ def standings_types
46
+ get('/standingsTypes')
47
+ end
48
+
49
+ def stat_groups
50
+ get('/statGroups')
51
+ end
52
+
53
+ def stat_types
54
+ get('/statTypes')
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Divisions
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Drafts
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ class Error < ::RuntimeError
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def to_s
10
+ format(
11
+ '%<code>s: %<message>s (%<uri>s)',
12
+ code: @response.code,
13
+ message: '', # @response.response,
14
+ uri: @response.request.last_uri.to_s
15
+ )
16
+ end
17
+ end
18
+
19
+ class ForbiddenError < Error
20
+ end
21
+
22
+ class NotFoundError < Error
23
+ end
24
+
25
+ class UnauthorizedError < Error
26
+ end
27
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Games
5
+ def boxscore(game_id)
6
+ get("/game/#{game_id}/boxscore")
7
+ end
8
+
9
+ def content(game_id, limit: nil)
10
+ get("/game/#{game_id}/content", highlightLimit: limit)
11
+ end
12
+
13
+ def context_metrics(game_id, timecode: nil)
14
+ get("/game/#{game_id}/contextMetrics", timecode: timecode)
15
+ end
16
+
17
+ # This endpoint can return very large payloads. It is STRONGLY recommended
18
+ # that clients ask for diffs and use "Accept-Encoding: gzip" header.
19
+ def live_feed(game_id, timecode: nil)
20
+ MLBStatsAPI::LiveFeed.new(
21
+ self,
22
+ get("/game/#{game_id}/feed/live", version: '1.1', timecode: timecode)
23
+ )
24
+ end
25
+
26
+ def live_feed_diff(game_id, timecode: nil, snapshot_at: nil)
27
+ query = { version: '1.1' }
28
+
29
+ if timecode
30
+ query[:startTimecode] = timecode
31
+ elsif snapshot_at
32
+ query[:endTimecode] = snapshot_at
33
+ else
34
+ raise ArgumentError, 'Please pass either a timecode or a snapshot.'
35
+ end
36
+
37
+ get("/game/#{game_id}/feed/live/diffPatch", query)
38
+ end
39
+
40
+ def live_feed_timestamps(game_id)
41
+ get("/game/#{game_id}/feed/live/timestamps", version: '1.1')
42
+ end
43
+
44
+ def linescore(game_id)
45
+ get("/game/#{game_id}/linescore")
46
+ end
47
+
48
+ def play_by_play(game_id, timecode: nil)
49
+ get("/game/#{game_id}/playByPlay", timecode: timecode)
50
+ end
51
+
52
+ def win_probability(game_id, timecode: nil)
53
+ get("/game/#{game_id}/winProbability", timecode: timecode)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module HomeRunDerby
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Leagues
5
+ LEAGUES = {
6
+ american: 103,
7
+ national: 104,
8
+ big_east: 107,
9
+ acc: 108,
10
+ texas: 109,
11
+ california: 110,
12
+ southern: 111,
13
+ pcl: 112,
14
+ eastern: 113,
15
+ cactus: 114,
16
+ grapefruit: 115,
17
+ south_atlantic: 116,
18
+ international: 117,
19
+ midwest: 118
20
+ }.freeze
21
+ end
22
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ class LiveFeed < 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['gameData']['game']['pk']
13
+ end
14
+
15
+ def boxscore
16
+ @data['liveData']['boxscore']
17
+ end
18
+
19
+ def decisions
20
+ @data['liveData']['decisions']
21
+ end
22
+
23
+ def leaders
24
+ @data['liveData']['leaders']
25
+ end
26
+
27
+ def linescore
28
+ @data['liveData']['linescore']
29
+ end
30
+
31
+ def plays
32
+ @data['liveData']['plays']
33
+ end
34
+
35
+ def timestamps
36
+ @api.live_feed_timestamps(@id)
37
+ end
38
+
39
+ def reload!
40
+ @data = @api.get("/game/#{@id}/feed/live", version: '1.1')
41
+
42
+ true
43
+ end
44
+
45
+ def update!
46
+ return reload! unless @data
47
+
48
+ diffs = @api.live_feed_diff(
49
+ @data['gamePk'],
50
+ timecode: @data['metaData']['timeStamp']
51
+ )
52
+
53
+ return process_diffs(diffs) if diffs.is_a(Array)
54
+
55
+ # If the diff is too large or too old, a new feed is returned
56
+ @data = diffs if diffs.is_a?(Hash)
57
+
58
+ true
59
+ end
60
+
61
+ def process_diffs(diffs)
62
+ diffs.each do |diff_set|
63
+ Hana::Patch.new(diff_set['diff']).apply(@data)
64
+ end
65
+
66
+ @api.logger&.info 'Successfully processed live feed diff'
67
+
68
+ true
69
+ rescue Hana::Patch::Exception
70
+ @api.logger&.info 'Failed to process live feed diff; nuking'
71
+
72
+ # Nuke it!
73
+ @data = nil
74
+
75
+ reload!
76
+
77
+ false
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ 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
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Schedules
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
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
+ module MLBStatsAPI
7
+ 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)
15
+ end
16
+ alias season seasons
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Sports
5
+ def sports
6
+ get('/sports')
7
+ end
8
+
9
+ def sport(sport_id)
10
+ get("/sports/#{sport_id}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Standings
5
+ STANDINGS_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
18
+
19
+ def standings(type:, league_ids:, season: nil)
20
+ raise 'Invalid standings type.' unless STANDINGS_TYPES[type]
21
+
22
+ get(
23
+ "/standings/#{STANDINGS_TYPES[type]}",
24
+ leagueId: Array(league_ids).join(','),
25
+ season: (season || Date.today.year)
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Stats
5
+ end
6
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ class Team < Base
5
+ def id
6
+ @data['id']
7
+ end
8
+
9
+ def name
10
+ @data['teamName']
11
+ end
12
+
13
+ def location
14
+ @data['locationName']
15
+ end
16
+
17
+ def abbreviation
18
+ @data['abbreviation']
19
+ end
20
+ alias code abbreviation
21
+
22
+ def file_code
23
+ @data['fileCode']
24
+ end
25
+
26
+ def short_name
27
+ @data['shortName']
28
+ end
29
+
30
+ def league_id
31
+ @data.dig('league', 'id')
32
+ end
33
+
34
+ def division_id
35
+ @data.dig('division', 'id')
36
+ end
37
+
38
+ def full_name
39
+ @data['name']
40
+ end
41
+
42
+ # So we don't get huge printouts
43
+ def inspect
44
+ %(#<MLBGameday::Team @name="#{name}">)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Teams
5
+ def team(team_id)
6
+ data = fetch("mlb_stats_api:teams:#{team_id}") do
7
+ get("/teams/#{team_id}", hydrate: 'venue(timezone)').dig('teams', 0)
8
+ end
9
+
10
+ MLBStatsAPI::Team.new data
11
+ end
12
+
13
+ def teams(*team_ids)
14
+ teams = []
15
+ ids = []
16
+
17
+ team_ids.each do |team_id|
18
+ value = @cache.load("mlb_stats_api:teams:#{team_id}")
19
+
20
+ if value
21
+ teams << MLBStatsAPI::Team.new(value)
22
+ else
23
+ ids << team_id
24
+ end
25
+ end
26
+
27
+ teams.concat load_teams_by_id(ids)
28
+ end
29
+
30
+ def affiliates(team_id, season: nil)
31
+ get("/teams/#{team_id}/affiliates", season: season)
32
+ end
33
+
34
+ def coaches(team_id, date: nil)
35
+ date ||= Date.today
36
+
37
+ get("/teams/#{team_id}/coaches", date: date.strftime('%m/%d/%Y'))
38
+ end
39
+
40
+ # def leaders(team_id)
41
+ # get("/teams/#{team_id}/leaders")
42
+ # end
43
+
44
+ def roster(team_id, type:, date: nil)
45
+ get("/teams/#{team_id}/roster/#{type}", date: date.strftime('%m/%d/%Y'))
46
+ end
47
+
48
+ protected
49
+
50
+ def load_teams_by_id(ids)
51
+ return [] if ids.none?
52
+
53
+ get('/teams', teamId: ids.join(','), hydrate: 'venue(timezone)')
54
+ .dig('teams')
55
+ .map do |data|
56
+ @cache.store("mlb_stats_api:teams:#{data['id']}", data)
57
+
58
+ MLBStatsAPI::Team.new(data)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ module Venues
5
+ def venue(venue_id)
6
+ MLBStatsAPI::Venue.new get("/venues/#{venue_id}").dig('venues', 0)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MLBStatsAPI
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'mlb_stats_api/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'mlb_stats_api'
9
+ spec.version = MLBStatsAPI::VERSION
10
+ spec.authors = ['Steven Hoffman']
11
+ spec.email = ['git@fustrate.com']
12
+
13
+ spec.summary = %(MLB has a new Stats API!)
14
+ spec.homepage = 'http://github.com/fustrate/mlb_stats_api'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '> 1.16'
25
+ spec.add_development_dependency 'rake', '> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.5'
27
+ spec.add_development_dependency 'webmock', '~> 2.3'
28
+
29
+ spec.add_dependency 'hana', '~> 1.3'
30
+ spec.add_dependency 'httparty', '~> 0.16'
31
+ spec.add_dependency 'moneta', '~> 1.0'
32
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlb_stats_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Hoffman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hana
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: moneta
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ description:
112
+ email:
113
+ - git@fustrate.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rubocop.yml"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/mlb_stats_api.rb
129
+ - lib/mlb_stats_api/base.rb
130
+ - lib/mlb_stats_api/client.rb
131
+ - lib/mlb_stats_api/conferences.rb
132
+ - lib/mlb_stats_api/config.rb
133
+ - lib/mlb_stats_api/divisions.rb
134
+ - lib/mlb_stats_api/drafts.rb
135
+ - lib/mlb_stats_api/errors.rb
136
+ - lib/mlb_stats_api/games.rb
137
+ - lib/mlb_stats_api/home_run_derby.rb
138
+ - lib/mlb_stats_api/leagues.rb
139
+ - lib/mlb_stats_api/live_feed.rb
140
+ - lib/mlb_stats_api/people.rb
141
+ - lib/mlb_stats_api/schedules.rb
142
+ - lib/mlb_stats_api/seasons.rb
143
+ - lib/mlb_stats_api/sports.rb
144
+ - lib/mlb_stats_api/standings.rb
145
+ - lib/mlb_stats_api/stats.rb
146
+ - lib/mlb_stats_api/team.rb
147
+ - lib/mlb_stats_api/teams.rb
148
+ - lib/mlb_stats_api/venue.rb
149
+ - lib/mlb_stats_api/venues.rb
150
+ - lib/mlb_stats_api/version.rb
151
+ - mlb_stats_api.gemspec
152
+ homepage: http://github.com/fustrate/mlb_stats_api
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.7.6
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: MLB has a new Stats API!
176
+ test_files: []