fantasy_football_nerd 0.9.0 → 1.0.1

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.
Files changed (23) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +260 -120
  3. data/lib/fantasy_football_nerd.rb +56 -201
  4. data/lib/fantasy_football_nerd/request.rb +19 -0
  5. data/lib/fantasy_football_nerd/util.rb +29 -0
  6. data/spec/api_key_setter_spec.rb +18 -0
  7. data/spec/fantasy_football_nerd_spec.rb +162 -154
  8. data/spec/request_spec.rb +16 -0
  9. data/spec/spec_helper.rb +12 -0
  10. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_auction_values.yml +331 -0
  11. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_bye_weeks.yml +70 -0
  12. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_draft_projections.yml +98 -0
  13. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_injuries_with_a_week.yml +847 -0
  14. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_injuries_without_a_week.yml +844 -0
  15. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_players.yml +1674 -0
  16. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_teams.yml +70 -0
  17. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_the_current_week.yml +306 -0
  18. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_the_ppr_draft_rankings.yml +1170 -0
  19. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_the_schedule.yml +306 -0
  20. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_the_standard_draft_rankings.yml +1167 -0
  21. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_weekly_projections.yml +108 -0
  22. data/spec/vcr/cassettes/Fantasy_Football_Nerd_Gem/should_retrieve_weekly_rankings.yml +112 -0
  23. metadata +27 -43
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb05673e2ae71ef09f1f6f36d69689c0769c7602
4
+ data.tar.gz: ce806bf9400433cabd4c01fb09bd3db1f604e0c7
5
+ SHA512:
6
+ metadata.gz: c451073cafd872881ad09a3f08c4d85678450579d660dcbb4783e246cb292d52cf23f91271c86a2abf089f51076e125f7de15a81b6bdb7dfb441851bf65f5c36
7
+ data.tar.gz: 9a8a1f831619960aaea70d6ebd802bd7c1b3a0f2c6818f881facb2408ff5a46fef51d2cb90de23521b7e83b378af2d4a6727c0046fdf9220011f69a411752588
data/README.md CHANGED
@@ -1,22 +1,30 @@
1
- Fantasy Football Nerd API
2
- ==========================
1
+ Fantasy Football Nerd API Ruby Gem
2
+ ==================================
3
3
 
4
- This is a Ruby Gem for the [Fantasy Football Nerd API](http://www.fantasyfootballnerd.com/api).
4
+ A Ruby Gem for the [Fantasy Football Nerd API](http://www.fantasyfootballnerd.com/api) which:
5
5
 
6
- [Fantasy Football Nerd](http://www.fantasyfootballnerd.com) "takes the 'wisdom of the crowd' to a new level by aggregating the fantasy football rankings of the best fantasy football sites... and weighting the rankings based upon past accuracy."
6
+ > takes the "wisdom of the crowd" to a new level by aggregating the fantasy football rankings of the best fantasy football sites on the planet to analyze the rankings given to each player to produce a consensus ranking.
7
7
 
8
- Fantasy Football Nerd provides an API with access to this fantasy football data:
8
+ This gem currently supports all Level 1 and Level 2 streams which cost $9 per season -- a total no-brainer if you're into fantasy sports and programming. Give the man his money.
9
9
 
10
- * Players List
11
- * Player Details (including recent articles)
12
- * Weekly Projections
13
- * Injury Reports
14
- * Preseason Draft Rankings (not currently supported)
15
- * Season Schedule (not currently supported)
10
+ Here's what you get with $9 and this gem:
16
11
 
12
+ * Current Week
13
+ * Team List
14
+ * Season schedule
15
+ * Player list
16
+ * Bye weeks
17
+ * Injuries
18
+ * Auction draft values
19
+ * Draft rankings - projected fantasy points for the entire season
20
+ * Draft projections - projected stats for each scoring category for the entire season
21
+ * Weekly rankings - projected fantasy points (PPR || Standard)
22
+ * Weekly projections - projected stats for each scoring category
17
23
 
18
- Full API access costs $9 for a season subsciption, though if you are a developer with a modicum of interest in Fantasy Football, this is the best $9 you will spend all season.
24
+ v1.0
25
+ ----------------
19
26
 
27
+ Fantasy Football Nerd recently overhauled to their API which a) drastically improved their service and b) completely deprecated the old API. The previous version of this gem won't work anymore so update your Gemfiles.
20
28
 
21
29
  Cache your data!
22
30
  ----------------
@@ -24,148 +32,280 @@ Take heed to the warning on the [Fantasy Football Nerd API page](http://www.fant
24
32
 
25
33
  >The data does not generally change more than once or twice per day, so it becomes unnecessary to continually make the same calls. Please store the results locally and reference the cached responses... Your account may be suspended or API access revoked if you are found to be making excessive data calls.
26
34
 
27
- Seriously, FFN is not a big operation. Don't abuse their servers.
35
+ Seriously, Fantasy Football Nerd is not a big operation. Don't abuse their servers.
28
36
 
29
37
  Setup
30
38
  =================
31
- Install the gem:
39
+ First, [sign up](http://www.fantasyfootballnerd.com/create-account) for a Fantasy Football Nerd account. Then...
32
40
 
33
- gem install fantasy-football-nerd
41
+ In plain ol' Ruby, install the gem:
34
42
 
35
- In plain ol' ruby, require it:
43
+ ```
44
+ gem install fantasy_football_nerd
45
+ ```
36
46
 
37
- ````ruby
38
- require 'rubygems'
39
- require 'fantasy-football-nerd'
40
- ````
41
-
42
- In rails, add the gem to your gemfile:
47
+ And require it:
43
48
 
44
49
  ````ruby
45
- gem 'fantasy-football-nerd'
50
+ require 'rubygems'
51
+ require 'fantasy_football_nerd'
46
52
  ````
47
53
 
48
- Set your FFN APIKey before making any calls:
54
+ If you're using Rails, add the gem to your Gemfile and run ```bundle install```
49
55
 
50
56
  ````ruby
51
- FFNerd.api_key = 123456789
57
+ gem 'fantasy_football_nerd'
52
58
  ````
53
59
 
54
- API Resources
55
- ===================
56
-
57
- Currently, this gem provides access to four feeds:
60
+ Before you can access the feeds you must set your API key (found on the [Fantasy Football Nerd API dashboard](http://www.fantasyfootballnerd.com/api)) via one of two ways:
58
61
 
59
- * Player List
60
- * Player Detail
61
- * Weekly Projections
62
- * Injuries
63
-
64
- Player List
65
- --------------------------
62
+ Set an environment variable via the terminal.
66
63
 
67
- ````ruby
68
- FFNerd.player_list
64
+ ````term
65
+ export FFNERD_API_KEY = 123456789
69
66
  ````
70
67
 
71
- Returns an array of players with attributes:
72
-
73
- ````ruby
74
- player.player_id
75
- player.name
76
- player.position
77
- player.team
78
- ````
68
+ Set a class variable from your script.
79
69
 
80
- Player Detail
81
- ------------------------------
82
-
83
- ````ruby
84
- player = FFNerd.player_detail(id)
85
- ````
70
+ ```ruby
71
+ FFNerd.api_key = 123456789
72
+ ```
86
73
 
87
- Returns a single player with attributes:
88
- ````ruby
89
- player.id
90
- player.first_name
91
- player.last_name
92
- player.team
93
- player.position
94
- player.articles
95
- ````
74
+ API Resources
75
+ ===================
96
76
 
97
- <tt>player.articles</tt> is an array of articles:
77
+ This gem supports all of Fantasy Football Nerd's Level 1 and Level 2 resources. Results are typically returned as an array of [ostructs](http://www.ruby-doc.org/stdlib-2.0/libdoc/ostruct/rdoc/OpenStruct.html) (which is basically a hash that you can access with "dot notation" as if it were an object instance variable). Fantasy Football Nerd returns keys in CamelCase, but that's not very Ruby like, so I've added snake_case attributes so that you can do ```player.displayName``` or ```player.display_name```, whichever suits your fancy.
98
78
 
99
- ````ruby
100
- article = player.articles.first
101
- article.title
102
- article.source
103
- article.published
104
- ````
79
+ Teams
80
+ --------------------------
81
+ Returns an array of teams.
105
82
 
106
- Projections
107
- ---------------
83
+ ```ruby
84
+ team = FFNerd.teams.first
85
+ team.code # "ARI"
86
+ team.full_name # "Arizona Cardinals"
87
+ team.short_name # "Arizona"
88
+ ```
108
89
 
109
- ````ruby
110
- projections = FFNerd.projections(week)
111
- ````
90
+ Schedule
91
+ --------------------------
92
+ Returns an array of games.
93
+
94
+ ```ruby
95
+ game = FFNerd.schedule.first
96
+ game.game_id # "1"
97
+ game.game_week # "1"
98
+ game.game_date # "2013-09-05"
99
+ game.away_team # "BAL"
100
+ game.home_team # "DEN"
101
+ ```
102
+
103
+ Players
104
+ --------------------------
105
+ Returns an array of players.
106
+
107
+ ```ruby
108
+ player = FFNerd.players.first
109
+ player.player_id # "2"
110
+ player.active # "1"
111
+ player.jersey # "3"
112
+ player.lname # "Anderson"
113
+ player.fname # "Derek"
114
+ player.display_name # "Derek Anderson"
115
+ player.team # "CAR"
116
+ player.position # "QB"
117
+ player.height # "6-6"
118
+ player.weight # "240"
119
+ player.dob # "1983-06-15"
120
+ player.college # "Oregon State"
121
+ ```
122
+
123
+ Bye Weeks
124
+ --------------------------
125
+ Returns an array of the teams on bye for the given week.
112
126
 
113
- Returns an array of players with attributes:
114
- ````ruby
115
- player = projections.first
116
- player.id
117
- player.name
118
- player.team
119
- player.position
120
- player.rank
121
- player.projected_points #equivalent to player.projection.standard
122
- player.projection.week
123
- player.projection.standard
124
- player.projection.standard_low
125
- player.projection.standard_high
126
- player.projection.ppr
127
- player.projection.ppr_low
128
- player.projection.ppr_high
129
- ````
127
+ ```ruby
128
+ bye = FFNerd.byes(4).first
129
+ bye.team # "CAR"
130
+ bye.bye_week # "4"
131
+ bye.display_name # "Carolina Panthers"
132
+ ```
130
133
 
131
134
  Injuries
132
- ---------------------
133
-
134
- ````ruby
135
- injuries = FFNerd.injuries(week)
136
- ````
135
+ --------------------------
136
+ Returns an array of injured players. Takes an optional parameter for the week number, or defaults to the current week.
137
+
138
+ ```ruby
139
+ injury = FFNerd.injuries(6) # all injuries for week 6
140
+ injury = FFNerd.injuries.first # the first injury of the current week
141
+ injury.week # "1"
142
+ injury.player_id # "0"
143
+ injury.player_name # "Javier Arenas"
144
+ injury.team # "ARI"
145
+ injury.position # "CB"
146
+ injury.injury # "Hip"
147
+ injury.practice_status # "Full Practice"
148
+ injury.game_status # "Probable"
149
+ injury.notes # ""
150
+ injury.last_update # "2013-09-09"
151
+ injury.practice_status_id # 0
152
+ ```
153
+
154
+
155
+ Auction Values
156
+ --------------------------
157
+ Returns an array of draft auction values.
158
+
159
+ ```ruby
160
+ value = FFNerd.auction_values.first
161
+ value.player_id # "259"
162
+ value.min_price # "60"
163
+ value.max_price # "66"
164
+ value.avg_price # "63"
165
+ value.display_name # "Adrian Peterson"
166
+ value.team # "MIN"
167
+ value.position # "RB"
168
+ ```
169
+
170
+ Current Week
171
+ --------------------------
172
+ Returns the current NFL week as an integer.
137
173
 
138
- Returns an array of players with attributes:
174
+ ```ruby
175
+ FFNerd.current_week # 17
176
+ ```
139
177
 
140
- ````ruby
141
- player = injuries.first
142
- player.id
143
- player.name
144
- player.team
145
- player.position
146
- player.injury.week
147
- player.injury.injury_desc
148
- player.injury.practice_status_desc
149
- player.injury.game_status_desc
150
- player.injury.last_update
151
- ````
178
+ Standard Draft Rankings
179
+ --------------------------
180
+ Returns an array of players according to their projected draft values based on standard scoring. In this example I'm looking at the fourth element in the array because the PPR and standard rankings don't deviate until then in the test data.
181
+
182
+ ```ruby
183
+ player = FFNerd.standard_draft_rankings[3]
184
+ player.playerId # "1136"
185
+ player.position # "RB"
186
+ player.displayName # "C.J. Spiller"
187
+ player.fname # "C.J."
188
+ player.lname # "Spiller"
189
+ player.team # "BUF"
190
+ player.byeWeek # "12"
191
+ player.nerdRank # "6.140"
192
+ player.positionRank # "4"
193
+ player.overallRank # "4"
194
+ ```
195
+
196
+ PPR Draft Rankings
197
+ --------------------------
198
+ Returns an array of players according to their projected draft values based on PPR scoring.
199
+
200
+ ```ruby
201
+ player = FFNerd.ppr_draft_rankings[3]
202
+ player.player_id # "454"
203
+ player.position # "WR"
204
+ player.display_name # "Calvin Johnson"
205
+ player.fname # "Calvin"
206
+ player.lname # "Johnson"
207
+ player.team # "DET"
208
+ player.bye_week # "9"
209
+ player.nerd_rank # "7.209"
210
+ player.position_rank # "1"
211
+ player.overall_rank # "4"
212
+ ```
213
+
214
+ Draft Projections
215
+ --------------------------
216
+ Returns an array of players with projected stats for a number of scoring categories. This data is useless once the season starts.
217
+
218
+ Must pass in a valid position of QB, RB, WR, TE, K, DEF.
219
+
220
+ ```ruby
221
+ player = FFNerd.draft_projections('QB').first
222
+ player.player_id # "14"
223
+ player.completions # "422"
224
+ player.attempts # "640"
225
+ player.passing_yards # "4992"
226
+ player.passing_td # "40"
227
+ player.passing_int # "17"
228
+ player.rush_yards # "28"
229
+ player.rush_td # "1"
230
+ player.fantasy_points # "335"
231
+ player.display_name # "Drew Brees"
232
+ player.team # "NO"
233
+ ```
234
+
235
+ Weekly Rankings
236
+ --------------------------
237
+ Returns an array of players with expected weekly fantasy points for both standard and PPR scoring.
238
+
239
+ Must requests a specific position: QB, RB, WR, TE, K, DEF. You can also send along the specific week number (1-17). If you omit a week, it defaults to the current week.
240
+
241
+ ```ruby
242
+ player = FFNerd.weekly_rankings('QB', 2).first
243
+ player.week # "2"
244
+ player.player_id # "14"
245
+ player.name # "Drew Brees"
246
+ player.position # "QB"
247
+ player.team # "NO"
248
+ player.standard # "24.80"
249
+ player.standard_low # "18.92"
250
+ player.standard_high # "32.00"
251
+ player.ppr # "24.80"
252
+ player.ppr_low # "18.92"
253
+ player.ppr_high # "32.00"
254
+ player.injury # nil
255
+ player.practice_status # nil
256
+ player.game_status # nil
257
+ player.last_update # nil
258
+ ```
259
+
260
+ Weekly Projections
261
+ --------------------------
262
+ Returns an array of players with expected weekly values for each scoring category.
263
+
264
+ Must requests a specific position: QB, RB, WR, TE, K (But *NOT DEF!*). You can also send along the specific week number (1-17). If you omit a week, it defaults to the current week.
265
+
266
+ ```ruby
267
+ player = FFNerd.weekly_projections('QB', 1).first
268
+ player.week # "1"
269
+ player.player_id # "14"
270
+ player.position # "QB"
271
+ player.pass_att # "39.0"
272
+ player.pass_cmp # "25.0"
273
+ player.pass_yds # "317.0"
274
+ player.pass_td # "2.0"
275
+ player.pass_int # "1.0"
276
+ player.rush_att # "1.0"
277
+ player.rush_yds # "1.0"
278
+ player.rush_td # "0.0"
279
+ player.fumbles_lost # "0.0"
280
+ player.receptions # "0.0"
281
+ player.rec_yds # "0.0"
282
+ player.rec_td # "0.0"
283
+ player.fg # "0.0"
284
+ player.fg_att # "0.0"
285
+ player.xp # "0.0"
286
+ player.def_int # "0.0"
287
+ player.def_fr # "0.0"
288
+ player.def_ff # "0.0"
289
+ player.def_sack # "0.0"
290
+ player.def_td # "0.0"
291
+ player.def_ret_td # "0.0"
292
+ player.def_safety # "0.0"
293
+ player.def_pa # "0.0"
294
+ player.def_yds_allowed # "0.0"
295
+ player.display_name # "Drew Brees"
296
+ player.team # "NO"
297
+ ```
152
298
 
153
- Still To Come
154
- ------------------
155
- I'll be adding this in the near future:
299
+ Tests
300
+ ===================
156
301
 
157
- * Better error reporting
158
- * Schedule
159
- * Draft Rankings
302
+ Set your API key to "test" to access FFNerd's test feeds. This is useful if you're developing your app prior to the beginning of the season or if you'd like to have a static dataset that won't change as the season progresses. All of the Rspec tests here use the test feeds. Speaking of rspec...
160
303
 
161
- Tests
162
- ------------------
163
- The gem includes extensive RSpec tests.
304
+ This gem includes RSpec tests and uses VCR to cache http responses. If you're going to contribute, please write some tests.
164
305
 
165
306
  Contributors
166
307
  -----------------
167
- This gem was created by:
168
-
169
- Greg Baugues ([greg@baugues.com](mailto:greg@baugues.com))
308
+ Greg Baugues ([greg@baugues.com](mailto:greg@baugues.com))<br/>
309
+ [www.baugues.com](http://www.baugues.com)
170
310
 
171
311
 
@@ -1,237 +1,92 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
- require 'hashie'
1
+ require 'json'
2
+ require 'ostruct'
3
+ require 'fantasy_football_nerd/request.rb'
4
+ require 'fantasy_football_nerd/util.rb'
4
5
 
5
- class FFNerd
6
+ POSITIONS = %w{QB RB WR TE K DEF}
6
7
 
7
- BASE_URL = "http://api.fantasyfootballnerd.com"
8
+ class FFNerd
9
+ @@api_key = nil
8
10
 
9
- #############################################################################
10
- # URL Generators
11
- # These methods generate the URLs that will be used for the API calls
12
- # feed_url() does most of the heavy lifting
13
- # the others are to make things easier on the developer
14
- #############################################################################
11
+ extend Request
15
12
 
16
13
  def self.api_key
14
+ @@api_key ||= ENV['FFNERD_API_KEY']
15
+ raise 'API key not set' if @@api_key.nil?
17
16
  @@api_key
18
17
  end
19
18
 
20
- def self.api_key=(api_key)
21
- @@api_key = api_key
22
- end
23
-
24
- def self.feed_url(feed, params = {} )
25
- raise "api_key not set" if @@api_key.nil?
26
- middle =
27
- case feed
28
- when :schedule then 'ffnScheduleXML.php'
29
- when :projections then 'ffnSitStartXML.php'
30
- when :injuries then 'ffnInjuriesXML.php'
31
- when :all_players then 'ffnPlayersXML.php'
32
- when :player then 'ffnPlayerDetailsXML.php'
33
- end
34
- url = "#{BASE_URL}/#{middle}?apiKey=#{@@api_key}"
35
- params.each { |key, value| url += "&#{key}=#{value}" }
36
- url
19
+ def self.api_key=(key)
20
+ @@api_key = key
37
21
  end
38
22
 
39
- def self.player_url(player_id)
40
- feed_url(:player, 'playerId' => 13)
23
+ def self.current_week
24
+ player = request_service('schedule', api_key)
25
+ player['currentWeek']
41
26
  end
42
27
 
43
- def self.projections_url(position, week)
44
- position = position.to_s.upcase
45
- feed_url(:projections, 'week' => week, 'position' => position)
28
+ def self.ostruct_request(service_name, json_key, extras = [])
29
+ data = request_service(service_name, api_key, extras)[json_key]
30
+ data = data.values.flatten if data.is_a? Hash
31
+ data.collect { |i| OpenStruct.new(i.add_snakecase_keys) }
46
32
  end
47
33
 
48
- def self.injuries_url(week)
49
- feed_url(:injuries, 'week' => week)
34
+ def self.teams
35
+ ostruct_request('nfl-teams', 'NFLTeams')
50
36
  end
51
37
 
52
- def self.player_list_url
53
- feed_url(:all_players)
54
- end
55
-
56
-
57
- #############################################################################
58
- # Resource retreiver
59
- # Connect to the API resource using the Url builders and Nokogiri
60
- #############################################################################
61
-
62
- def self.get_resource(url)
63
- Nokogiri::HTML(open(url))
38
+ def self.schedule
39
+ ostruct_request('schedule', 'Schedule')
64
40
  end
65
41
 
66
- #############################################################################
67
- # Player List
68
- # Grabs a list of all players
69
- #############################################################################
70
-
71
-
72
- def self.player_list
73
- players = []
74
- url = player_list_url
75
- doc = get_resource(url)
76
- doc.css('player').each do |data|
77
- player = Hashie::Mash.new
78
- player.id = data.attr('playerid').to_i
79
- player.name = data.attr('name')
80
- player.position = data.attr('position')
81
- player.team = data.attr('team')
82
- players << player
83
- end
84
- players
42
+ def self.players
43
+ ostruct_request('players', 'Players')
85
44
  end
86
45
 
87
- #############################################################################
88
- # Player Detail
89
- # grabs player detail and related news articles
90
- #############################################################################
91
-
92
-
93
- def self.player_detail(player_id)
94
- player = Hashie::Mash.new
95
- url = player_url(player_id)
96
- doc = get_resource(url)
97
- player.first_name = doc.css('playerdetails firstname').text
98
- player.last_name = doc.css('playerdetails lastname').text
99
- player.team = doc.css('playerdetails team').text
100
- player.position = doc.css('playerdetails position').text
101
- player.articles = []
102
- parse_articles(doc).each { |article| player.articles << article }
103
- player
46
+ def self.byes(week)
47
+ raise "Must include a bye week between 4 and 12" unless (4..12).include?(week)
48
+ ostruct_request('byes', "Bye Week #{week}")
104
49
  end
105
50
 
106
- #used by self.player to get articles
107
- def self.parse_articles(doc)
108
- articles = []
109
- doc.css('article').each do |data|
110
- article = Hashie::Mash.new
111
- article.title = data.css('title').text
112
- article.source = data.css('source').text
113
- article.published = Date.parse(data.css('published').text)
114
- articles << article
115
- end
116
- articles
51
+ def self.injuries(week = nil)
52
+ extras = [week]
53
+ ostruct_request('injuries', 'Injuries', extras)
117
54
  end
118
55
 
119
- #############################################################################
120
- # Projections
121
- # retrieves weekly projections
122
- #############################################################################
123
-
124
- def self.projections(week, position = :all)
125
- projections = []
126
- position = position.to_s.upcase
127
- url = projections_url(position, week)
128
- doc = get_resource(url)
129
- doc.css('player').each do |data|
130
- player = Hashie::Mash.new
131
- player.name = data.attr('name')
132
- player.projected_points = data.attr('projectedpoints').to_f
133
- player.team = data.attr('team')
134
- player.position = data.attr('position')
135
- player.id = data.attr('playerid').to_i
136
- player.rank = data.attr('rank').to_i
137
-
138
- #create and population player.projection
139
- player.projection = Hashie::Mash.new
140
- player.projection.week = data.attr('week').to_i
141
- projections_map.each do |attribute, xml|
142
- player.projection[attribute] = data.css("projections #{xml}").text.to_f
143
- end
144
-
145
- projections << player
146
- end
147
- projections
56
+ def self.auction_values
57
+ ostruct_request('auction', 'AuctionValues')
148
58
  end
149
59
 
150
- def self.projections_map
151
- {
152
- standard: 'standard',
153
- standard_low: 'standardlow',
154
- standard_high: 'standardhigh',
155
- ppr: 'ppr',
156
- ppr_low: 'pprlow',
157
- ppr_high: 'pprhigh'
158
- }
60
+ def self.standard_draft_rankings
61
+ ostruct_request('draft-rankings', 'DraftRankings')
159
62
  end
160
63
 
161
- #############################################################################
162
- # Injuries
163
- # retrieves weekly injuries
164
- #############################################################################
165
-
166
-
167
- def self.injuries(week)
168
- players = []
169
- url = injuries_url(week)
170
- doc = get_resource(url)
171
- #puts doc.css('injury')
172
- doc.css('injury').each do |data|
173
- player = Hashie::Mash.new
174
-
175
- injury_player_data_map.each do |attribute, xml|
176
- player[attribute] = data.css(xml).text
177
- end
178
-
179
- player.injury = Hashie::Mash.new
180
- injury_data_map.each do |attribute, xml|
181
- player.injury[attribute] = data.css(xml).text
182
- end
183
-
184
- #convert to more appropriate data types
185
- player.id = player.id.to_i
186
- player.injury.week = player.injury.week.to_i
187
- player.injury.last_update = Date.parse(player.injury.last_update)
188
-
189
- players << player
190
- end
191
- players
64
+ def self.ppr_draft_rankings
65
+ #appended a 1 to url for ppr rankings
66
+ ostruct_request('draft-rankings', 'DraftRankings', '1')
192
67
  end
193
68
 
194
-
195
- def self.injury_data_map
196
- {
197
- week: 'week',
198
- injury_desc: 'injurydesc',
199
- practice_status_desc: 'practicestatusdesc',
200
- game_status_desc: 'gamestatusdesc',
201
- last_update: 'lastupdate'
202
- }
69
+ def self.draft_projections(position)
70
+ raise "Must pass in a valid position" unless POSITIONS.include?(position)
71
+ ostruct_request('draft-projections', 'DraftProjections', [position])
203
72
  end
204
73
 
205
- def self.injury_player_data_map
206
- {
207
- id: 'playerid',
208
- name: 'playername',
209
- team: 'team',
210
- position: 'position'
211
- }
74
+ def self.weekly_rankings(position, week = nil)
75
+ raise "Must pass in a valid position" unless POSITIONS.include?(position)
76
+ raise "Your (optional) week must be between 1 and 17" if week && !(1..17).include?(week)
77
+ week ||= current_week
78
+ extras = [position, week, 1]
79
+ ostruct_request('weekly-rankings', 'Rankings', extras)
212
80
  end
213
81
 
214
- #############################################################################
215
- # players
216
- # The one method to rule them all
217
- #############################################################################
218
-
219
- def self.players(week, position = :all)
220
- players = {}
221
-
222
- FFNerd.projections(week).each do |player|
223
- player.injured = false
224
- players[player.id] = player
225
- end
226
-
227
- FFNerd.injuries(week).each do |player|
228
- raise if players[player.id].nil?
229
- players[player.id].injured = true
230
- players[player.id].injury = player.injury
231
- end
232
-
233
- players.values
82
+ def self.weekly_projections(position, week = nil)
83
+ #FFNerd defaults to current week if week is left blank
84
+ raise "Weekly projections don't include DEF (but you can find those values in weekly rankings)" if position == "DEF"
85
+ raise "Must pass in a valid position" unless POSITIONS.include?(position)
86
+ raise "Your (optional) week must be between 1 and 17" if week && !(1..17).include?(week)
87
+ week ||= current_week
88
+ extras = [position, week]
89
+ ostruct_request('weekly-projections', 'Projections', extras)
234
90
  end
235
91
 
236
-
237
- end
92
+ end