nfl_data 0.0.14 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.envrc +7 -0
- data/.gitignore +3 -3
- data/.rspec +1 -0
- data/.standard.yml +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +94 -22
- data/Rakefile +5 -6
- data/bin/console +1 -1
- data/bin/setup +8 -0
- data/lib/nfl_data.rb +10 -19
- data/lib/nfl_data/api/player.rb +8 -26
- data/lib/nfl_data/api/schedule.rb +19 -0
- data/lib/nfl_data/api/statline.rb +8 -22
- data/lib/nfl_data/models/game.rb +5 -0
- data/lib/nfl_data/models/player.rb +11 -18
- data/lib/nfl_data/models/schedule.rb +12 -0
- data/lib/nfl_data/models/statline.rb +18 -19
- data/lib/nfl_data/my_sports_feeds/client.rb +45 -0
- data/lib/nfl_data/my_sports_feeds/players_feed.rb +18 -0
- data/lib/nfl_data/my_sports_feeds/seasonal_games_feed.rb +22 -0
- data/lib/nfl_data/my_sports_feeds/weekly_player_gamelogs.rb +21 -0
- data/lib/nfl_data/parsers/player_parser.rb +20 -93
- data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
- data/lib/nfl_data/parsers/statline_parser.rb +27 -71
- data/lib/nfl_data/version.rb +1 -1
- data/nfl_data.gemspec +23 -23
- data/spec/api/player_spec.rb +24 -0
- data/spec/api/schedule_spec.rb +20 -0
- data/spec/api/statline_spec.rb +31 -0
- data/spec/models/game_spec.rb +15 -0
- data/spec/models/player_spec.rb +42 -0
- data/spec/models/schedule_spec.rb +17 -0
- data/spec/models/statline_spec.rb +63 -0
- data/spec/my_sports_feeds/client_spec.rb +17 -0
- data/spec/my_sports_feeds/players_feed_spec.rb +49 -0
- data/spec/my_sports_feeds/seasonal_games_feed_spec.rb +41 -0
- data/spec/my_sports_feeds/weekly_player_gamelogs_spec.rb +144 -0
- data/spec/parsers/player_parser_spec.rb +63 -0
- data/spec/parsers/schedule_parser_spec.rb +41 -0
- data/spec/parsers/statline_parser_spec.rb +68 -0
- data/spec/spec_helper.rb +55 -0
- metadata +83 -52
- data/.codeclimate.yml +0 -5
- data/.rubocop.yml +0 -2
- data/lib/nfl_data/api/team.rb +0 -23
- data/lib/nfl_data/models/team.rb +0 -38
- data/lib/nfl_data/parsers/data/teams.rb +0 -36
- data/lib/nfl_data/parsers/parser_helper.rb +0 -6
- data/lib/nfl_data/parsers/team_parser.rb +0 -76
- data/test/nfl_data/api/player_test.rb +0 -25
- data/test/nfl_data/api/statline_test.rb +0 -21
- data/test/nfl_data/api/team_test.rb +0 -13
- data/test/nfl_data/models/player_test.rb +0 -81
- data/test/nfl_data/models/statline_test.rb +0 -121
- data/test/nfl_data/models/team_test.rb +0 -43
- data/test/nfl_data/parsers/player_parser_test.rb +0 -81
- data/test/nfl_data/parsers/statline_parser_test.rb +0 -34
- data/test/nfl_data/parsers/team_parser_test.rb +0 -37
- data/test/test_helper.rb +0 -14
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe NflData::Api::Schedule do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it "provides the season in json" do
|
7
|
+
VCR.use_cassette("msf_seasonal_games") do
|
8
|
+
expect(JSON.parse(subject.season(year: 2020))).to resemble_json(
|
9
|
+
"games": [
|
10
|
+
{
|
11
|
+
"week": 1,
|
12
|
+
"away_team": "KC",
|
13
|
+
"home_team": "DEN",
|
14
|
+
"start_time": Time.now
|
15
|
+
}
|
16
|
+
]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -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,49 @@
|
|
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.first).to resemble_json(
|
11
|
+
{
|
12
|
+
"player": {
|
13
|
+
"id": 13507,
|
14
|
+
"firstName": "Manny",
|
15
|
+
"lastName": "Abad",
|
16
|
+
"primaryPosition": "DB",
|
17
|
+
"alternatePositions": Array,
|
18
|
+
"jerseyNumber": 38,
|
19
|
+
"currentTeam": {
|
20
|
+
"id": 67,
|
21
|
+
"abbreviation": "TEN"
|
22
|
+
},
|
23
|
+
"currentRosterStatus": "ROSTER",
|
24
|
+
"currentInjury": nil,
|
25
|
+
"height": nil,
|
26
|
+
"weight": nil,
|
27
|
+
"birthDate": "1993-11-23",
|
28
|
+
"age": 24,
|
29
|
+
"birthCity": nil,
|
30
|
+
"birthCountry": nil,
|
31
|
+
"rookie": false,
|
32
|
+
"highSchool": nil,
|
33
|
+
"college": nil,
|
34
|
+
"handedness": nil,
|
35
|
+
"officialImageSrc": nil,
|
36
|
+
"socialMediaAccounts": Array,
|
37
|
+
"currentContractYear": nil,
|
38
|
+
"drafted": nil,
|
39
|
+
"externalMappings": Array
|
40
|
+
},
|
41
|
+
"teamAsOfDate": {
|
42
|
+
"id": 67,
|
43
|
+
"abbreviation": "TEN"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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
|