nfl_live_update 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +34 -0
- data/Rakefile +16 -0
- data/lib/nfl/live_update/game_center/game.rb +33 -0
- data/lib/nfl/live_update/game_center/player_stat.rb +17 -0
- data/lib/nfl/live_update/game_center/team.rb +38 -0
- data/lib/nfl/live_update/game_center/team_score.rb +20 -0
- data/lib/nfl/live_update/game_center/team_stat.rb +26 -0
- data/lib/nfl/live_update/game_center.rb +5 -0
- data/lib/nfl/live_update/score_strip/game.rb +64 -0
- data/lib/nfl/live_update/score_strip/games.rb +46 -0
- data/lib/nfl/live_update/score_strip.rb +3 -0
- data/lib/nfl/live_update/version.rb +5 -0
- data/lib/nfl.rb +19 -0
- data/nfl_live_update.gemspec +27 -0
- data/test/fixtures/apples.yml +12 -0
- data/test/test_helper.rb +49 -0
- data/test/unit/score_strip_games_test.rb +5 -0
- metadata +128 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.3@nfl
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nfl_live_update (0.0.1)
|
5
|
+
nokogiri
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (0.9.8)
|
11
|
+
method_source (0.6.7)
|
12
|
+
ruby_parser (>= 2.3.1)
|
13
|
+
nokogiri (1.5.0)
|
14
|
+
pry (0.9.7.4)
|
15
|
+
coderay (~> 0.9.8)
|
16
|
+
method_source (~> 0.6.7)
|
17
|
+
ruby_parser (>= 2.3.1)
|
18
|
+
slop (~> 2.1.0)
|
19
|
+
rake (0.9.2.2)
|
20
|
+
ruby_parser (2.3.1)
|
21
|
+
sexp_processor (~> 3.0)
|
22
|
+
sexp_processor (3.0.10)
|
23
|
+
shoulda (2.11.3)
|
24
|
+
slop (2.1.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler
|
31
|
+
nfl_live_update!
|
32
|
+
pry
|
33
|
+
rake
|
34
|
+
shoulda
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
6
|
+
test.libs << 'lib' << 'test'
|
7
|
+
test.test_files = FileList['test/*_test.rb']
|
8
|
+
test.verbose = true
|
9
|
+
# test.warning = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
sh "pry -I lib -r nfl.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :test
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module GameCenter
|
4
|
+
class Game
|
5
|
+
|
6
|
+
attr_accessor :home, :away, :json
|
7
|
+
|
8
|
+
def initialize(json)
|
9
|
+
@next_update = json.delete("nextupdate")
|
10
|
+
@id = json.keys.first
|
11
|
+
json = json[@id.to_s]
|
12
|
+
@home = Team.new(json["home"])
|
13
|
+
@away = Team.new(json["away"])
|
14
|
+
|
15
|
+
@json = json
|
16
|
+
@json.delete("home")
|
17
|
+
@json.delete("away")
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
def test_game
|
23
|
+
eid = "2011122500"
|
24
|
+
url = "http://www.nfl.com/liveupdate/game-center/#{eid}/#{eid}_gtd.json"
|
25
|
+
new(JSON.parse(open(url).readlines.join))
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module GameCenter
|
4
|
+
class PlayerStat
|
5
|
+
|
6
|
+
attr_accessor :player_id, :player_name, :stats
|
7
|
+
|
8
|
+
def initialize(key, json)
|
9
|
+
@player_id = key
|
10
|
+
@player_name = json.delete("name")
|
11
|
+
@stats = json
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module GameCenter
|
4
|
+
class Team
|
5
|
+
|
6
|
+
attr_accessor :abbr, :time_outs, :players, :score, :stats
|
7
|
+
|
8
|
+
def initialize(json)
|
9
|
+
@abbr = json["abbr"]
|
10
|
+
@time_outs = json["to"]
|
11
|
+
@players = json["players"]
|
12
|
+
|
13
|
+
@score = TeamScore.new(json["score"])
|
14
|
+
@stats = json["stats"]
|
15
|
+
@stats.each do |k,v|
|
16
|
+
self.class.class_eval do
|
17
|
+
define_method("#{k}_stats") do
|
18
|
+
@stats[k]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@stats[k] = if k == "team"
|
22
|
+
TeamStat.new(@stats[k])
|
23
|
+
else
|
24
|
+
@stats[k].map do |k2,v2|
|
25
|
+
PlayerStat.new(k2, v2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def stat_categories
|
32
|
+
@stats.keys
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module GameCenter
|
4
|
+
class TeamScore
|
5
|
+
|
6
|
+
attr_accessor :first_quarter, :second_quarter, :third_quarter,
|
7
|
+
:forth_quarter, :overtime
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@first_quarter = json["1"]
|
11
|
+
@second_quarter = json["2"]
|
12
|
+
@third_quarter = json["3"]
|
13
|
+
@forth_quarter = json["4"]
|
14
|
+
@overtime = json["5"]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module GameCenter
|
4
|
+
class TeamStat
|
5
|
+
|
6
|
+
attr_accessor :first_downs, :total_yards, :passing_yards,
|
7
|
+
:rushing_yards, :penalties, :penalty_yards, :turnovers,
|
8
|
+
:punts, :punting_yards, :punting_average, :time_of_possession
|
9
|
+
|
10
|
+
def initialize(json)
|
11
|
+
@first_downs = json["totfd"]
|
12
|
+
@total_yards = json["totyds"]
|
13
|
+
@passing_yards = json["pyds"]
|
14
|
+
@rushing_yards = json["ryds"]
|
15
|
+
@penalties = json["pen"]
|
16
|
+
@penalty_yards = json["penyds"]
|
17
|
+
@punts = json["pt"]
|
18
|
+
@punting_yards = json["ptyds"]
|
19
|
+
@punting_average = json["ptavg"]
|
20
|
+
@time_of_possession = json["top"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module ScoreStrip
|
4
|
+
class Game
|
5
|
+
|
6
|
+
attr_accessor :id, :gsis, :day_of_week, :time_of_day, :status,
|
7
|
+
:home_abbr, :home_nickname, :home_score,
|
8
|
+
:visitor_abbr, :visitor_nickname, :visitor_score,
|
9
|
+
:red_zone, :ga, :game_type, :k, :p, :network
|
10
|
+
|
11
|
+
attr_reader :xml
|
12
|
+
|
13
|
+
def initialize(xml)
|
14
|
+
attributes = xml.attributes
|
15
|
+
attributes.each do |k,v|
|
16
|
+
attributes[k] = v.text
|
17
|
+
end
|
18
|
+
|
19
|
+
@id = attributes["eid"]
|
20
|
+
@gsis = attributes["gsis"]
|
21
|
+
@day_of_week = attributes["d"]
|
22
|
+
@time_of_day = attributes["t"]
|
23
|
+
@status = attributes["q"]
|
24
|
+
|
25
|
+
@home_abbr = attributes["h"]
|
26
|
+
@home_nickname = attributes["hnn"]
|
27
|
+
@home_score = attributes["hs"]
|
28
|
+
|
29
|
+
@visitor_abbr = attributes["v"]
|
30
|
+
@visitor_nickname = attributes["vnn"]
|
31
|
+
@visitor_score = attributes["vs"]
|
32
|
+
|
33
|
+
@red_zone = attributes["rz"]
|
34
|
+
@ga = attributes["ga"]
|
35
|
+
@game_type = attributes["gt"]
|
36
|
+
|
37
|
+
@k = attributes["k"]
|
38
|
+
@p = attributes["p"]
|
39
|
+
@network = attributes["n"]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def set_game_type(gt)
|
46
|
+
case gt
|
47
|
+
when "REG"
|
48
|
+
"Regular"
|
49
|
+
when "WC"
|
50
|
+
"Wild Card"
|
51
|
+
when "CON"
|
52
|
+
"Conference"
|
53
|
+
when "DIV"
|
54
|
+
"Division"
|
55
|
+
when "PRO"
|
56
|
+
"Pro Bowl"
|
57
|
+
else
|
58
|
+
gt
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NFL
|
2
|
+
module LiveUpdate
|
3
|
+
module ScoreStrip
|
4
|
+
class Games
|
5
|
+
|
6
|
+
LIVE_UPDATE_URL = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"
|
7
|
+
AJAX_URL = "http://www.nfl.com/ajax/scorestrip"
|
8
|
+
|
9
|
+
def initialize(xml)
|
10
|
+
gms = xml.xpath("//ss//gms").first
|
11
|
+
|
12
|
+
@week = gms.attribute("w").value
|
13
|
+
@year = gms.attribute("y").value
|
14
|
+
@type = gms.attribute("t").value
|
15
|
+
@gd = gms.attribute("gd").value
|
16
|
+
@bph = gms.attribute("bph").value
|
17
|
+
@games = gms.xpath("//g").map {|g| Game.new(g) }
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
def current
|
23
|
+
new(get(LIVE_UPDATE_URL))
|
24
|
+
end
|
25
|
+
|
26
|
+
def url(params={})
|
27
|
+
season = params[:season] || Time.now.year
|
28
|
+
season_type = params[:season_type] || "REG"
|
29
|
+
week = params[:week]
|
30
|
+
"#{AJAX_URL}?season=#{season}&seasonType=#{season_type}&week=#{week}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def where(params)
|
34
|
+
new(get(url(params)))
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(url)
|
38
|
+
Nokogiri::XML(open(url))
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/nfl.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'rss'
|
5
|
+
|
6
|
+
require './lib/nfl/live_update/score_strip'
|
7
|
+
require './lib/nfl/live_update/game_center'
|
8
|
+
|
9
|
+
module NFL
|
10
|
+
|
11
|
+
def self.score_strip
|
12
|
+
NFL::LiveUpdate::ScoreStrip::Games.current
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.test_game
|
16
|
+
NFL::LiveUpdate::GameCenter::Game.test_game
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "nfl/live_update/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "nfl_live_update"
|
6
|
+
s.version = NFL::LiveUpdate::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Jon Karna"]
|
9
|
+
s.email = ["ipg49vv2@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/jonkarna/nfl_live_update"
|
11
|
+
s.summary = %q{A simple Ruby framework for building REST-like APIs.}
|
12
|
+
s.description = %q{A Ruby framework for rapid API development with great conventions.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "nfl_live_update"
|
15
|
+
|
16
|
+
s.add_runtime_dependency "nokogiri"
|
17
|
+
|
18
|
+
s.add_development_dependency "rake"
|
19
|
+
s.add_development_dependency "pry"
|
20
|
+
s.add_development_dependency "bundler"
|
21
|
+
s.add_development_dependency "shoulda"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'turn'
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_record/fixtures'
|
5
|
+
require 'yaml'
|
6
|
+
require 'sqlite3'
|
7
|
+
require 'enumerated_field'
|
8
|
+
require 'shoulda'
|
9
|
+
require 'shoulda/active_record'
|
10
|
+
|
11
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :apples, :force => true do |t|
|
14
|
+
t.string :color
|
15
|
+
t.string :kind
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Apple < ActiveRecord::Base
|
20
|
+
include EnumeratedField
|
21
|
+
|
22
|
+
enum_field :color, [['Red', :red], ['Green', :green]], :validate => false
|
23
|
+
enum_field :kind, [['Fuji Apple', :fuji], ['Delicious Red Apple', :delicious]], :validate => false
|
24
|
+
end
|
25
|
+
|
26
|
+
class Banana
|
27
|
+
include EnumeratedField
|
28
|
+
include ActiveModel::Validations
|
29
|
+
|
30
|
+
attr_accessor :brand
|
31
|
+
attr_accessor :color
|
32
|
+
attr_accessor :tastiness
|
33
|
+
|
34
|
+
enum_field :brand, [["Chiquita", :chiquita], ["Del Monte", :delmonte]]
|
35
|
+
enum_field :color, [["Awesome Yellow", :yellow], ["Icky Green", :green]], :allow_nil => true
|
36
|
+
# stressing the constantizing of the keys
|
37
|
+
enum_field :tastiness, [
|
38
|
+
["Great", "great!"],
|
39
|
+
["Good", "it's good"],
|
40
|
+
["Bad", "hate-hate"],
|
41
|
+
], :validate => false
|
42
|
+
|
43
|
+
def initialize(brand, color)
|
44
|
+
self.brand = brand
|
45
|
+
self.color = color
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Fixtures.create_fixtures 'test/fixtures', :apples
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nfl_live_update
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Karna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &2165580640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2165580640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &2165580220 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2165580220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: pry
|
38
|
+
requirement: &2165579780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2165579780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &2165579320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2165579320
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: shoulda
|
60
|
+
requirement: &2165578880 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2165578880
|
69
|
+
description: A Ruby framework for rapid API development with great conventions.
|
70
|
+
email:
|
71
|
+
- ipg49vv2@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .rvmrc
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- Rakefile
|
80
|
+
- lib/nfl.rb
|
81
|
+
- lib/nfl/live_update/game_center.rb
|
82
|
+
- lib/nfl/live_update/game_center/game.rb
|
83
|
+
- lib/nfl/live_update/game_center/player_stat.rb
|
84
|
+
- lib/nfl/live_update/game_center/team.rb
|
85
|
+
- lib/nfl/live_update/game_center/team_score.rb
|
86
|
+
- lib/nfl/live_update/game_center/team_stat.rb
|
87
|
+
- lib/nfl/live_update/score_strip.rb
|
88
|
+
- lib/nfl/live_update/score_strip/game.rb
|
89
|
+
- lib/nfl/live_update/score_strip/games.rb
|
90
|
+
- lib/nfl/live_update/version.rb
|
91
|
+
- nfl_live_update.gemspec
|
92
|
+
- test/fixtures/apples.yml
|
93
|
+
- test/test_helper.rb
|
94
|
+
- test/unit/score_strip_games_test.rb
|
95
|
+
homepage: https://github.com/jonkarna/nfl_live_update
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 2352121008628860136
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 2352121008628860136
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project: nfl_live_update
|
121
|
+
rubygems_version: 1.8.10
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: A simple Ruby framework for building REST-like APIs.
|
125
|
+
test_files:
|
126
|
+
- test/fixtures/apples.yml
|
127
|
+
- test/test_helper.rb
|
128
|
+
- test/unit/score_strip_games_test.rb
|