Class: FFNerd

Inherits:
Object
  • Object
show all
Extended by:
CommercialFeeds, Request
Defined in:
lib/fantasy_football_nerd.rb

Constant Summary collapse

@@api_key =
nil

Class Method Summary collapse

Methods included from Request

base_url, request_service, service_url

Methods included from CommercialFeeds

create_stats_ostruct, is_float_stat?, new_keys, player_info, player_stats

Class Method Details

.api_keyObject



15
16
17
18
19
# File 'lib/fantasy_football_nerd.rb', line 15

def self.api_key
  @@api_key ||= ENV['FFNERD_API_KEY']
  raise 'API key not set' if @@api_key.nil?
  @@api_key
end

.api_key=(key) ⇒ Object



21
22
23
# File 'lib/fantasy_football_nerd.rb', line 21

def self.api_key=(key)
  @@api_key = key
end

.auction_valuesObject



59
60
61
# File 'lib/fantasy_football_nerd.rb', line 59

def self.auction_values
  ostruct_request('auction', 'AuctionValues')
end

.byes(week) ⇒ Object



49
50
51
52
# File 'lib/fantasy_football_nerd.rb', line 49

def self.byes(week)
  raise "Must include a bye week between 4 and 12" unless (4..12).include?(week)
  ostruct_request('byes', "Bye Week #{week}")
end

.current_weekObject



25
26
27
28
# File 'lib/fantasy_football_nerd.rb', line 25

def self.current_week
  player = request_service('schedule', api_key)
  player['currentWeek']
end

.draft_projections(position) ⇒ Object



72
73
74
75
# File 'lib/fantasy_football_nerd.rb', line 72

def self.draft_projections(position)
  raise "Must pass in a valid position" unless POSITIONS.include?(position)
  ostruct_request('draft-projections', 'DraftProjections', [position])
end

.injuries(week = nil) ⇒ Object



54
55
56
57
# File 'lib/fantasy_football_nerd.rb', line 54

def self.injuries(week = nil)
  extras = [week]
  ostruct_request('injuries', 'Injuries', extras)
end

.ostruct_request(service_name, json_key, extras = []) ⇒ Object



30
31
32
33
34
35
# File 'lib/fantasy_football_nerd.rb', line 30

def self.ostruct_request(service_name, json_key, extras = [])
  extras = [extras].flatten
  data = request_service(service_name, api_key, extras)[json_key]
  data = data.values.flatten if data.is_a? Hash
  data.collect { |i| OpenStruct.new(i.add_snakecase_keys) }
end

.playersObject



45
46
47
# File 'lib/fantasy_football_nerd.rb', line 45

def self.players
  ostruct_request('players', 'Players')
end

.ppr_draft_rankingsObject



67
68
69
70
# File 'lib/fantasy_football_nerd.rb', line 67

def self.ppr_draft_rankings
  #appended a 1 to url for ppr rankings
  ostruct_request('draft-rankings', 'DraftRankings', '1')
end

.scheduleObject



41
42
43
# File 'lib/fantasy_football_nerd.rb', line 41

def self.schedule
  ostruct_request('schedule', 'Schedule')
end

.standard_draft_rankingsObject



63
64
65
# File 'lib/fantasy_football_nerd.rb', line 63

def self.standard_draft_rankings
  ostruct_request('draft-rankings', 'DraftRankings')
end

.teamsObject



37
38
39
# File 'lib/fantasy_football_nerd.rb', line 37

def self.teams
  ostruct_request('nfl-teams', 'NFLTeams')
end

.weekly_projections(position, week = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/fantasy_football_nerd.rb', line 85

def self.weekly_projections(position, week = nil)
  #FFNerd defaults to current week if week is left blank
  raise "Weekly projections don't include DEF (but you can find those values in weekly rankings)" if position == "DEF"
  raise "Must pass in a valid position" unless POSITIONS.include?(position)
  raise "Your (optional) week must be between 1 and 17" if week && !(1..17).include?(week)
  week ||= current_week
  extras = [position, week]
  ostruct_request('weekly-projections', 'Projections', extras)
end

.weekly_rankings(position, week = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/fantasy_football_nerd.rb', line 77

def self.weekly_rankings(position, week = nil)
  raise "Must pass in a valid position" unless POSITIONS.include?(position)
  raise "Your (optional) week must be between 1 and 17" if week && !(1..17).include?(week)
  week ||= current_week
  extras = [position, week, 1]
  ostruct_request('weekly-rankings', 'Rankings', extras)
end