mlb_gameday 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: afb572d47ba8e0600616d659f913fd1b130e706a
4
- data.tar.gz: a1a020d170a635355a210c5490965e2129f41f19
2
+ SHA256:
3
+ metadata.gz: 499145f925f463abfdf236a63966ee0e8bedfae2dddabe69d3a6b5781c934951
4
+ data.tar.gz: 140ba72b1cfbdcc55a093159b6030c9059fe29cd41b52343ee601560b155619a
5
5
  SHA512:
6
- metadata.gz: 9b4a14b8ef055db01a778d8b48739b4b612057e2ef12577ade28137181938f5817f1ac9971235b5a5e23ad099e17cae9b193fbaaaf301df37edec38d7d78fc14
7
- data.tar.gz: f99acf4627c0f9bf6ad877dbb339fc33fc41bd2a09372d2b2642ac923ce51fc49b3396adb7f96154b2f24e6312794a385c05f4932fa2d2547edea7c2464c831d
6
+ metadata.gz: 39daa28891b1a746e7736fb15025e347a69720a79b70d13d5cf3c64868f1606eae9515341356e2a3d07a68ea8af649f907a810b83eaec018e996628ddf988b17
7
+ data.tar.gz: 9f29ea34ca7af20a0d19bc7b8cff5bb650e8e4fefd824a24c38fae1fc83585a255494ff5d5988ac28bd48014bc02e487d272d84a68b2614ef37eab95483eed0f
data/.rubocop.yml CHANGED
@@ -2,7 +2,10 @@ AllCops:
2
2
  Include:
3
3
  - Rakefile
4
4
  - Gemfile
5
- TargetRubyVersion: 2.4
5
+ TargetRubyVersion: 2.5
6
+
7
+ Layout/MultilineMethodCallIndentation:
8
+ EnforcedStyle: indented
6
9
 
7
10
  Metrics/AbcSize:
8
11
  Enabled: false
@@ -18,6 +21,3 @@ Metrics/MethodLength:
18
21
 
19
22
  Style/Documentation:
20
23
  Enabled: false
21
-
22
- Style/MultilineMethodCallIndentation:
23
- EnforcedStyle: indented
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Changed data source to gd-terr-origin.mlb.com since gdx.mlb.com redirects there.
6
+ * Code cleanup.
7
+
3
8
  ## 0.2.3 / 0.2.4
4
9
 
5
10
  * Add All Star teams
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # MlbGameday
1
+ # MLBGameday
2
2
 
3
3
  TODO: Write a gem description
4
4
 
data/lib/mlb_gameday.rb CHANGED
@@ -11,13 +11,11 @@ require 'chronic'
11
11
  end
12
12
 
13
13
  module MLBGameday
14
- API_URL = 'http://gd2.mlb.com/components/game/mlb'
14
+ API_URL = 'http://gd-terr-origin.mlb.com/components/game/mlb'
15
15
 
16
- BATTER = '/year_%{year}/batters/%{id}'
17
- PITCHER = '/year_%{year}/pitchers/%{id}'
18
- RAWBOXSCORE = '/year_%{year}/month_%{month}/day_%{day}/gid_%{gid}/rawboxscore'
19
- GAMECENTER = '/year_%{year}/month_%{month}/day_%{day}/gid_%{gid}/gamecenter'
20
- LINESCORE = '/year_%{year}/month_%{month}/day_%{day}/gid_%{gid}/linescore'
16
+ BATTER = '/year_%<year>d/batters/%<id>d'
17
+ PITCHER = '/year_%<year>d/pitchers/%<id>d'
18
+ GAME_FOLDER = '/year_%<year>d/month_%02<month>d/day_%02<day>d/gid_%<gid>s'
21
19
  SCOREBOARD = '/year_%Y/month_%m/day_%d/miniscoreboard'
22
20
 
23
21
  class API
@@ -107,43 +105,33 @@ module MLBGameday
107
105
  end
108
106
 
109
107
  def linescore_xml(gid)
110
- year, month, day, = gid.split '_'
111
-
112
- fetch_xml LINESCORE, year: year, month: month, day: day, gid: gid
108
+ fetch_xml "#{GAME_FOLDER}/linescore", gid: gid
113
109
  end
114
110
 
115
111
  def rawboxscore_xml(gid)
116
- year, month, day, = gid.split '_'
117
-
118
- fetch_xml RAWBOXSCORE, year: year, month: month, day: day, gid: gid
112
+ fetch_xml "#{GAME_FOLDER}/rawboxscore", gid: gid
119
113
  end
120
114
 
121
115
  def gamecenter_xml(gid)
122
- year, month, day, = gid.split '_'
123
-
124
- fetch_xml GAMECENTER, year: year, month: month, day: day, gid: gid
116
+ fetch_xml "#{GAME_FOLDER}/gamecenter", gid: gid
125
117
  end
126
118
 
127
119
  def batter_xml(id, year: nil)
128
- # We only really want one piece of data from this file...
129
- year_data = fetch_xml BATTER, id: id, year: (year || Date.today.year)
130
-
131
- gid = year_data.xpath('//batting/@game_id').text
132
- year, month, day, = gid.split '/'
120
+ # We only really want one piece of data from this file. This gives us
121
+ # the GID of their most recent appearance.
122
+ gid = fetch_xml(BATTER, id: id, year: (year || Date.today.year))
123
+ .xpath('//batting/@game_id').text.gsub(/[^a-z0-9]/, '_')
133
124
 
134
- fetch_xml "/year_#{year}/month_#{month}/day_#{day}/" \
135
- "gid_#{gid.gsub(/[^a-z0-9]/, '_')}/batters/#{id}"
125
+ fetch_xml "#{GAME_FOLDER}/batters/%<batter>s", gid: gid, batter: id
136
126
  end
137
127
 
138
128
  def pitcher_xml(id, year: nil)
139
- # We only really want one piece of data from this file...
140
- year_data = fetch_xml PITCHER, id: id, year: (year || Date.today.year)
129
+ # We only really want one piece of data from this file. This gives us
130
+ # the GID of their most recent appearance.
131
+ gid = fetch_xml(PITCHER, id: id, year: (year || Date.today.year))
132
+ .xpath('//pitching/@game_id').text.gsub(/[^a-z0-9]/, '_')
141
133
 
142
- gid = year_data.xpath('//pitching/@game_id').text
143
- year, month, day, = gid.split '/'
144
-
145
- fetch_xml "/year_#{year}/month_#{month}/day_#{day}/" \
146
- "gid_#{gid.gsub(/[^a-z0-9]/, '_')}/pitchers/#{id}"
134
+ fetch_xml "#{GAME_FOLDER}/pitchers/%<pitcher>s", gid: gid, pitcher: id
147
135
  end
148
136
 
149
137
  protected
@@ -151,6 +139,14 @@ module MLBGameday
151
139
  def fetch_xml(path, interpolations = {})
152
140
  full_path = "#{API_URL}#{path}.xml"
153
141
 
142
+ if interpolations[:gid]
143
+ year, month, day, = interpolations[:gid].split '_'
144
+
145
+ interpolations[:year] = year
146
+ interpolations[:month] = month
147
+ interpolations[:day] = day
148
+ end
149
+
154
150
  full_path = format(full_path, interpolations) if interpolations.any?
155
151
 
156
152
  Nokogiri::XML open full_path
@@ -10,16 +10,10 @@ module MLBGameday
10
10
  def initialize(api, gid, files = {})
11
11
  @api = api
12
12
  @gid = gid
13
-
14
13
  @files = files
15
14
 
16
- if files[:linescore]
17
- @home_team = @api.team files[:linescore].xpath('//game/@home_name_abbrev').text
18
- @away_team = @api.team files[:linescore].xpath('//game/@away_name_abbrev').text
19
- else
20
- @home_team = @api.team files[:gamecenter].xpath('//game/@id').text[18, 6]
21
- @away_team = @api.team files[:gamecenter].xpath('//game/@id').text[11, 6]
22
- end
15
+ @home_team = @api.team home_team_identifier
16
+ @away_team = @api.team away_team_identifier
23
17
  end
24
18
 
25
19
  def teams
@@ -290,5 +284,24 @@ module MLBGameday
290
284
  def inspect
291
285
  %(#<MLBGameday::Game @gid="#{@gid}">)
292
286
  end
287
+
288
+ protected
289
+
290
+ def home_team_identifier
291
+ if files[:linescore]
292
+ return files[:linescore].xpath('//game/@home_name_abbrev').text
293
+ end
294
+
295
+ files[:gamecenter].xpath('//game/@id').text[18, 6]
296
+ end
297
+
298
+ def away_team_identifier
299
+ if files[:linescore]
300
+ return files[:linescore].xpath('//game/@away_name_abbrev').text
301
+ end
302
+
303
+ files[:gamecenter].xpath('//game/@id').text[11, 6]
304
+ end
293
305
  end
306
+ # rubocop:enable Metrics/ClassLength
294
307
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLBGameday
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.0'
5
5
  end
data/mlb_gameday.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  lib = File.expand_path('../lib', __FILE__)
@@ -12,7 +11,7 @@ Gem::Specification.new do |spec|
12
11
  spec.email = ['git@fustrate.com']
13
12
  spec.description = 'Access data about games and players from the ' \
14
13
  'official MLB Gameday API'
15
- spec.summary = %(Fetches gameday data from the MLB Gameday API)
14
+ spec.summary = 'Fetches gameday data from the MLB Gameday API'
16
15
  spec.homepage = 'http://github.com/fustrate/mlb_gameday'
17
16
  spec.license = 'MIT'
18
17
 
@@ -22,10 +21,10 @@ Gem::Specification.new do |spec|
22
21
  spec.require_paths = %w[lib]
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 1.9'
25
- spec.add_development_dependency 'rake', '~> 10.4'
26
24
  spec.add_development_dependency 'minitest', '~> 5.5'
25
+ spec.add_development_dependency 'rake', '~> 10.4'
27
26
 
27
+ spec.add_dependency 'chronic', '~> 0.10'
28
28
  spec.add_dependency 'httparty', '~> 0.13'
29
29
  spec.add_dependency 'nokogiri', '~> 1.6'
30
- spec.add_dependency 'chronic', '~> 0.10'
31
30
  end
data/test/game_spec.rb CHANGED
@@ -9,7 +9,7 @@ class MockedApi < MLBGameday::API
9
9
 
10
10
  def open(url, &block)
11
11
  dir = File.dirname __FILE__
12
- base = url.gsub 'http://gd2.mlb.com/components/game/mlb/', ''
12
+ base = url.gsub 'http://gd-terr-origin.mlb.com/components/game/mlb/', ''
13
13
  path = File.join dir, base
14
14
 
15
15
  unless File.exist?(path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_gameday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Hoffman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2018-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,75 +25,75 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.4'
33
+ version: '5.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.4'
40
+ version: '5.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.5'
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.5'
54
+ version: '10.4'
55
55
  - !ruby/object:Gem::Dependency
56
- name: httparty
56
+ name: chronic
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.13'
61
+ version: '0.10'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.13'
68
+ version: '0.10'
69
69
  - !ruby/object:Gem::Dependency
70
- name: nokogiri
70
+ name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.6'
75
+ version: '0.13'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.6'
82
+ version: '0.13'
83
83
  - !ruby/object:Gem::Dependency
84
- name: chronic
84
+ name: nokogiri
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.10'
89
+ version: '1.6'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.10'
96
+ version: '1.6'
97
97
  description: Access data about games and players from the official MLB Gameday API
98
98
  email:
99
99
  - git@fustrate.com
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  requirements: []
245
245
  rubyforge_project:
246
- rubygems_version: 2.6.11
246
+ rubygems_version: 2.7.3
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: Fetches gameday data from the MLB Gameday API