nhl_stats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4754e1a9e0ecd04c5f06cbcf240234e365e335c089b4737fd0a54b762956e7ba
4
+ data.tar.gz: 5d68b5d523a585ce03ea2b6f07a15a07870d2e9e3aee390b2c312d3fa21a3cfa
5
+ SHA512:
6
+ metadata.gz: f96380dae1725d572dd788726e528cbccf75f005f3cfa712d59021235817a61d3dd90fbe89b1093fb35e444e3f835ab0518a21336da4cf93ce1180fb2594ca71
7
+ data.tar.gz: b84f054d0ade94e70368b550214244aaa1dfe6a918b95cc0cce87a2e28dbba2a4d2f20e6a9e08d52f9c8b898c51ad7d32befc72803442227e14bc674ad47eceb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,36 @@
1
+ Layout/AlignArguments:
2
+ EnforcedStyle: with_fixed_indentation
3
+
4
+ Layout/DotPosition:
5
+ EnforcedStyle: trailing
6
+
7
+ Layout/IndentFirstArrayElement:
8
+ EnforcedStyle: consistent
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*'
13
+
14
+ Metrics/LineLength:
15
+ Max: 120
16
+
17
+ Style/Documentation:
18
+ Enabled: false
19
+
20
+ Style/FrozenStringLiteralComment:
21
+ EnforcedStyle: never
22
+
23
+ Style/HashSyntax:
24
+ EnforcedStyle: no_mixed_keys
25
+
26
+ Style/NumericLiterals:
27
+ MinDigits: 12
28
+
29
+ Style/StringLiterals:
30
+ EnforcedStyle: double_quotes
31
+
32
+ Style/TrailingCommaInArrayLiteral:
33
+ EnforcedStyleForMultiline: comma
34
+
35
+ Style/TrailingCommaInHashLiteral:
36
+ EnforcedStyleForMultiline: comma
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ - 2.6.1
8
+ before_install: gem install bundler -v 2.0.2
9
+
10
+ matrix:
11
+ include:
12
+ - script: bundle exec rubocop
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at wright1@ualberta.ca. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nhl_stats.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "rubocop"
8
+ end
9
+
10
+ group :development do
11
+ gem "bundler"
12
+ gem "rake"
13
+ gem "rspec"
14
+ gem "vcr"
15
+ gem "webmock"
16
+
17
+ gem "pry-byebug"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nhl_stats (0.1.0)
5
+ faraday (~> 0.15.4)
6
+ json (~> 2.2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.6.0)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ ast (2.4.0)
14
+ byebug (11.0.1)
15
+ coderay (1.1.2)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.3)
19
+ faraday (0.15.4)
20
+ multipart-post (>= 1.2, < 3)
21
+ hashdiff (1.0.0)
22
+ jaro_winkler (1.5.3)
23
+ json (2.2.0)
24
+ method_source (0.9.2)
25
+ multipart-post (2.1.1)
26
+ parallel (1.17.0)
27
+ parser (2.6.3.0)
28
+ ast (~> 2.4.0)
29
+ pry (0.12.2)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.9.0)
32
+ pry-byebug (3.7.0)
33
+ byebug (~> 11.0)
34
+ pry (~> 0.10)
35
+ public_suffix (3.1.1)
36
+ rainbow (3.0.0)
37
+ rake (12.3.3)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.2)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.4)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.2)
51
+ rubocop (0.74.0)
52
+ jaro_winkler (~> 1.5.1)
53
+ parallel (~> 1.10)
54
+ parser (>= 2.6)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 1.4.0, < 1.7)
58
+ ruby-progressbar (1.10.1)
59
+ safe_yaml (1.0.5)
60
+ unicode-display_width (1.6.0)
61
+ vcr (5.0.0)
62
+ webmock (3.6.2)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff (>= 0.4.0, < 2.0.0)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler
72
+ nhl_stats!
73
+ pry-byebug
74
+ rake
75
+ rspec
76
+ rubocop
77
+ vcr
78
+ webmock
79
+
80
+ BUNDLED WITH
81
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ [![Build Status](https://travis-ci.org/ChaoticBoredom/nhl_stats.svg?branch=master)](https://travis-ci.org/ChaoticBoredom/nhl_stats)
2
+
3
+ # NHLStats
4
+
5
+ Wrapper for the NHL Stats API. Documentation for said API is done unofficially, can be found [here](https://gitlab.com/dword4/nhlapi)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nhl_stats'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nhl_stats
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ChaoticBoredom/nhl_stats. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the NHLStats project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ChaoticBoredom/nhl_stats/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nhl_stats"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
@@ -0,0 +1,48 @@
1
+ module NHLStats
2
+ class Game
3
+ attr_reader :id, :home_team_id, :away_team_id, :home_score, :away_score, :date
4
+
5
+ def initialize(game_data)
6
+ @id = game_data[:id] || game_data.dig("gamePk")
7
+ home_team_data(game_data)
8
+ away_team_data(game_data)
9
+ @date = Time.parse(game_data.dig("periods", 0, "startTime") || game_data.dig("gameDate"))
10
+ end
11
+
12
+ def home_team
13
+ NHLStats::Team.find(home_team_id)
14
+ end
15
+
16
+ def away_team
17
+ NHLStats::Team.find(away_team_id)
18
+ end
19
+
20
+ def self.find(id)
21
+ response = Faraday.get("#{API_ROOT}/game/#{id}/linescore")
22
+ attributes = JSON.parse(response.body)
23
+ new(attributes.merge(:id => id))
24
+ end
25
+
26
+ def self.list(params = {})
27
+ response = Faraday.get("#{API_ROOT}/schedule", params)
28
+ JSON.parse(response.body).
29
+ fetch("dates", []).
30
+ map { |d| d.fetch("games", []).map { |g| NHLStats::Game.new(g) } }.
31
+ flatten
32
+ end
33
+
34
+ private
35
+
36
+ def home_team_data(game_data)
37
+ home = game_data.dig("teams", "home")
38
+ @home_team_id = home.dig("team", "id")
39
+ @home_score = home.dig("goals") || home.dig("score")
40
+ end
41
+
42
+ def away_team_data(game_data)
43
+ away = game_data.dig("teams", "away")
44
+ @away_team_id = away.dig("team", "id")
45
+ @away_score = away.dig("goals") || away.dig("score")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ module NHLStats
2
+ class Player
3
+ attr_reader :id, :full_name, :first_name, :last_name, :number, :birth_date,
4
+ :nationality, :active, :position
5
+
6
+ def initialize(player_data)
7
+ @id = player_data["id"]
8
+ @full_name = player_data["fullName"]
9
+ @number = (player_data["primaryNumber"] || player_data["jerseyNumber"]).to_i
10
+ @position = player_data.dig("primaryPosition", "abbreviation") || player_data.dig("position", "abbreviation")
11
+
12
+ # Roster response returns an array of players w/o the following
13
+ if player_data.key?("firstName")
14
+ roster_response_data(player_data)
15
+ else
16
+ @active = true
17
+ end
18
+ end
19
+
20
+ def self.find(id)
21
+ response = Faraday.get("#{API_ROOT}/people/#{id}")
22
+ attributes = JSON.parse(response.body).dig("people", 0)
23
+ new(attributes)
24
+ end
25
+
26
+ private
27
+
28
+ def roster_response_data(player_data)
29
+ @first_name = player_data["firstName"]
30
+ @last_name = player_data["lastName"]
31
+ @birth_date = Date.parse(player_data["birthDate"])
32
+ @nationality = player_data["nationality"]
33
+ @active = player_data["active"]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ module NHLStats
2
+ class Team
3
+ attr_reader :id, :name, :abbreviation
4
+
5
+ def initialize(team_data)
6
+ @id = team_data["id"]
7
+ @name = team_data["name"]
8
+ @abbreviation = team_data["abbreviation"]
9
+ end
10
+
11
+ def current_roster
12
+ response = Faraday.get("#{API_ROOT}/teams/#{id}/roster")
13
+ roster_response_to_players(response)
14
+ end
15
+
16
+ def roster_for_season(season)
17
+ response = Faraday.get("#{API_ROOT}/teams/#{id}/roster", :season => season)
18
+ roster_response_to_players(response)
19
+ end
20
+
21
+ def self.find(id)
22
+ response = Faraday.get("#{API_ROOT}/teams/#{id}")
23
+ attributes = JSON.parse(response.body).dig("teams", 0)
24
+ new(attributes)
25
+ end
26
+
27
+ def self.list(params = {})
28
+ response = Faraday.get("#{API_ROOT}/teams", params)
29
+ JSON.parse(response.body).
30
+ dig("teams").
31
+ map { |t| NHLStats::Team.new(t) }
32
+ end
33
+
34
+ private
35
+
36
+ def roster_response_to_players(response)
37
+ JSON.parse(response.body).fetch("roster", []).map do |p_data|
38
+ NHLStats::Player.new(p_data.delete("person").merge(p_data))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module NHLStats
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/nhl_stats.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "nhl_stats/version"
2
+ require "nhl_stats/game"
3
+ require "nhl_stats/player"
4
+ require "nhl_stats/team"
5
+
6
+ require "faraday"
7
+ require "json"
8
+ require "time"
9
+
10
+ API_ROOT = "https://statsapi.web.nhl.com/api/v1".freeze
11
+
12
+ module NHLStats
13
+ class Error < StandardError; end
14
+ end
data/nhl_stats.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "nhl_stats/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nhl_stats"
7
+ spec.version = NHLStats::VERSION
8
+ spec.authors = ["Susan Wright"]
9
+ spec.email = ["wright1@ualberta.ca"]
10
+
11
+ spec.summary = "Gem wrapping the undocumented NHL stats API"
12
+ spec.description = "Gem wrapping the undocumented NHL stats API"
13
+ spec.homepage = "https://shrugguy.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://shrugguy.com"
18
+ spec.metadata["changelog_uri"] = "https://shrugguy.com"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday", "~> 0.15.4"
30
+ spec.add_dependency "json", "~> 2.2.0"
31
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nhl_stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Susan Wright
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
41
+ description: Gem wrapping the undocumented NHL stats API
42
+ email:
43
+ - wright1@ualberta.ca
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - lib/nhl_stats.rb
61
+ - lib/nhl_stats/game.rb
62
+ - lib/nhl_stats/player.rb
63
+ - lib/nhl_stats/team.rb
64
+ - lib/nhl_stats/version.rb
65
+ - nhl_stats.gemspec
66
+ homepage: https://shrugguy.com
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ homepage_uri: https://shrugguy.com
71
+ source_code_uri: https://shrugguy.com
72
+ changelog_uri: https://shrugguy.com
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.0.4
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Gem wrapping the undocumented NHL stats API
92
+ test_files: []