yahoo_nba 0.0.1.alpha → 0.0.2.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in yahoo_nba.gemspec
4
4
  gemspec
5
+
6
+ gem 'oauth'
7
+ gem 'crack'
8
+
@@ -1,3 +1,3 @@
1
1
  module YahooNba
2
- VERSION = "0.0.1.alpha"
2
+ VERSION = "0.0.2.alpha"
3
3
  end
@@ -0,0 +1,33 @@
1
+ module YahooNba
2
+ class Query
3
+
4
+ def initialize(consumer_key, consumer_secret)
5
+ consumer = ::OAuth::Consumer.new(consumer_key,
6
+ consumer_secret,
7
+ :site => 'http://fantasysports.yahooapis.com',
8
+ :http_method => :get)
9
+ @access_token = OAuth::AccessToken.new(consumer)
10
+ end
11
+
12
+ def get_players_info_array_starting_at(num)
13
+ players_info_xml = @access_token.get("/fantasy/v2/game/249/players;start=#{num};count=25")
14
+ players_info_array = Crack::XML.parse(players_info_xml.body)['fantasy_content']['game']['players']['player']
15
+ end
16
+
17
+ def get_players_key_hash_from(players_info_array)
18
+ players_key_hash = {}
19
+ players_info_array.each{|item| players_key_hash[item["name"]["full"]] = item['player_key']}
20
+ players_key_hash
21
+ end
22
+
23
+ def get_players_stats_hash_using(players_key_hash)
24
+ players_stats_hash = {}
25
+ players_key_hash.each do |player_name, player_id|
26
+ player_stats_xml = @access_token.get("/fantasy/v2/player/#{player_id}/stats")
27
+ player_stats = Crack::XML.parse(player_stats_xml.body)["fantasy_content"]["player"]
28
+ players_stats_hash[player_name] = player_stats
29
+ end
30
+ players_stats_hash
31
+ end
32
+ end
33
+ end
data/lib/yahoo_nba.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "yahoo_nba/version"
2
+ require "yahoo_nba/yahoo_nba"
3
+ require 'oauth'
4
+ require 'crack'
2
5
 
3
- module YahooNba
4
- # Your code goes here...
5
- end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe YahooNba do
4
+
5
+ it "allows rspec to work" do
6
+ true.should equal(true)
7
+ end
8
+
9
+ describe YahooNba::Query do
10
+ before(:each) do
11
+ @consumer_key = "dj0yJmk9Z3ExYnVlRERPekVDJmQ9WVdrOVlWTnJOV2t6TlRRbWNHbzlNVFEzTnpRd09EUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iNw--"
12
+ @consumer_secret = "a7d3c791b23f35774c608b7863b2d47508560927"
13
+ end
14
+
15
+ it "should have initialize creates a new Query" do
16
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
17
+ query.should_not equal(nil)
18
+ query.class.should equal(YahooNba::Query)
19
+ end
20
+
21
+ it "should have initialize creates new OAuth::Consumer" do
22
+ OAuth::Consumer.should_receive(:new).with(@consumer_key, @consumer_secret, anything)
23
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
24
+ end
25
+
26
+ it "should have initialize sets access_token" do
27
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
28
+ query.instance_variable_get(:@access_token).should_not equal(nil)
29
+ end
30
+
31
+ it "should have get_players_starting_at call get on the access token and parse the response" do
32
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
33
+ access_token = query.instance_variable_get(:@access_token)
34
+ num = 20
35
+ mock_xml = double
36
+ mock_response = double(:body => mock_xml)
37
+ access_token.should_receive(:get).with("/fantasy/v2/game/249/players;start=#{num};count=25").and_return(mock_response)
38
+ Crack::XML.should_receive(:parse).with(mock_xml).and_return({'fantasy_content' => {'game' => {'players' => {'player' => 'right!'}}}})
39
+ query.get_players_info_array_starting_at(num).should == 'right!'
40
+ end
41
+
42
+ it "should get players key has from players_info array" do
43
+ players_info_array = [{"player_key"=>"249.p.4244", "player_id"=>"4244", "name"=>{"full"=>"Kevin Durant", "first"=>"Kevin", "last"=>"Durant", "ascii_first"=>"Kevin", "ascii_last"=>"Durant"}, "editorial_player_key"=>"nba.p.4244", "editorial_team_key"=>"nba.t.25", "editorial_team_full_name"=>"Oklahoma City Thunder", "editorial_team_abbr"=>"OKC", "uniform_number"=>"35", "display_position"=>"SF", "image_url"=>"http://l.yimg.com/a/i/us/sp/v/nba/players_l/20101116/4244.jpg?x=46&y=60&xc=1&yc=1&wc=164&hc=215&q=100&sig=OTXf3hs63PFp0fv8wxtCIg--", "is_undroppable"=>"0", "position_type"=>"P", "eligible_positions"=>{"position"=>"SF"}, "has_player_notes"=>"1", "has_recent_player_notes"=>"1"}]
44
+ players_key_hash = {"Kevin Durant"=>"249.p.4244"}
45
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
46
+ hash_results = query.get_players_key_hash_from(players_info_array)
47
+ hash_results.should == players_key_hash
48
+ end
49
+
50
+ it "should get players stats using players_key_hash" do
51
+ query = YahooNba::Query.new(@consumer_key, @consumer_secret)
52
+ players_key_hash = {"Kevin Durant"=>"249.p.4244"}
53
+ access_token = query.instance_variable_get(:@access_token)
54
+ mock_xml = double
55
+ mock_response = double(:body => mock_xml)
56
+ access_token.should_receive(:get).with("/fantasy/v2/player/#{players_key_hash['Kevin Durant']}/stats").and_return(mock_response)
57
+ Crack::XML.should_receive(:parse).with(mock_xml).and_return({"fantasy_content" => {"player" => "the right stats!"}})
58
+ player_stats_hash = query.get_players_stats_hash_using(players_key_hash)
59
+ player_stats_hash.should == {"Kevin Durant" => "the right stats!"}
60
+ end
61
+
62
+ end
63
+
64
+ end
data/yahoo_nba.gemspec CHANGED
@@ -15,5 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = YahooNba::VERSION
17
17
 
18
+ gem.add_development_dependency "rake"
18
19
  gem.add_development_dependency "rspec"
19
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo_nba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 0.0.2.alpha
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-24 00:00:00.000000000 Z
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70167040790720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70167040790720
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &70206894442260 !ruby/object:Gem::Requirement
27
+ requirement: &70167040790300 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,7 +32,7 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70206894442260
35
+ version_requirements: *70167040790300
25
36
  description: Get nba stats using yahoo api
26
37
  email:
27
38
  - ! "jc582@optonline.net\t"
@@ -31,14 +42,16 @@ extra_rdoc_files: []
31
42
  files:
32
43
  - .gitignore
33
44
  - .rspec
45
+ - .travis.yml
34
46
  - Gemfile
35
47
  - LICENSE
36
48
  - README.md
37
49
  - Rakefile
38
50
  - lib/yahoo_nba.rb
39
51
  - lib/yahoo_nba/version.rb
52
+ - lib/yahoo_nba/yahoo_nba.rb
40
53
  - spec/spec_helper.rb
41
- - spec/yahoo_nba_spec.rb
54
+ - spec/yahoo_nba/yahoo_nba_spec.rb
42
55
  - yahoo_nba.gemspec
43
56
  homepage: ''
44
57
  licenses: []
@@ -66,4 +79,4 @@ specification_version: 3
66
79
  summary: Gem to get nba player stats using yahoo api
67
80
  test_files:
68
81
  - spec/spec_helper.rb
69
- - spec/yahoo_nba_spec.rb
82
+ - spec/yahoo_nba/yahoo_nba_spec.rb
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- describe YahooNba do
3
- it "allows rspec to work" do
4
- true.should equal(true)
5
- end
6
- end