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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fde80abd92b5afed0b3c16a9cd3d687387380bd5
4
- data.tar.gz: f904cf0f9158c3996494aff4864f1ab3767daa59
2
+ SHA256:
3
+ metadata.gz: 11ff82cffbfc2eb617a981c072f60cae3b57ef849cead1c5d19d582840484e81
4
+ data.tar.gz: 698b9e7e774bc906ab8821a4a408e829541f8a1d9fd29dac100129b21a3df41b
5
5
  SHA512:
6
- metadata.gz: 6e7d173e1e01bdf293fda1ad9c5c495bb6d7a3f4d5ee0382a680e411241450aaf0c6c762aeb7334a48ec6f403de1e702ceeec7981d29b5478123f9dac38b415e
7
- data.tar.gz: fd76a8e7240ae7b46e4c5b084c52138f11eb671de0ae7d8115d926a205e510636563d670e3291ec138e68688e1e594e134baeb729fc57c200944f1059528b365
6
+ metadata.gz: 20be7edab126dbbf2ee1f993c3ff7e9c657f3bdae61d3ee4d8adc836a219b6545045a6f55e4711a0e0c0ff329eaba8a08ec20c04abc3dede085496dae749c6f9
7
+ data.tar.gz: 0dce67944ff44f3e6d4adc5a0c691ebb3677c8deef98ed0005caf3122c070dda56024d75b2506f95ace6eb5f365d8b583fd68163ee1e09dd8bbe075dcac8823e
data/.envrc ADDED
@@ -0,0 +1,7 @@
1
+ # Load .env variables automatically with direnv
2
+ # http://direnv.net/
3
+
4
+ if [ -e ./.env ]
5
+ then
6
+ dotenv
7
+ fi
data/.gitignore CHANGED
@@ -12,14 +12,14 @@ lib/bundler/man
12
12
  pkg
13
13
  rdoc
14
14
  spec/reports
15
- test/tmp
16
- test/version_tmp
17
15
  tmp
18
16
  *.bundle
19
17
  *.so
20
18
  *.o
21
19
  *.a
22
20
  mkmf.log
23
- test/fixtures/cassettes
24
21
  .ruby-version
25
22
  .ruby-gemset
23
+ spec/examples.txt
24
+ spec/cassettes
25
+ .env
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ parallel: true
2
+ format: progress
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.7
5
+ - 2.6
6
+ - 2.5
@@ -0,0 +1,11 @@
1
+ ## 0.1.1 / 2020-09-04
2
+
3
+ * Zeitwerk compatibility updates for usage with Rails
4
+
5
+ ## 0.1.0 / 2020-08-31
6
+
7
+ * No more NFL.com parsing, using MySportsFeeds API instead. This will require users to acquire their own MySportsFeeds accounts and API tokens. Please see the README or [the MySportsFeeds website](https://www.mysportsfeeds.com for more details.
8
+
9
+ ## 0.0.14 and previous
10
+
11
+ * This version and previous used Nokogiri to parse NFL.com. NFL has since changed their website and broken all of the parsing code. Any version before here probably won't work and should be upgraded.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in nfl_data.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,11 +1,20 @@
1
1
  # NflData
2
2
 
3
- This gem is for parsing data from NFL.com and returning a JSON blob that can be used for any fantasy related activities you may wish to pursue.
3
+ This gem is for parsing data from NFL.com and returning a JSON blob that can be used
4
+ for any fantasy related activities you may wish to pursue.
4
5
 
5
- This was written by @mikesells and @thetizzo
6
+ **However** since NFL.com has updated their website to a much more difficult to parse version,
7
+ this gem is now going to be using [MySportsFeeds API](https://www.mysportsfeeds.com/data-feeds/) instead.
8
+
9
+ Thanks to the people at [MySportsFeeds](https://www.mysportsfeeds.com) for providing an affordable
10
+ service for this type of data. If you would like to use this gem I encourage you to head over to their
11
+ website and sign up for an account.
12
+
13
+ This gem was written by @mikesells and @thetizzo
6
14
 
7
15
  [![Gem Version](https://badge.fury.io/rb/nfl_data.svg)](http://badge.fury.io/rb/nfl_data)
8
- [![Code Climate](https://codeclimate.com/github/thetizzo/nfl_data/badges/gpa.svg)](https://codeclimate.com/github/thetizzo/nfl_data)
16
+
17
+ [![Build Status](https://travis-ci.com/thetizzo/nfl_data.svg?branch=master)](https://travis-ci.com/thetizzo/nfl_data)
9
18
 
10
19
  ## Installation
11
20
 
@@ -21,24 +30,56 @@ Or install it yourself as:
21
30
 
22
31
  $ gem install nfl_data
23
32
 
24
- ## Usage
33
+ ## Configuration
25
34
 
26
- To use this gem there are some simple calls that can be made. Everything should return JSON.
35
+ Configuration for [MySportsFeeds API](https://www.mysportsfeeds.com/data-feeds/) credentials
36
+ can be set with the following Environment Variables:
27
37
 
28
- ### Players
38
+ ```
39
+ MYSPORTSFEEDS_API_KEY
40
+ MYSPORTSFEEDS_API_HOST
41
+ MYSPORTSFEEDS_API_VERSION
42
+ ```
29
43
 
30
- Pull players by position:
44
+ ### MySportsFeeds API Docs
31
45
 
32
- ```ruby
33
- NflData::API::Player.get_all
46
+ https://www.mysportsfeeds.com/data-feeds/api-docs/
34
47
 
35
- NflData::API::Player.get_quarterbacks
48
+ I've written this to use >= v2.1 of the MSF API.
36
49
 
37
- NflData::API::Player.get_runningbacks
50
+ ## Usage
38
51
 
39
- NflData::API::Player.get_wide_receivers
52
+ To use this gem there are some simple calls that can be made. Everything will return JSON.
53
+
54
+ ### Players
40
55
 
41
- NflData::API::Player.get_tight_ends
56
+ Pull players by position. Not passing a position param will pull all players.
57
+
58
+ Position param is passed through to MySportsFeeds and can be any value they accept. Please see
59
+ their docs above.
60
+
61
+ ```ruby
62
+ NflData::API::Player.new.players(position: "qb")
63
+ ```
64
+
65
+ #### Example Response
66
+
67
+ ```json
68
+ {
69
+ "players": [
70
+ {
71
+ "first_name": "John",
72
+ "last_name": "Elway",
73
+ "full_name": "John Elway",
74
+ "position": "QB",
75
+ "number": 7,
76
+ "team": "DEN",
77
+ "msf_player_id": 12345,
78
+ "image_source":""
79
+ },
80
+ ...
81
+ ]
82
+ }
42
83
  ```
43
84
 
44
85
  ### Statlines
@@ -46,21 +87,52 @@ Pull players by position:
46
87
  Pull statlines by week and year:
47
88
 
48
89
  ```ruby
49
- NflData::API::Statline.get_passing(1, 2014)
50
-
51
- NflData::API::Statline.get_rushing(1, 2014)
52
-
53
- NflData::API::Statline.get_receiving(1, 2014)
90
+ NflData::API::Statline.new.statlines(year: 2020, week: 1)
54
91
  ```
55
92
 
56
- ### Teams
93
+ #### Example Response
94
+
95
+ ```json
96
+ {
97
+ "statlines": [
98
+ {
99
+ "rush_atts": 2,
100
+ "rush_yards": 11,
101
+ "rush_tds": 1,
102
+ "fumbles": 0,
103
+ "pass_comp": 11,
104
+ "pass_att": 23,
105
+ "pass_yards": 123,
106
+ "pass_tds": 2,
107
+ "ints": 1,
108
+ "qb_rating": 92.6,
109
+ "receptions": 3,
110
+ "rec_yards": 10,
111
+ "rec_tds": 0,
112
+ "msf_game_id": 51465,
113
+ "msf_player_id": 6826
114
+ }
115
+ ...
116
+ ]
117
+ }
118
+ ```
57
119
 
58
- Pull teams by year with or without schedules:
120
+ ### Schedule
59
121
 
122
+ Pull season schedule by year:
60
123
  ```ruby
61
- NflData::API::Team.get_all(2014)
124
+ NflData::Api::Schedule.new.season(year: 2020)
125
+ ```
126
+
127
+ #### Example Response
62
128
 
63
- NflData::API::Team.get_all_with_schedule(2014)
129
+ ```json
130
+ {
131
+ "games": [
132
+ {"week":1,"away_team":"HOU","home_team":"KC","start_time":"2020-09-10T04:25:00.000Z"}
133
+ ...
134
+ ]
135
+ }
64
136
  ```
65
137
 
66
138
  ## Contributing
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
- require 'bundler/gem_tasks'
1
+ require "bundler/gem_tasks"
2
+ require "standard/rake"
3
+ require "rspec/core/rake_task"
2
4
 
3
- require 'rake/testtask'
5
+ RSpec::Core::RakeTask.new(:spec)
4
6
 
5
- Rake::TestTask.new do |t|
6
- t.libs << 'test'
7
- t.pattern = 'test/**/*_test.rb'
8
- end
7
+ task default: [:spec, :standard]
@@ -5,4 +5,4 @@ require 'irb'
5
5
  require 'irb/completion'
6
6
  require 'nfl_data'
7
7
 
8
- IRB.start
8
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,21 +1,12 @@
1
- require 'nfl_data/version'
2
-
3
- require 'nokogiri'
4
- require 'open-uri'
5
- require 'json'
6
-
7
- require 'nfl_data/models/player'
8
- require 'nfl_data/models/statline'
9
- require 'nfl_data/models/team'
10
-
11
- require 'nfl_data/parsers/parser_helper'
12
- require 'nfl_data/parsers/player_parser'
13
- require 'nfl_data/parsers/statline_parser'
14
- require 'nfl_data/parsers/team_parser'
15
-
16
- require 'nfl_data/api/player'
17
- require 'nfl_data/api/statline'
18
- require 'nfl_data/api/team'
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "json"
4
+ require "typhoeus"
5
+ require "base64"
6
+ require "zeitwerk"
7
+
8
+ loader = Zeitwerk::Loader.for_gem
9
+ loader.setup
19
10
 
20
11
  module NflData
21
12
  end
@@ -1,34 +1,16 @@
1
1
  module NflData
2
- module API
2
+ module Api
3
3
  class Player
4
- def initialize
5
- @parser = PlayerParser.new
6
- end
4
+ attr_reader :parser, :feed
7
5
 
8
- def get(position)
9
- @parser.get_by_position(position).to_json
6
+ def initialize(parser: Parsers::PlayerParser.new, feed: MySportsFeeds::PlayersFeed.new)
7
+ @parser = parser
8
+ @feed = feed
10
9
  end
11
10
 
12
- class << self
13
- def get_all
14
- new.get(:all)
15
- end
16
-
17
- def get_quarterbacks
18
- new.get(:quarterbacks)
19
- end
20
-
21
- def get_runningbacks
22
- new.get(:runningbacks)
23
- end
24
-
25
- def get_wide_receivers
26
- new.get(:wide_receivers)
27
- end
28
-
29
- def get_tight_ends
30
- new.get(:tight_ends)
31
- end
11
+ def players(position: nil)
12
+ player_data = feed.feed(position: position)
13
+ {players: parser.parse(player_data: player_data).map(&:to_h)}.to_json
32
14
  end
33
15
  end
34
16
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NflData
4
+ module Api
5
+ class Schedule
6
+ attr_reader :parser, :feed
7
+
8
+ def initialize(parser: Parsers::ScheduleParser.new, feed: MySportsFeeds::SeasonalGamesFeed.new)
9
+ @parser = parser
10
+ @feed = feed
11
+ end
12
+
13
+ def season(year:)
14
+ schedule_data = feed.feed(season_start_year: year)
15
+ parser.parse(schedule_data: schedule_data).to_h.to_json
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,30 +1,16 @@
1
1
  module NflData
2
- module API
2
+ module Api
3
3
  class Statline
4
- def initialize
5
- @parser = StatlineParser.new
6
- end
4
+ attr_reader :parser, :feed
7
5
 
8
- def get(week, year, stat_type)
9
- @parser.get(week, year, stat_type).to_json
6
+ def initialize(parser: Parsers::StatlineParser.new, feed: MySportsFeeds::WeeklyPlayerGamelogs.new)
7
+ @parser = parser
8
+ @feed = feed
10
9
  end
11
10
 
12
- class << self
13
- def get_all(week, year)
14
- new.get(week, year, :all)
15
- end
16
-
17
- def get_passing(week, year)
18
- new.get(week, year, :passing)
19
- end
20
-
21
- def get_rushing(week, year)
22
- new.get(week, year, :rushing)
23
- end
24
-
25
- def get_receiving(week, year)
26
- new.get(week, year, :receiving)
27
- end
11
+ def statlines(year:, week:)
12
+ statline_data = feed.feed(season_start_year: year, week: week)
13
+ {statlines: parser.parse(statline_data: statline_data).map(&:to_h)}.to_json
28
14
  end
29
15
  end
30
16
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NflData
4
+ Game = Struct.new(:week, :away_team, :home_team, :start_time, keyword_init: true)
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NflData
4
+ module MySportsFeeds
5
+ class Client
6
+ attr_reader :base_url, :api_key, :api_host, :api_version, :format
7
+
8
+ def initialize(
9
+ api_host: ENV.fetch("MYSPORTSFEEDS_API_HOST"),
10
+ api_key: ENV.fetch("MYSPORTSFEEDS_API_KEY"),
11
+ api_version: ENV.fetch("MYSPORTSFEEDS_API_VERSION")
12
+ )
13
+ @api_host = api_host
14
+ @api_key = api_key
15
+ @api_version = api_version
16
+ @format = "json"
17
+ @base_url = "#{@api_host}/#{@api_version}/pull/nfl/"
18
+ end
19
+
20
+ def get(endpoint:, params: {})
21
+ request(method: :get, endpoint: endpoint, params: params)
22
+ end
23
+
24
+ private
25
+
26
+ def request(method:, endpoint:, params:)
27
+ request = Typhoeus::Request.new(
28
+ "#{base_url}#{endpoint}.#{format}",
29
+ method: method,
30
+ params: params,
31
+ accept_encoding: "gzip",
32
+ userpwd: "#{api_key}:MYSPORTSFEEDS"
33
+ )
34
+
35
+ # request.on_complete do |response|
36
+ # if response.success?
37
+ # end
38
+ # end
39
+
40
+ response = request.run
41
+ JSON.parse(response.body)
42
+ end
43
+ end
44
+ end
45
+ end