nba 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +27 -0
- data/Gemfile +10 -0
- data/README.md +60 -2
- data/Rakefile +18 -0
- data/lib/nba/player.rb +3 -5
- data/lib/nba/team.rb +3 -3
- data/lib/nba/version.rb +1 -1
- data/nba.gemspec +1 -2
- data/spec/nba_spec.rb +73 -0
- data/spec/spec_helper.rb +25 -0
- metadata +8 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91a5381ea2ab0af2822bd27dbe4d0e12ec4514c7
|
4
|
+
data.tar.gz: b90e24f82c2e1dd024b59c2299a32e8afc46597e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63791f32a033ad8bcf725c38bbc3150453bbd2669a974edcd02679980087de0fd5f6b3e6c6b14a2c8fa9587b02f93398e293048f6355047aca09f76cc0bede73
|
7
|
+
data.tar.gz: f4f92cc7eaac36c0bfa2c8d09e670500d1f0289924867e88ee480575ad904e7f7db8437609003dec0e51077e740a94fad0a3c012a279598bc70e617ec0bc866d
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem update bundler
|
3
|
+
- bundle --version
|
4
|
+
- gem update --system 2.1.11
|
5
|
+
- gem --version
|
6
|
+
bundler_args: --without development
|
7
|
+
language: ruby
|
8
|
+
rvm:
|
9
|
+
- 1.8.7
|
10
|
+
- 1.9.2
|
11
|
+
- 1.9.3
|
12
|
+
- 2.0.0
|
13
|
+
- 2.1.0
|
14
|
+
- rbx
|
15
|
+
- ruby-head
|
16
|
+
matrix:
|
17
|
+
include:
|
18
|
+
- rvm: jruby-18mode
|
19
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
20
|
+
- rvm: jruby-19mode
|
21
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
22
|
+
- rvm: jruby-head
|
23
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
24
|
+
allow_failures:
|
25
|
+
- rvm: jruby-head
|
26
|
+
- rvm: ruby-head
|
27
|
+
fast_finish: true
|
data/Gemfile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'rake'
|
4
|
+
|
3
5
|
group :development do
|
4
6
|
gem 'pry'
|
5
7
|
gem 'pry-rescue'
|
@@ -9,5 +11,13 @@ group :development do
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
group :test do
|
15
|
+
gem 'rspec', '>= 2.11'
|
16
|
+
gem 'webmock'
|
17
|
+
end
|
18
|
+
|
19
|
+
gem 'jruby-openssl', :platforms => :jruby
|
20
|
+
gem 'rubysl', '~> 2.0', :platform => :rbx
|
21
|
+
|
12
22
|
# Specify your gem's dependencies in nba.gemspec
|
13
23
|
gemspec
|
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# NBA.rb
|
2
2
|
|
3
|
+
[][gem]
|
4
|
+
[][travis]
|
5
|
+
|
6
|
+
[gem]: https://rubygems.org/gems/nba
|
7
|
+
[travis]: https://travis-ci.org/larrylv/nba
|
8
|
+
|
3
9
|
NBA.rb is a Ruby library for retrieving NBA League players, teams and divisions.
|
4
10
|
|
5
|
-
Insipred by @sferik's [MLB]
|
11
|
+
Insipred by [@sferik][sferik]'s [MLB.rb][mlb].
|
12
|
+
|
13
|
+
[sferik]: https://github.com/sferik
|
14
|
+
[mlb]: https://github.com/sferik/mlb
|
6
15
|
|
7
16
|
## Installation
|
8
17
|
gem install nba
|
@@ -17,9 +26,58 @@ Insipred by @sferik's [MLB](https://github.com/sferik/mlb).
|
|
17
26
|
>> NBA::Team.all.first.players.first.number # => 15
|
18
27
|
>> NBA::Team.all.first.players.first.position # => ["Forward-center"]
|
19
28
|
|
29
|
+
## Supported Ruby Versions
|
30
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
31
|
+
implementations:
|
32
|
+
|
33
|
+
* Ruby 1.8.7
|
34
|
+
* Ruby 1.9.2
|
35
|
+
* Ruby 1.9.3
|
36
|
+
* Ruby 2.0.0
|
37
|
+
* Ruby 2.1.0
|
38
|
+
* [Rubinius][]
|
39
|
+
* [JRuby][]
|
40
|
+
|
41
|
+
[rubinius]: http://rubini.us/
|
42
|
+
[jruby]: http://jruby.org/
|
43
|
+
|
44
|
+
If something doesn't work on one of these interpreters, it's a bug.
|
45
|
+
|
46
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
47
|
+
implementations, however support will only be provided for the versions listed
|
48
|
+
above.
|
49
|
+
|
50
|
+
If you would like this library to support another Ruby version, you may
|
51
|
+
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
52
|
+
run and pass on that implementation. When something breaks on your
|
53
|
+
implementation, you will be responsible for providing patches in a timely
|
54
|
+
fashion. If critical issues for a particular implementation exist at the time
|
55
|
+
of a major release, support for that Ruby version may be dropped.
|
56
|
+
|
57
|
+
## Colophon
|
58
|
+
NBA was built with the following tools:
|
59
|
+
|
60
|
+
* [Bundler][]
|
61
|
+
* [Freebase][]
|
62
|
+
* [Faraday][]
|
63
|
+
* [Markdown][]
|
64
|
+
* [RSpec][]
|
65
|
+
* [vim][]
|
66
|
+
* [WebMock][]
|
67
|
+
|
68
|
+
[bundler]: http://gembundler.com/
|
69
|
+
[freebase]: http://www.freebase.com/
|
70
|
+
[faraday]: https://github.com/technoweenie/faraday
|
71
|
+
[markdown]: http://daringfireball.net/projects/markdown/
|
72
|
+
[rspec]: http://relishapp.com/rspec/
|
73
|
+
[vim]: http://www.vim.org/
|
74
|
+
[webmock]: https://github.com/bblimke/webmock
|
75
|
+
|
76
|
+
And, special thanks to [@sfeirk][sferik]!
|
77
|
+
|
20
78
|
## Contributing
|
21
79
|
|
22
|
-
1. Fork it ( http://github.com
|
80
|
+
1. Fork it ( http://github.com/larrylv/nba/fork )
|
23
81
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
82
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
25
83
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1 +1,19 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :test => :spec
|
7
|
+
|
8
|
+
namespace :cache do
|
9
|
+
require 'nba'
|
10
|
+
desc 'Update the teams file cache'
|
11
|
+
task :update do
|
12
|
+
doc = NBA::Team.results_from_freebase(true)
|
13
|
+
File.open('cache/teams.json', 'w') do |file|
|
14
|
+
file.write(doc.body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => [:spec]
|
data/lib/nba/player.rb
CHANGED
@@ -10,17 +10,15 @@ module NBA
|
|
10
10
|
|
11
11
|
# Returns an array of Player objects given a team roster
|
12
12
|
def self.all_from_roster(players)
|
13
|
-
players.map do |player|
|
14
|
-
next if player['to'] != nil
|
15
|
-
|
13
|
+
players.select{ |player| player['to'].nil? }.map do |player|
|
16
14
|
new(
|
17
15
|
:name => player['player'],
|
18
16
|
:number => player['number'],
|
19
17
|
:position => player['position'],
|
20
18
|
:from => player['from'],
|
21
|
-
:to =>
|
19
|
+
:to => "Present"
|
22
20
|
)
|
23
|
-
end
|
21
|
+
end
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
data/lib/nba/team.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'multi_json'
|
3
2
|
|
4
3
|
module NBA
|
5
4
|
class Team
|
@@ -19,7 +18,7 @@ module NBA
|
|
19
18
|
# connection error, in which case read from a fixture file
|
20
19
|
@all ||= begin
|
21
20
|
results_to_team(results_from_freebase)
|
22
|
-
rescue Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError
|
21
|
+
rescue Errno::EHOSTUNREACH, Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError
|
23
22
|
results_to_team(results_from_cache)
|
24
23
|
end
|
25
24
|
end
|
@@ -85,7 +84,8 @@ module NBA
|
|
85
84
|
"player": null,
|
86
85
|
"from": null,
|
87
86
|
"to": null,
|
88
|
-
"position": []
|
87
|
+
"position": [],
|
88
|
+
"sort": "player"
|
89
89
|
}],
|
90
90
|
"sort": "name",
|
91
91
|
"type": "/basketball/basketball_team",
|
data/lib/nba/version.rb
CHANGED
data/nba.gemspec
CHANGED
@@ -20,8 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'faraday', ['~> 0.8', '< 0.10']
|
22
22
|
spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
|
23
|
-
spec.
|
23
|
+
spec.add_dependency 'json', '~> 1.8'
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
-
spec.add_development_dependency "rake"
|
27
26
|
end
|
data/spec/nba_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NBA::Team, '.all' do
|
4
|
+
context 'with connection' do
|
5
|
+
before do
|
6
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_return(:body => fixture('teams.json'))
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
NBA::Team.reset
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'requests the correct resource' do
|
14
|
+
NBA::Team.all
|
15
|
+
expect(a_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query})).to have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns the correct team results' do
|
19
|
+
teams = NBA::Team.all
|
20
|
+
expect(teams.first.name).to eq 'Atlanta Hawks'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns the correct player results' do
|
24
|
+
teams = NBA::Team.all
|
25
|
+
expect(teams.first.players.first.name).to eq 'Al Horford'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with timeout' do
|
30
|
+
before do
|
31
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_timeout
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
NBA::Team.reset
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns the correct results' do
|
39
|
+
teams = NBA::Team.all
|
40
|
+
expect(teams.first.name).to eq 'Atlanta Hawks'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'without connection' do
|
45
|
+
before do
|
46
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_raise(SocketError)
|
47
|
+
end
|
48
|
+
|
49
|
+
after do
|
50
|
+
NBA::Team.reset
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns the correct results' do
|
54
|
+
teams = NBA::Team.all
|
55
|
+
expect(teams.first.name).to eq 'Atlanta Hawks'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with no route to host' do
|
60
|
+
before do
|
61
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_raise(Errno::EHOSTUNREACH)
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
NBA::Team.reset
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns the correct results' do
|
69
|
+
teams = NBA::Team.all
|
70
|
+
expect(teams.first.name).to eq 'Atlanta Hawks'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nba'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
WebMock.disable_net_connect!
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
def fixture_path
|
20
|
+
File.expand_path('../../cache', __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fixture(file)
|
24
|
+
File.new(fixture_path + '/' + file)
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Lv
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0.9'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: json
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
@@ -72,20 +72,6 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.5'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rake
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
75
|
description: NBA.rb is a Ruby library for retrieving NBA League players, teams and
|
90
76
|
divisions
|
91
77
|
email:
|
@@ -95,6 +81,7 @@ extensions: []
|
|
95
81
|
extra_rdoc_files: []
|
96
82
|
files:
|
97
83
|
- ".gitignore"
|
84
|
+
- ".travis.yml"
|
98
85
|
- Gemfile
|
99
86
|
- LICENSE.md
|
100
87
|
- LICENSE.txt
|
@@ -107,6 +94,8 @@ files:
|
|
107
94
|
- lib/nba/team.rb
|
108
95
|
- lib/nba/version.rb
|
109
96
|
- nba.gemspec
|
97
|
+
- spec/nba_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
110
99
|
homepage: ''
|
111
100
|
licenses:
|
112
101
|
- MIT
|
@@ -131,4 +120,6 @@ rubygems_version: 2.2.0
|
|
131
120
|
signing_key:
|
132
121
|
specification_version: 4
|
133
122
|
summary: NBA.rb is a Ruby library for retrieving NBA League players, teams and divisions
|
134
|
-
test_files:
|
123
|
+
test_files:
|
124
|
+
- spec/nba_spec.rb
|
125
|
+
- spec/spec_helper.rb
|