Class: YahooNba::Query
- Inherits:
-
Object
- Object
- YahooNba::Query
- Includes:
- PlayerIncludes
- Defined in:
- lib/yahoo_nba/yahoo_nba.rb
Instance Method Summary collapse
- #get_all_player_keys_hash ⇒ Object
- #get_player_stats_hash_with_player_key(player_key) ⇒ Object
- #get_player_stats_hash_with_player_name(player_name) ⇒ Object
- #get_players_info_array_starting_at(num) ⇒ Object
- #get_players_key_hash_from(players_info_array) ⇒ Object
- #get_players_stats_hash_using(players_key_hash) ⇒ Object
- #get_stats_categories ⇒ Object
-
#initialize(consumer_key, consumer_secret) ⇒ Query
constructor
A new instance of Query.
Methods included from PlayerIncludes
Constructor Details
#initialize(consumer_key, consumer_secret) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 12 13 14 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 7 def initialize(consumer_key, consumer_secret) consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://fantasysports.yahooapis.com', :http_method => :get) @access_token = OAuth::AccessToken.new(consumer) @player_key_hash = player_key_hash end |
Instance Method Details
#get_all_player_keys_hash ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 47 def get_all_player_keys_hash combined_array = [] 0.step(500, 25) do |n| combined_array = combined_array | get_players_info_array_starting_at(n) end get_players_key_hash_from(combined_array) end |
#get_player_stats_hash_with_player_key(player_key) ⇒ Object
38 39 40 41 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 38 def get_player_stats_hash_with_player_key(player_key) player_stats_xml = @access_token.get("/fantasy/v2/player/#{player_key}/stats") player_stats = Crack::XML.parse(player_stats_xml.body)["fantasy_content"]["player"] end |
#get_player_stats_hash_with_player_name(player_name) ⇒ Object
43 44 45 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 43 def get_player_stats_hash_with_player_name(player_name) get_player_stats_hash_with_player_key(@player_key_hash[player_name]) end |
#get_players_info_array_starting_at(num) ⇒ Object
16 17 18 19 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 16 def get_players_info_array_starting_at(num) players_info_xml = @access_token.get("/fantasy/v2/game/249/players;start=#{num};count=25") players_info_array = Crack::XML.parse(players_info_xml.body)['fantasy_content']['game']['players']['player'] end |
#get_players_key_hash_from(players_info_array) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 21 def get_players_key_hash_from(players_info_array) players_key_hash = {} players_info_array.each do |item| players_key_hash[item["name"]["full"]] = item['player_key'] end players_key_hash end |
#get_players_stats_hash_using(players_key_hash) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 29 def get_players_stats_hash_using(players_key_hash) players_stats_hash = {} players_key_hash.each do |player_name, player_key| player_stats = get_player_stats_hash_with_player_key(player_key) players_stats_hash[player_name] = player_stats end players_stats_hash end |
#get_stats_categories ⇒ Object
55 56 57 58 |
# File 'lib/yahoo_nba/yahoo_nba.rb', line 55 def get_stats_categories stats_categories_xml = @access_token.get("/fantasy/v2/game/nba/stat_categories") stats_categories_hash = Crack::XML.parse(stats_categories_xml.body)["fantasy_content"]["game"]["stat_categories"]["stats"] end |