live_update 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/MIT-LICENSE +20 -0
- data/README.md +49 -0
- data/Rakefile +34 -0
- data/config/initializers/inflections.rb +20 -0
- data/lib/live_update.rb +7 -0
- data/lib/live_update/game.rb +68 -0
- data/lib/live_update/schedule.rb +33 -0
- data/lib/live_update/version.rb +3 -0
- data/lib/tasks/live_update_tasks.rake +4 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 680a4bc6b6b793b4a9f58d7225cb6a871b6aa66d
|
4
|
+
data.tar.gz: 2f7e931d6897e1a855101e9800e1980591eabf40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 635f941ade8b438651cc6d6d7892809860d0628f7b35b352a45c24123a35c2714b27343241137fa72f61d009cfb95e819200fcd340ab03b20c18ce2ba9501e7d
|
7
|
+
data.tar.gz: 42cf4215a3cd92a60c82b8ac5d730dca04677b9b75d64574c89981dd1a3cd02d55eae7457ca77a4b213ba0ba1cdce856c3193b3c58584cc2621996ff4fb00288
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Dave Nguyen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# NFL Live Update
|
2
|
+
Get NFL schedules and live scores through official feeds.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'live_update'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
```bash
|
18
|
+
$ gem install live_update
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# Pull the latest schedule
|
25
|
+
schedule = LiveUpdate::Schedule.new
|
26
|
+
|
27
|
+
# Grab some stats about the schedule
|
28
|
+
schedule.week #=> 14
|
29
|
+
schedule.year #=> 2016
|
30
|
+
schedule.games #=> [#<LiveUpdate::Game>, ...]
|
31
|
+
|
32
|
+
# Get the raw data:
|
33
|
+
schedule._data #=> {:ss=>{:gms=>{:w=>"13", :y=>"2016", ...}}}
|
34
|
+
schedule._xml #=> "<?xml version=\"1.0\" ..."
|
35
|
+
|
36
|
+
# Find game by ID and grab its stats
|
37
|
+
game = schedule.game(id)
|
38
|
+
game.started? #=> true
|
39
|
+
game.final? #=> false
|
40
|
+
game.home #=> PHI
|
41
|
+
game.possession #=> PHI
|
42
|
+
game.quarter #=> 4
|
43
|
+
game.clock #=> 02:13
|
44
|
+
game.home_score #=> 24
|
45
|
+
game._data #=> {:eid=>"2016120100", :gsis=>"57078", ...}
|
46
|
+
```
|
47
|
+
|
48
|
+
## License
|
49
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'LiveUpdate'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym 'RESTful'
|
16
|
+
# end
|
17
|
+
|
18
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
19
|
+
inflect.acronym 'NFL'
|
20
|
+
end
|
data/lib/live_update.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module LiveUpdate
|
2
|
+
class Game
|
3
|
+
FEED_URL = 'scorestrip/ss.xml'
|
4
|
+
GAME_TYPES = { CON: 'Conference', DIV: 'Division', PRO: 'Pro Bowl',
|
5
|
+
REG: 'Regular', WC: 'Wild Card' }.with_indifferent_access
|
6
|
+
|
7
|
+
attr_reader :_data, :home, :id, :possession, :quarter, :starts_at,
|
8
|
+
:clock, :type, :updated_at, :visitor
|
9
|
+
|
10
|
+
def initialize(data)
|
11
|
+
@_data = data
|
12
|
+
@updated_at = Time.now
|
13
|
+
parse
|
14
|
+
end
|
15
|
+
|
16
|
+
def final?
|
17
|
+
quarter == 'F'
|
18
|
+
end
|
19
|
+
|
20
|
+
def started?
|
21
|
+
quarter != 'P'
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse
|
27
|
+
parse_id
|
28
|
+
parse_type
|
29
|
+
parse_starts_at
|
30
|
+
parse_game_stats
|
31
|
+
parse_teams
|
32
|
+
parse_scores
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_game_stats
|
36
|
+
@possession = _data[:p]
|
37
|
+
@quarter = _data[:q]
|
38
|
+
@clock = _data[:k]
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_id
|
42
|
+
@id = _data[:eid]
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_scores
|
46
|
+
@home_score = _data[:hs]
|
47
|
+
@visitor_score = _data[:vs]
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_starts_at
|
51
|
+
date = id[0..-3]
|
52
|
+
time = _data[:t]
|
53
|
+
tz = 'Eastern Time (US & Canada)'
|
54
|
+
@starts_at = DateTime.parse("#{date} #{time} #{tz}") + 12.hours
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_teams
|
58
|
+
@home = _data[:h]
|
59
|
+
@home_name = _data[:hnn].capitalize
|
60
|
+
@visitor = _data[:v]
|
61
|
+
@visitor_name = _data[:vnn].capitalize
|
62
|
+
end
|
63
|
+
|
64
|
+
def parse_type
|
65
|
+
@type = GAME_TYPES[_data[:gt]] || _data[:gt]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LiveUpdate
|
2
|
+
class Schedule
|
3
|
+
FEED_URL = 'scorestrip/ss.xml'
|
4
|
+
|
5
|
+
attr_reader :_data, :_xml, :games, :updated_at, :week, :year
|
6
|
+
|
7
|
+
def initialize(path = nil)
|
8
|
+
@_xml = open(path || (BASE_URL + FEED_URL)).read
|
9
|
+
@updated_at = Time.now
|
10
|
+
@_data = Hash.from_xml(_xml).deep_symbolize_keys!
|
11
|
+
parse
|
12
|
+
end
|
13
|
+
|
14
|
+
def game(id)
|
15
|
+
games.find { |game| game.id == id }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse
|
21
|
+
@week = _data[:ss][:gms][:w].to_i
|
22
|
+
@year = _data[:ss][:gms][:y].to_i
|
23
|
+
parse_games
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_games
|
27
|
+
@games = []
|
28
|
+
_data[:ss][:gms][:g].each do |game|
|
29
|
+
games << Game.new(game)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: live_update
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.0.1
|
33
|
+
description: Get NFL schedules and live scores through official feeds.
|
34
|
+
email:
|
35
|
+
- Dave.Nguyen@inthenight.net
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- config/initializers/inflections.rb
|
44
|
+
- lib/live_update.rb
|
45
|
+
- lib/live_update/game.rb
|
46
|
+
- lib/live_update/schedule.rb
|
47
|
+
- lib/live_update/version.rb
|
48
|
+
- lib/tasks/live_update_tasks.rake
|
49
|
+
homepage: https://github.com/davenguyen/live_update
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.8
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Get NFL schedules and live scores through official feeds.
|
73
|
+
test_files: []
|