fantasydata 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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +3 -0
  3. data/README.md +15 -1
  4. data/lib/fantasydata.rb +4 -0
  5. data/lib/fantasydata/api/injury.rb +18 -0
  6. data/lib/fantasydata/api/player_stat.rb +24 -0
  7. data/lib/fantasydata/api/season.rb +22 -0
  8. data/lib/fantasydata/api/team.rb +8 -0
  9. data/lib/fantasydata/api/timeline.rb +31 -0
  10. data/lib/fantasydata/api/week.rb +4 -4
  11. data/lib/fantasydata/client.rb +8 -2
  12. data/lib/fantasydata/injury.rb +13 -0
  13. data/lib/fantasydata/team_game_stat.rb +103 -0
  14. data/lib/fantasydata/team_season_stat.rb +84 -0
  15. data/lib/fantasydata/timeline.rb +12 -0
  16. data/lib/fantasydata/version.rb +1 -1
  17. data/spec/fantasydata/api/injury_spec.rb +54 -0
  18. data/spec/fantasydata/api/player_stat_spec.rb +121 -0
  19. data/spec/fantasydata/api/season_spec.rb +69 -0
  20. data/spec/fantasydata/api/team_spec.rb +43 -2
  21. data/spec/fantasydata/api/timeline_spec.rb +96 -0
  22. data/spec/fantasydata/api/week_spec.rb +13 -13
  23. data/spec/fixtures/injury/by_team.json +1 -0
  24. data/spec/fixtures/injury/by_year_and_week.json +1 -0
  25. data/spec/fixtures/player_stat/season_stat_by_player_id.json +1 -0
  26. data/spec/fixtures/player_stat/season_stat_by_player_id_projection.json +1 -0
  27. data/spec/fixtures/player_stat/season_stat_by_season_projection.json +1 -0
  28. data/spec/fixtures/player_stat/season_stat_by_team.json +1 -0
  29. data/spec/fixtures/player_stat/season_stat_by_team_projection.json +1 -0
  30. data/spec/fixtures/season/current.json +1 -0
  31. data/spec/fixtures/season/last_completed.json +1 -0
  32. data/spec/fixtures/season/upcoming.json +1 -0
  33. data/spec/fixtures/team/season_stats.json +1 -0
  34. data/spec/fixtures/team/week_stats.json +1 -0
  35. data/spec/fixtures/timeline/all.json +1 -0
  36. data/spec/fixtures/timeline/completed.json +1 -0
  37. data/spec/fixtures/timeline/current.json +1 -0
  38. data/spec/fixtures/timeline/recent.json +1 -0
  39. data/spec/fixtures/timeline/upcoming.json +1 -0
  40. metadata +60 -19
@@ -0,0 +1,12 @@
1
+ require 'fantasydata/base'
2
+
3
+ module Fantasydata
4
+ class Timeline < Fantasydata::Base
5
+ attr_reader :season_type, :season, :week, :name, :short_name,
6
+ :start_date, :end_date, :first_game_start,
7
+ :first_game_end, :last_game_end, :has_games,
8
+ :has_started, :has_ended, :has_first_game_started,
9
+ :has_first_game_ended, :has_last_game_ended
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Fantasydata
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ describe Fantasydata::API::Injury do
4
+
5
+ before do
6
+ @client = new_test_client
7
+ end
8
+
9
+ describe '#injuries_by_year_and_week' do
10
+ before do
11
+ stub_get("/nfl/v2/JSON/Injuries/2014/5").
12
+ to_return(:body => fixture("injury/by_year_and_week.json"),
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "requests correct resource" do
17
+ @client.injuries_by_year_and_week(2014, 5)
18
+ expect(a_get("/nfl/v2/JSON/Injuries/2014/5")).to have_been_made
19
+ end
20
+
21
+ it "returns injuries" do
22
+ injuries = @client.injuries_by_year_and_week(2014, 5)
23
+
24
+ expect(injuries).to be_an Array
25
+ expect(injuries.first).to be_an Fantasydata::Injury
26
+ expect(injuries.first.injury_id).to eq 31066
27
+ expect(injuries.first.player_id).to eq 13406
28
+ end
29
+ end
30
+
31
+ describe '#injuries_by_year_week_team' do
32
+ before do
33
+ stub_get("/nfl/v2/JSON/Injuries/2014/5/MIN").
34
+ to_return(:body => fixture("injury/by_team.json"),
35
+ :headers => {:content_type => "application/json; charset=utf-8"})
36
+ end
37
+
38
+ it "requests correct resource" do
39
+ @client.injuries_by_year_week_team(2014, 5, 'MIN')
40
+ expect(a_get("/nfl/v2/JSON/Injuries/2014/5/MIN")).to have_been_made
41
+ end
42
+
43
+ it "returns injuries" do
44
+ injuries = @client.injuries_by_year_week_team(2014, 5, 'MIN')
45
+
46
+ expect(injuries).to be_an Array
47
+ expect(injuries.first).to be_an Fantasydata::Injury
48
+ expect(injuries.first.injury_id).to eq 31739
49
+ expect(injuries.first.player_id).to eq 14461
50
+ end
51
+ end
52
+
53
+
54
+ end
@@ -6,6 +6,13 @@ describe Fantasydata::API::PlayerStat do
6
6
  @client = new_test_client
7
7
  end
8
8
 
9
+ ######################
10
+ #
11
+ # PLAYER GAME STATS
12
+ #
13
+ ######################
14
+
15
+
9
16
  describe '#player_game_stat_by_player' do
10
17
  before do
11
18
  stub_get("/nfl/v2/JSON/PlayerGameStatsByPlayerID/2014/12/7328").
@@ -135,4 +142,118 @@ describe Fantasydata::API::PlayerStat do
135
142
  end
136
143
  end
137
144
 
145
+ ######################
146
+ #
147
+ # PLAYER SEASON STATS
148
+ #
149
+ ######################
150
+
151
+ describe '#player_season_stats_by_year_projection' do
152
+ before do
153
+ stub_get("/nfl/v2/JSON/PlayerSeasonProjectionStats/2014").
154
+ to_return(:body => fixture("player_stat/season_stat_by_season_projection.json"),
155
+ :headers => {:content_type => "application/json; charset=utf-8"})
156
+ end
157
+
158
+ it "requests correct resource" do
159
+ @client.player_season_stats_by_year_projection(2014)
160
+ expect(a_get("/nfl/v2/JSON/PlayerSeasonProjectionStats/2014")).to have_been_made
161
+ end
162
+
163
+ it "returns player details" do
164
+ stats = @client.player_season_stats_by_year_projection(2014)
165
+
166
+ expect(stats).to be_an Array
167
+ expect(stats.first).to be_an Fantasydata::PlayerSeasonStat
168
+ expect(stats.first.player_id).to eq 2428
169
+ expect(stats.first.player_season_id).to eq 0
170
+ end
171
+ end
172
+
173
+ describe '#player_season_stat_by_player_id' do
174
+ before do
175
+ stub_get("/nfl/v2/JSON/PlayerSeasonStatsByPlayerID/2014/2428").
176
+ to_return(:body => fixture("player_stat/season_stat_by_player_id.json"),
177
+ :headers => {:content_type => "application/json; charset=utf-8"})
178
+ end
179
+
180
+ it "requests correct resource" do
181
+ @client.player_season_stat_by_player_id(2014, 2428)
182
+ expect(a_get("/nfl/v2/JSON/PlayerSeasonStatsByPlayerID/2014/2428")).to have_been_made
183
+ end
184
+
185
+ it "returns player details" do
186
+ stats = @client.player_season_stat_by_player_id(2014, 2428)
187
+
188
+ expect(stats).to be_an Fantasydata::PlayerSeasonStat
189
+ expect(stats.player_id).to eq 2428
190
+ expect(stats.player_season_id).to eq 14247797
191
+ end
192
+ end
193
+
194
+ describe '#player_season_stat_by_player_id_projection' do
195
+ before do
196
+ stub_get("/nfl/v2/JSON/PlayerSeasonProjectionStatsByPlayerID/2014/2429").
197
+ to_return(:body => fixture("player_stat/season_stat_by_player_id_projection.json"),
198
+ :headers => {:content_type => "application/json; charset=utf-8"})
199
+ end
200
+
201
+ it "requests correct resource" do
202
+ @client.player_season_stat_by_player_id_projection(2014, 2429)
203
+ expect(a_get("/nfl/v2/JSON/PlayerSeasonProjectionStatsByPlayerID/2014/2429")).to have_been_made
204
+ end
205
+
206
+ it "returns player details" do
207
+ stats = @client.player_season_stat_by_player_id_projection(2014, 2429)
208
+
209
+ expect(stats).to be_an Fantasydata::PlayerSeasonStat
210
+ expect(stats.player_id).to eq 2429
211
+ expect(stats.player_season_id).to eq 0
212
+ end
213
+ end
214
+
215
+ describe '#player_season_stat_by_team' do
216
+ before do
217
+ stub_get("/nfl/v2/JSON/PlayerSeasonStatsByTeam/2014/MIN").
218
+ to_return(:body => fixture("player_stat/season_stat_by_team.json"),
219
+ :headers => {:content_type => "application/json; charset=utf-8"})
220
+ end
221
+
222
+ it "requests correct resource" do
223
+ @client.player_season_stat_by_team(2014, 'MIN')
224
+ expect(a_get("/nfl/v2/JSON/PlayerSeasonStatsByTeam/2014/MIN")).to have_been_made
225
+ end
226
+
227
+ it "returns player details" do
228
+ stats = @client.player_season_stat_by_team(2014, 'MIN')
229
+
230
+ expect(stats).to be_an Array
231
+ expect(stats.first).to be_an Fantasydata::PlayerSeasonStat
232
+ expect(stats.first.player_id).to eq 14463
233
+ expect(stats.first.player_season_id).to eq 14248877
234
+ end
235
+ end
236
+
237
+ describe '#player_season_stat_by_team_projection' do
238
+ before do
239
+ stub_get("/nfl/v2/JSON/PlayerSeasonProjectionStatsByTeam/2014/MIN").
240
+ to_return(:body => fixture("player_stat/season_stat_by_team_projection.json"),
241
+ :headers => {:content_type => "application/json; charset=utf-8"})
242
+ end
243
+
244
+ it "requests correct resource" do
245
+ @client.player_season_stat_by_team_projection(2014, 'MIN')
246
+ expect(a_get("/nfl/v2/JSON/PlayerSeasonProjectionStatsByTeam/2014/MIN")).to have_been_made
247
+ end
248
+
249
+ it "returns player details" do
250
+ stats = @client.player_season_stat_by_team_projection(2014, 'MIN')
251
+
252
+ expect(stats).to be_an Array
253
+ expect(stats.first).to be_an Fantasydata::PlayerSeasonStat
254
+ expect(stats.first.player_id).to eq 4807
255
+ expect(stats.first.player_season_id).to eq 0
256
+ end
257
+ end
258
+
138
259
  end
@@ -0,0 +1,69 @@
1
+ require 'helper'
2
+
3
+ describe Fantasydata::API::Season do
4
+
5
+ before do
6
+ @client = new_test_client
7
+ end
8
+
9
+ describe '#season_current' do
10
+ before do
11
+ stub_get("/nfl/v2/JSON/CurrentSeason").
12
+ to_return(:body => fixture("season/current.json"),
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "requests correct resource" do
17
+ @client.current_season
18
+ expect(a_get("/nfl/v2/JSON/CurrentSeason")).to have_been_made
19
+ end
20
+
21
+ it "returns current season" do
22
+ current_season = @client.current_season
23
+
24
+ expect(current_season).to be_an Integer
25
+ expect(current_season).to eq 2015
26
+ end
27
+ end
28
+
29
+ describe '#season_last_completed' do
30
+ before do
31
+ stub_get("/nfl/v2/JSON/LastCompletedSeason").
32
+ to_return(:body => fixture("season/last_completed.json"),
33
+ :headers => {:content_type => "application/json; charset=utf-8"})
34
+ end
35
+
36
+ it "requests correct resource" do
37
+ @client.last_completed_season
38
+ expect(a_get("/nfl/v2/JSON/LastCompletedSeason")).to have_been_made
39
+ end
40
+
41
+ it "returns last completed season" do
42
+ season = @client.last_completed_season
43
+
44
+ expect(season).to be_an Integer
45
+ expect(season).to eq 2014
46
+ end
47
+ end
48
+
49
+ describe '#season_upcoming' do
50
+ before do
51
+ stub_get("/nfl/v2/JSON/UpcomingSeason").
52
+ to_return(:body => fixture("season/upcoming.json"),
53
+ :headers => {:content_type => "application/json; charset=utf-8"})
54
+ end
55
+
56
+ it "requests correct resource" do
57
+ @client.upcoming_season
58
+ expect(a_get("/nfl/v2/JSON/UpcomingSeason")).to have_been_made
59
+ end
60
+
61
+ it "returns upcoming season" do
62
+ season = @client.upcoming_season
63
+
64
+ expect(season).to be_an Integer
65
+ expect(season).to eq 2015
66
+ end
67
+ end
68
+
69
+ end
@@ -49,8 +49,49 @@ describe Fantasydata::API::Team do
49
49
  end
50
50
  end
51
51
 
52
-
52
+ describe '#teams_stats_by_year_and_week' do
53
+ before do
54
+ stub_get("/nfl/v2/JSON/TeamGameStats/2014/1").
55
+ to_return(:body => fixture("team/week_stats.json"),
56
+ :headers => {:content_type => "application/json; charset=utf-8"})
57
+ end
53
58
 
54
- end
59
+ it "requests correct resource" do
60
+ @client.team_game_stats_by_year_and_week(2014, 1)
61
+ expect(a_get("/nfl/v2/JSON/TeamGameStats/2014/1")).to have_been_made
62
+ end
55
63
 
64
+ it "returns active teams" do
65
+ teams = @client.team_game_stats_by_year_and_week(2014, 1)
56
66
 
67
+ expect(teams).to be_an Array
68
+ expect(teams.first).to be_an Fantasydata::TeamGameStat
69
+ expect(teams.first.day_of_week).to eq 'Monday'
70
+ expect(teams.first.punt_net_yards).to eq 129
71
+ expect(teams.first.game_key).to eq '201410101'
72
+ end
73
+ end
74
+
75
+ describe '#teams_stats_by_season' do
76
+ before do
77
+ stub_get("/nfl/v2/JSON/TeamSeasonStats/2012").
78
+ to_return(:body => fixture("team/season_stats.json"),
79
+ :headers => {:content_type => "application/json; charset=utf-8"})
80
+ end
81
+
82
+ it "requests correct resource" do
83
+ @client.team_game_stats_by_season(2012)
84
+ expect(a_get("/nfl/v2/JSON/TeamSeasonStats/2012")).to have_been_made
85
+ end
86
+
87
+ it "returns active teams" do
88
+ teams = @client.team_game_stats_by_season(2012)
89
+
90
+ expect(teams).to be_an Array
91
+ expect(teams.first).to be_an Fantasydata::TeamSeasonStat
92
+ expect(teams.first.penalties).to eq 102
93
+ expect(teams.first.punt_net_yards).to eq 4634
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,96 @@
1
+ require 'helper'
2
+
3
+ describe Fantasydata::API::Timeline do
4
+
5
+ before do
6
+ @client = new_test_client
7
+ end
8
+
9
+ describe '#current_timelines' do
10
+ before do
11
+ stub_get("/nfl/v2/JSON/Timeframes/current").
12
+ to_return(:body => fixture("timeline/current.json"),
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "requests correct resource" do
17
+ @client.current_timeline
18
+ expect(a_get("/nfl/v2/JSON/Timeframes/current")).to have_been_made
19
+ end
20
+
21
+ it "returns data" do
22
+ timeline = @client.current_timeline
23
+
24
+ expect(timeline).to be_an Fantasydata::Timeline
25
+ expect(timeline.short_name).to eq 'NFL Draft'
26
+ expect(timeline.has_games).to eq false
27
+ end
28
+ end
29
+
30
+ describe '#upcoming_timelines' do
31
+ before do
32
+ stub_get("/nfl/v2/JSON/Timeframes/upcoming").
33
+ to_return(:body => fixture("timeline/upcoming.json"),
34
+ :headers => {:content_type => "application/json; charset=utf-8"})
35
+ end
36
+
37
+ it "requests correct resource" do
38
+ @client.upcoming_timelines
39
+ expect(a_get("/nfl/v2/JSON/Timeframes/upcoming")).to have_been_made
40
+ end
41
+
42
+ it "returns data" do
43
+ timelines = @client.upcoming_timelines
44
+
45
+ expect(timelines).to be_an Array
46
+ expect(timelines.first).to be_an Fantasydata::Timeline
47
+ expect(timelines.first.short_name).to eq 'NFL Draft'
48
+ expect(timelines.first.has_games).to eq false
49
+ end
50
+ end
51
+
52
+ describe '#completed_timelines' do
53
+ before do
54
+ stub_get("/nfl/v2/JSON/Timeframes/completed").
55
+ to_return(:body => fixture("timeline/completed.json"),
56
+ :headers => {:content_type => "application/json; charset=utf-8"})
57
+ end
58
+
59
+ it "requests correct resource" do
60
+ @client.completed_timelines
61
+ expect(a_get("/nfl/v2/JSON/Timeframes/completed")).to have_been_made
62
+ end
63
+
64
+ it "returns data" do
65
+ timelines = @client.completed_timelines
66
+
67
+ expect(timelines).to be_an Array
68
+ expect(timelines.first).to be_an Fantasydata::Timeline
69
+ expect(timelines.first.short_name).to eq 'Free Agency'
70
+ expect(timelines.first.has_games).to eq false
71
+ end
72
+ end
73
+
74
+ describe '#all_timelines' do
75
+ before do
76
+ stub_get("/nfl/v2/JSON/Timeframes/all").
77
+ to_return(:body => fixture("timeline/all.json"),
78
+ :headers => {:content_type => "application/json; charset=utf-8"})
79
+ end
80
+
81
+ it "requests correct resource" do
82
+ @client.all_timelines
83
+ expect(a_get("/nfl/v2/JSON/Timeframes/all")).to have_been_made
84
+ end
85
+
86
+ it "returns data" do
87
+ timelines = @client.all_timelines
88
+
89
+ expect(timelines).to be_an Array
90
+ expect(timelines.first).to be_an Fantasydata::Timeline
91
+ expect(timelines.first.short_name).to eq 'Offseason'
92
+ expect(timelines.first.has_games).to eq false
93
+ end
94
+ end
95
+
96
+ end
@@ -14,12 +14,12 @@ describe Fantasydata::API::Week do
14
14
  end
15
15
 
16
16
  it "requests correct resource" do
17
- @client.week_current
17
+ @client.current_week
18
18
  expect(a_get("/nfl/v2/JSON/CurrentWeek")).to have_been_made
19
19
  end
20
20
 
21
- it "returns player details" do
22
- current_week = @client.week_current
21
+ it "returns current week" do
22
+ current_week = @client.current_week
23
23
 
24
24
  expect(current_week).to be_an Integer
25
25
  expect(current_week).to eq 16
@@ -34,32 +34,32 @@ describe Fantasydata::API::Week do
34
34
  end
35
35
 
36
36
  it "requests correct resource" do
37
- @client.week_last_completed
37
+ @client.last_completed_week
38
38
  expect(a_get("/nfl/v2/JSON/LastCompletedWeek")).to have_been_made
39
39
  end
40
40
 
41
- it "returns player details" do
42
- current_week = @client.week_last_completed
41
+ it "returns last completed week" do
42
+ week = @client.last_completed_week
43
43
 
44
- expect(current_week).to be_an Integer
45
- expect(current_week).to eq 4
44
+ expect(week).to be_an Integer
45
+ expect(week).to eq 4
46
46
  end
47
47
  end
48
48
 
49
49
  describe '#week_upcoming' do
50
50
  before do
51
- stub_get("/nfl/v2/XML/UpcomingWeek").
51
+ stub_get("/nfl/v2/JSON/UpcomingWeek").
52
52
  to_return(:body => fixture("week/upcoming.json"),
53
53
  :headers => {:content_type => "application/json; charset=utf-8"})
54
54
  end
55
55
 
56
56
  it "requests correct resource" do
57
- @client.week_upcoming
58
- expect(a_get("/nfl/v2/XML/UpcomingWeek")).to have_been_made
57
+ @client.upcoming_week
58
+ expect(a_get("/nfl/v2/JSON/UpcomingWeek")).to have_been_made
59
59
  end
60
60
 
61
- it "returns player details" do
62
- current_week = @client.week_upcoming
61
+ it "returns upcoming week" do
62
+ current_week = @client.upcoming_week
63
63
 
64
64
  expect(current_week).to be_an Integer
65
65
  expect(current_week).to eq 9