mlb_gd2 0.1.0
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 +7 -0
- data/lib/mlb_gd2/game.rb +41 -0
- data/lib/mlb_gd2/gameday.rb +21 -0
- data/lib/mlb_gd2/gameday_helpers.rb +20 -0
- data/lib/mlb_gd2.rb +3 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b82350dbea5909d0e7053ba929fc480a33b5430
|
4
|
+
data.tar.gz: 309285ff26e9815b8f102d821d35579cbd59ea83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea5a334b9449863313cec8f697f7bf32e5c105f2bd8a2e3e8c35bdd6f7c6a3ab2bb38822b660faeacdb1776674b0fe7155dc3551d2537bf7e417d1f4bbf65379
|
7
|
+
data.tar.gz: d6ec4186e015fb06911ffbf5a5dc5b79667552ec74a44e9d43973a750fcf7a542fd31ccfd74201765e24d105489a768df77a29560c32d00084449c8cdaf37d24
|
data/lib/mlb_gd2/game.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
class Game
|
5
|
+
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
@boxscore = GamedayUrlBuilder.generate_nokogiri_xml(url + 'boxscore.xml').xpath("//boxscore").first
|
9
|
+
end
|
10
|
+
|
11
|
+
def teams
|
12
|
+
Hash[
|
13
|
+
:away, boxscore["away_fname"],
|
14
|
+
:home, boxscore["home_fname"]
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def linescores
|
19
|
+
linescore = boxscore.xpath("//linescore").first
|
20
|
+
|
21
|
+
Hash[
|
22
|
+
:away, {
|
23
|
+
inning_line_score: boxscore.xpath("//inning_line_score").map { |inning| inning["away"].to_i },
|
24
|
+
runs: linescore["away_team_runs"].to_i,
|
25
|
+
hits: linescore["away_team_hits"].to_i,
|
26
|
+
errors: linescore["away_team_errors"].to_i
|
27
|
+
},
|
28
|
+
:home, {
|
29
|
+
inning_line_score: boxscore.xpath("//inning_line_score").map { |inning| inning["home"].to_i },
|
30
|
+
runs: linescore["home_team_runs"].to_i,
|
31
|
+
hits: linescore["home_team_hits"].to_i,
|
32
|
+
errors: linescore["home_team_errors"].to_i
|
33
|
+
}
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :url, :boxscore
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
class Gameday
|
5
|
+
|
6
|
+
attr_reader :games, :date
|
7
|
+
|
8
|
+
def initialize(year, month, day)
|
9
|
+
date_time = Time.new(year, month, day)
|
10
|
+
base_url = GamedayUrlBuilder.build_base_url(date_time)
|
11
|
+
|
12
|
+
@games = GamedayUrlBuilder.generate_nokogiri_html(base_url).search('a[href^="gid"]').map do |link|
|
13
|
+
gid = link.attributes["href"].value
|
14
|
+
Game.new(base_url + gid)
|
15
|
+
end
|
16
|
+
@date = date_time.strftime("%B %-d, %Y")
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
class GamedayUrlBuilder
|
5
|
+
|
6
|
+
GD2_MLB_BASE = "http://gd2.mlb.com/components/game/mlb"
|
7
|
+
|
8
|
+
def self.build_base_url(date)
|
9
|
+
GD2_MLB_BASE + date.strftime("/year_%Y/month_%m/day_%d/")
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.generate_nokogiri_html(url)
|
13
|
+
Nokogiri::HTML(Net::HTTP.get(URI(url)))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.generate_nokogiri_xml(url)
|
17
|
+
Nokogiri::XML(Net::HTTP.get(URI(url)))
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/mlb_gd2.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mlb_gd2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henry Firth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
description: A simple wrapper for MLB's GD2 API
|
28
|
+
email: henrynf12@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/mlb_gd2.rb
|
34
|
+
- lib/mlb_gd2/game.rb
|
35
|
+
- lib/mlb_gd2/gameday.rb
|
36
|
+
- lib/mlb_gd2/gameday_helpers.rb
|
37
|
+
homepage: http://rubygems.org/gems/mlb_gd2
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.4.5.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: MLB Gameday API Wrapper
|
61
|
+
test_files: []
|