nfl_data 0.0.11 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.envrc +7 -0
  3. data/.gitignore +3 -3
  4. data/.rspec +1 -0
  5. data/.standard.yml +2 -0
  6. data/.travis.yml +6 -0
  7. data/CHANGELOG.md +11 -0
  8. data/Gemfile +1 -1
  9. data/README.md +94 -22
  10. data/Rakefile +5 -6
  11. data/bin/console +1 -1
  12. data/bin/setup +8 -0
  13. data/lib/nfl_data.rb +9 -18
  14. data/lib/nfl_data/api/player.rb +8 -26
  15. data/lib/nfl_data/api/schedule.rb +19 -0
  16. data/lib/nfl_data/api/statline.rb +8 -22
  17. data/lib/nfl_data/game.rb +5 -0
  18. data/lib/nfl_data/my_sports_feeds/client.rb +45 -0
  19. data/lib/nfl_data/my_sports_feeds/players_feed.rb +18 -0
  20. data/lib/nfl_data/my_sports_feeds/seasonal_games_feed.rb +22 -0
  21. data/lib/nfl_data/my_sports_feeds/weekly_player_gamelogs.rb +21 -0
  22. data/lib/nfl_data/parsers/player_parser.rb +21 -77
  23. data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
  24. data/lib/nfl_data/parsers/statline_parser.rb +27 -71
  25. data/lib/nfl_data/player.rb +13 -0
  26. data/lib/nfl_data/schedule.rb +12 -0
  27. data/lib/nfl_data/statline.rb +20 -0
  28. data/lib/nfl_data/version.rb +1 -1
  29. data/nfl_data.gemspec +23 -22
  30. data/spec/api/player_spec.rb +24 -0
  31. data/spec/api/schedule_spec.rb +20 -0
  32. data/spec/api/statline_spec.rb +31 -0
  33. data/spec/models/game_spec.rb +15 -0
  34. data/spec/models/player_spec.rb +42 -0
  35. data/spec/models/schedule_spec.rb +17 -0
  36. data/spec/models/statline_spec.rb +63 -0
  37. data/spec/my_sports_feeds/client_spec.rb +17 -0
  38. data/spec/my_sports_feeds/players_feed_spec.rb +50 -0
  39. data/spec/my_sports_feeds/seasonal_games_feed_spec.rb +41 -0
  40. data/spec/my_sports_feeds/weekly_player_gamelogs_spec.rb +144 -0
  41. data/spec/parsers/player_parser_spec.rb +63 -0
  42. data/spec/parsers/schedule_parser_spec.rb +41 -0
  43. data/spec/parsers/statline_parser_spec.rb +68 -0
  44. data/spec/spec_helper.rb +55 -0
  45. metadata +98 -52
  46. data/.codeclimate.yml +0 -5
  47. data/.rubocop.yml +0 -2
  48. data/lib/nfl_data/api/team.rb +0 -23
  49. data/lib/nfl_data/models/player.rb +0 -20
  50. data/lib/nfl_data/models/statline.rb +0 -21
  51. data/lib/nfl_data/models/team.rb +0 -38
  52. data/lib/nfl_data/parsers/parser_helper.rb +0 -6
  53. data/lib/nfl_data/parsers/team_parser.rb +0 -94
  54. data/test/nfl_data/api/player_test.rb +0 -25
  55. data/test/nfl_data/api/statline_test.rb +0 -21
  56. data/test/nfl_data/api/team_test.rb +0 -13
  57. data/test/nfl_data/models/player_test.rb +0 -79
  58. data/test/nfl_data/models/statline_test.rb +0 -121
  59. data/test/nfl_data/models/team_test.rb +0 -43
  60. data/test/nfl_data/parsers/player_parser_test.rb +0 -86
  61. data/test/nfl_data/parsers/statline_parser_test.rb +0 -34
  62. data/test/nfl_data/parsers/team_parser_test.rb +0 -41
  63. data/test/test_helper.rb +0 -14
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::Api::Statline do
4
+ subject { described_class.new }
5
+
6
+ it "provides the players in json" do
7
+ VCR.use_cassette("msf_weekly_gamelogs") do
8
+ expect(JSON.parse(subject.statlines(year: 2019, week: 1))).to resemble_json(
9
+ "statlines": [
10
+ {
11
+ "rush_atts": 1,
12
+ "rush_yards": 6,
13
+ "rush_tds": 0,
14
+ "fumbles": 0,
15
+ "pass_comp": 0,
16
+ "pass_att": 0,
17
+ "pass_yards": 0,
18
+ "pass_tds": 0,
19
+ "ints": 0,
20
+ "qb_rating": 0.0,
21
+ "receptions": 0,
22
+ "rec_yards": 0,
23
+ "rec_tds": 0,
24
+ "msf_game_id": 51465,
25
+ "msf_player_id": 6826
26
+ }
27
+ ]
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::Game do
4
+ let(:game) { described_class.new }
5
+
6
+ it { should respond_to :week }
7
+ it { should respond_to :home_team }
8
+ it { should respond_to :away_team }
9
+ it { should respond_to :start_time }
10
+
11
+ it "should be able to be initialized with keyword args" do
12
+ game = described_class.new(week: 1)
13
+ expect(game.week).to eq(1)
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ RSpec.describe NflData::Player do
2
+ let(:player) { described_class.new }
3
+
4
+ it { should respond_to(:first_name) }
5
+ it { should respond_to(:last_name) }
6
+ it { should respond_to(:full_name) }
7
+ it { should respond_to(:position) }
8
+ it { should respond_to(:number) }
9
+ it { should respond_to(:team) }
10
+ it { should respond_to(:msf_player_id) }
11
+ it { should respond_to(:image_source) }
12
+
13
+ describe "convert to hash" do
14
+ before do
15
+ player.first_name = "John"
16
+ player.last_name = "Elway"
17
+ player.position = "QB"
18
+ player.full_name = "John Elway"
19
+ player.number = 7
20
+ player.team = "Broncos"
21
+ player.msf_player_id = "123"
22
+ player.image_source = "google.com"
23
+ end
24
+
25
+ def valid_player_hash
26
+ {
27
+ first_name: "John",
28
+ last_name: "Elway",
29
+ full_name: "John Elway",
30
+ position: "QB",
31
+ number: 7,
32
+ team: "Broncos",
33
+ msf_player_id: "123",
34
+ image_source: "google.com"
35
+ }
36
+ end
37
+
38
+ it "can return itself as hash" do
39
+ expect(player.to_h).to eq(valid_player_hash)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::Schedule do
4
+ let(:schedule) { described_class.new }
5
+
6
+ it "should be empty when there are no games" do
7
+ expect(schedule.games).to be_empty
8
+ end
9
+
10
+ it "should return an array of game hashes" do
11
+ game_1 = NflData::Game.new(week: 1, away_team: "Raiders")
12
+ game_2 = NflData::Game.new(week: 1, away_team: "Broncos")
13
+ schedule.games = [game_1, game_2]
14
+
15
+ expect(schedule.to_h[:games]).to eq([game_1.to_h, game_2.to_h])
16
+ end
17
+ end
@@ -0,0 +1,63 @@
1
+ RSpec.describe NflData::Statline do
2
+ let(:statline) { described_class.new }
3
+
4
+ it { should respond_to(:rush_atts) }
5
+ it { should respond_to(:rush_yards) }
6
+ it { should respond_to(:rush_tds) }
7
+ it { should respond_to(:fumbles) }
8
+ it { should respond_to(:pass_comp) }
9
+ it { should respond_to(:pass_att) }
10
+ it { should respond_to(:pass_yards) }
11
+ it { should respond_to(:pass_tds) }
12
+ it { should respond_to(:ints) }
13
+ it { should respond_to(:qb_rating) }
14
+ it { should respond_to(:receptions) }
15
+ it { should respond_to(:rec_yards) }
16
+ it { should respond_to(:rec_tds) }
17
+ it { should respond_to(:msf_game_id) }
18
+ it { should respond_to(:msf_player_id) }
19
+
20
+ describe "convert to hash" do
21
+ before do
22
+ statline.msf_player_id = "123"
23
+ statline.msf_game_id = 17
24
+ statline.rush_atts = 1
25
+ statline.rush_yards = 25
26
+ statline.rush_tds = 1
27
+ statline.fumbles = 0
28
+ statline.pass_comp = 1
29
+ statline.pass_att = 2
30
+ statline.pass_yards = 100
31
+ statline.pass_tds = 1
32
+ statline.ints = 1
33
+ statline.qb_rating = "46.8"
34
+ statline.receptions = 2
35
+ statline.rec_yards = 25
36
+ statline.rec_tds = 1
37
+ end
38
+
39
+ def valid_statline_hash
40
+ {
41
+ msf_player_id: "123",
42
+ msf_game_id: 17,
43
+ rush_atts: 1,
44
+ rush_yards: 25,
45
+ rush_tds: 1,
46
+ fumbles: 0,
47
+ pass_comp: 1,
48
+ pass_att: 2,
49
+ pass_yards: 100,
50
+ pass_tds: 1,
51
+ ints: 1,
52
+ qb_rating: "46.8",
53
+ receptions: 2,
54
+ rec_yards: 25,
55
+ rec_tds: 1
56
+ }
57
+ end
58
+
59
+ it "can return itself as hash" do
60
+ expect(statline.to_h).to eq(valid_statline_hash)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::MySportsFeeds::Client do
4
+ subject do
5
+ described_class.new(api_host: "http://api.example.com",
6
+ api_key: "123",
7
+ api_version: "v2")
8
+ end
9
+
10
+ it "should request json format" do
11
+ expect(subject.format).to eq("json")
12
+ end
13
+
14
+ it "should construct the base url" do
15
+ expect(subject.base_url).to eq("http://api.example.com/v2/pull/nfl/")
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::MySportsFeeds::PlayersFeed do
4
+ subject { described_class.new }
5
+
6
+ let(:feed) { subject.feed }
7
+
8
+ it "requests the players" do
9
+ VCR.use_cassette("msf_players") do
10
+ expect(subject.feed.find { |player| player.dig("player", "id") == 6826 }).to resemble_json(
11
+ {
12
+ "player" => {
13
+ "id" => 6826,
14
+ "firstName" => "Ameer",
15
+ "lastName" => "Abdullah",
16
+ "primaryPosition" => "RB",
17
+ "alternatePositions" => [],
18
+ "jerseyNumber" => 31,
19
+ "currentTeam" => {"id" => 63, "abbreviation" => "MIN"},
20
+ "currentRosterStatus" => "ROSTER",
21
+ "currentInjury" => nil,
22
+ "height" => "5'9\"",
23
+ "weight" => 203,
24
+ "birthDate" => "1993-06-13",
25
+ "age" => 27,
26
+ "birthCity" => "Mobile, AL",
27
+ "birthCountry" => "USA",
28
+ "rookie" => false,
29
+ "highSchool" => nil,
30
+ "college" => "Nebraska",
31
+ "handedness" => nil,
32
+ "officialImageSrc" => "http://static.nfl.com/static/content/public/static/img/fantasy/transparent/200x200/ABD647726.png",
33
+ "socialMediaAccounts" => [],
34
+ "currentContractYear" => nil,
35
+ "drafted" => {"year" => 2015, "team" => {"id" => 61, "abbreviation" => "DET"},
36
+ "pickTeam" => {"id" => 61, "abbreviation" => "DET"},
37
+ "round" => 2,
38
+ "roundPick" => 22,
39
+ "overallPick" => 54},
40
+ "externalMappings" => [{"source" => "NFL.com Stats Leaders", "id" => "ABD647726"}]
41
+ },
42
+ "teamAsOfDate" => {
43
+ "id" => 63,
44
+ "abbreviation" => "MIN"
45
+ }
46
+ }
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::MySportsFeeds::SeasonalGamesFeed do
4
+ subject { described_class.new }
5
+
6
+ it "requests the season schedule" do
7
+ VCR.use_cassette("msf_seasonal_games") do
8
+ expect(subject.feed(season_start_year: 2020).first).to resemble_json(
9
+ "id": 40557,
10
+ "week": 14,
11
+ "startTime": "2017-12-10T18:00:00.000Z",
12
+ "endedTime": nil,
13
+ "awayTeam": {
14
+ "id": 65,
15
+ "abbreviation": "IND"
16
+ },
17
+ "homeTeam": {
18
+ "id": 48,
19
+ "abbreviation": "BUF"
20
+ },
21
+ "venue": {
22
+ "id": 46,
23
+ "name": "New Era Field"
24
+ },
25
+ "venueAllegiance": "NEUTRAL",
26
+ "scheduleStatus": "NORMAL",
27
+ "originalStartTime": nil,
28
+ "delayedOrPostponedReason": nil,
29
+ "playedStatus": "COMPLETED",
30
+ "attendance": nil,
31
+ "officials": Array,
32
+ "broadcasters": Array,
33
+ "weather": nil
34
+ )
35
+ end
36
+ end
37
+
38
+ it "should convert year to compatible season slug" do
39
+ expect(subject.season_slug(2020)).to eq("2020-2021-regular")
40
+ end
41
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::MySportsFeeds::WeeklyPlayerGamelogs do
4
+ subject { described_class.new }
5
+
6
+ it "requests the season schedule" do
7
+ VCR.use_cassette("msf_weekly_gamelogs") do
8
+ expect(subject.feed(season_start_year: 2019, week: 1).first).to resemble_json(
9
+ {
10
+ "game": {
11
+ "id": 40606,
12
+ "week": 17,
13
+ "startTime": "2017-12-31T21:25:00.000Z",
14
+ "awayTeamAbbreviation": "JAX",
15
+ "homeTeamAbbreviation": "TEN"
16
+ },
17
+ "player": {
18
+ "id": 8640,
19
+ "firstName": "Marcus",
20
+ "lastName": "Mariota",
21
+ "position": "QB",
22
+ "jerseyNumber": 8
23
+ },
24
+ "team": {
25
+ "id": 67,
26
+ "abbreviation": "TEN"
27
+ },
28
+ "stats": {
29
+ "passing": {
30
+ "passAttempts": 21,
31
+ "passCompletions": 12,
32
+ "passPct": 57.1,
33
+ "passYards": 134,
34
+ "passAvg": 6.4,
35
+ "passYardsPerAtt": 6.4,
36
+ "passTD": 1,
37
+ "passTDPct": 4.8,
38
+ "passInt": 0,
39
+ "passIntPct": 0,
40
+ "passLng": 66,
41
+ "pass20Plus": 1,
42
+ "pass40Plus": 1,
43
+ "passSacks": 3,
44
+ "passSackY": 18,
45
+ "qbRating": 92.2
46
+ },
47
+ "rushing": {
48
+ "rushAttempts": 10,
49
+ "rushYards": 60,
50
+ "rushAverage": 6,
51
+ "rushTD": 0,
52
+ "rushLng": 66,
53
+ "rush1stDowns": 4,
54
+ "rush1stDownsPct": 40,
55
+ "rush20Plus": 0,
56
+ "rush40Plus": 0,
57
+ "rushFumbles": 1
58
+ },
59
+ "receiving": {
60
+ "targets": 0,
61
+ "receptions": 0,
62
+ "recYards": 0,
63
+ "recAverage": 0,
64
+ "recTD": 0,
65
+ "recLng": 0,
66
+ "rec1stDowns": 0,
67
+ "rec20Plus": 0,
68
+ "rec40Plus": 0,
69
+ "recFumbles": 0
70
+ },
71
+ "tackles": {
72
+ "tackleSolo": 0,
73
+ "tackleTotal": 0,
74
+ "tackleAst": 0,
75
+ "sacks": 0,
76
+ "sackYds": 0,
77
+ "tacklesForLoss": 0
78
+ },
79
+ "interceptions": {
80
+ "interceptions": 0,
81
+ "intTD": 0,
82
+ "intYds": 0,
83
+ "intAverage": 0,
84
+ "intLng": 0,
85
+ "passesDefended": 0,
86
+ "stuffs": 0,
87
+ "stuffYds": 0,
88
+ "safeties": 0,
89
+ "kB": 0
90
+ },
91
+ "fumbles": {
92
+ "fumbles": 1,
93
+ "fumLost": 1,
94
+ "fumForced": 0,
95
+ "fumOwnRec": 0,
96
+ "fumOppRec": 0,
97
+ "fumRecYds": -74,
98
+ "fumTotalRec": 0,
99
+ "fumTD": 0
100
+ },
101
+ "kickoffReturns": {
102
+ "krRet": 0,
103
+ "krYds": 0,
104
+ "krAvg": 0,
105
+ "krLng": 0,
106
+ "krTD": 0,
107
+ "kr20Plus": 0,
108
+ "kr40Plus": 0,
109
+ "krFC": 0,
110
+ "krFum": 0
111
+ },
112
+ "puntReturns": {
113
+ "prRet": 0,
114
+ "prYds": 0,
115
+ "prAvg": 0,
116
+ "prLng": 0,
117
+ "prTD": 0,
118
+ "pr20Plus": 0,
119
+ "pr40Plus": 0,
120
+ "prFC": 0,
121
+ "prFum": 0
122
+ },
123
+ "miscellaneous": {
124
+ "gamesStarted": 1
125
+ },
126
+ "twoPointAttempts": {
127
+ "twoPtAtt": 0,
128
+ "twoPtMade": 0,
129
+ "twoPtPassAtt": 0,
130
+ "twoPtPassMade": 0,
131
+ "twoPtPassRec": 0,
132
+ "twoPtRushAtt": 0,
133
+ "twoPtRushMade": 0
134
+ }
135
+ }
136
+ }
137
+ )
138
+ end
139
+ end
140
+
141
+ it "should convert year to compatible season slug" do
142
+ expect(subject.season_slug(2020)).to eq("2020-2021-regular")
143
+ end
144
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NflData::Parsers::PlayerParser do
4
+ subject(:parsed) { described_class.new.parse(player_data: player_data) }
5
+
6
+ let(:player_data) do
7
+ [
8
+ {
9
+ "player" => {
10
+ "id" => 13507,
11
+ "firstName" => "Manny",
12
+ "lastName" => "Abad",
13
+ "primaryPosition" => "DB",
14
+ "alternatePositions" => [],
15
+ "jerseyNumber" => 38,
16
+ "currentTeam" => {
17
+ "id" => 67,
18
+ "abbreviation" => "TEN"
19
+ },
20
+ "currentRosterStatus" => "ROSTER",
21
+ "currentInjury" => nil,
22
+ "height" => "5'11\"",
23
+ "weight" => 184,
24
+ "birthDate" => "1993-11-23",
25
+ "age" => 24,
26
+ "birthCity" => nil,
27
+ "birthCountry" => nil,
28
+ "rookie" => false,
29
+ "highSchool" => nil,
30
+ "college" => nil,
31
+ "handedness" => nil,
32
+ "officialImageSrc" => "nfl.com",
33
+ "socialMediaAccounts" => [],
34
+ "currentContractYear" => nil,
35
+ "drafted" => nil,
36
+ "externalMappings" => []
37
+ },
38
+ "teamAsOfDate" => {
39
+ "id" => 67,
40
+ "abbreviation" => "TEN"
41
+ }
42
+ }
43
+ ]
44
+ end
45
+
46
+ let(:player) { parsed.first }
47
+
48
+ it "should return an array of players" do
49
+ expect(parsed).to be_a(Array)
50
+ expect(player).to be_a(NflData::Player)
51
+ end
52
+
53
+ it "should parse the games" do
54
+ expect(player.first_name).to eq("Manny")
55
+ expect(player.last_name).to eq("Abad")
56
+ expect(player.full_name).to eq("Manny Abad")
57
+ expect(player.position).to eq("DB")
58
+ expect(player.number).to eq(38)
59
+ expect(player.team).to eq("TEN")
60
+ expect(player.msf_player_id).to eq(13507)
61
+ expect(player.image_source).to eq("nfl.com")
62
+ end
63
+ end