stattleship-ruby 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16188346bbcd22a47c2e66791f883577317bbd71
4
- data.tar.gz: 8f979f332bf109ceecf7596f281b44762a9f8c5a
3
+ metadata.gz: 3bb7487a0e1804b8eaf3c6736232859281d72fc3
4
+ data.tar.gz: abfdaaedcb7d76cff31ca9e5ff6f39228039444a
5
5
  SHA512:
6
- metadata.gz: 9da199ee3bbca311f5a070e096731cba1ff48d16e741cfd6a30a349fdc2efba9117c1df47d058c442c32b119ac46efc3580c4bc0f1f3fc71dea19f2c658b0fb7
7
- data.tar.gz: 46637e178323c660829ffd79a0cd8627c68b3d3ee41514d1f3cf0c82964ece197e4851284772a5f1cea3beb60408bffdbb0af4407c5db49c9aedb114f14d9e8b
6
+ metadata.gz: 951516c77702fd612becdb85da904bfcb8b82fe4bf57c1c0b064db1e4c22b976620848ccaa9368f176ae29909256ba74ae4775faa71d8bab1506920023596cc0
7
+ data.tar.gz: c9ba9eff2c92bee84a9c610a02f96c1c74579d4dee93bc041073c54a9d75947836bf2f92d5f4769fcdd3834f1b331d9c62dd4ccf8a3c0d19277b172aa05a6c67
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.22
4
+
5
+ Populate season information on
6
+
7
+ * `StatLeadersParams`
8
+ * `TotalPlayerStatParams`
9
+ * `TotalTeamStatParams`
10
+
3
11
  ## 0.1.21
4
12
 
5
13
  ### Added
data/README.md CHANGED
@@ -22,7 +22,7 @@ gem install stattleship-ruby
22
22
  ## Usage
23
23
 
24
24
  ```
25
- gem 'stattleship-ruby', '~> 0.1.21'
25
+ gem 'stattleship-ruby', '~> 0.1.22'
26
26
  ```
27
27
 
28
28
  ### Build
@@ -34,7 +34,7 @@ gem build stattleship-ruby.gemspec
34
34
  ### Install
35
35
 
36
36
  ```
37
- gem install stattleship-ruby-0.1.21.gem
37
+ gem install stattleship-ruby-0.1.22.gem
38
38
  ```
39
39
  ## Prerequisites
40
40
 
@@ -0,0 +1,32 @@
1
+ # Set your STATTLESHIP_ACCESS_TOKEN from https://www.stattleship.com in the examples/.env file
2
+
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require File.join(dir, 'stattleship')
8
+ require 'pp'
9
+
10
+ # Construct params for the fetch
11
+ query_params = Stattleship::Params::FootballFeatsParams.new
12
+
13
+ query_params.season_id = 'nfl-2015-2016'
14
+
15
+ query_params.game_id = 'nfl-2015-2016-nyj-dal-2015-12-19-1925'
16
+ query_params.level_up = 2
17
+
18
+ # fetch will automatically traverse the paginated response links
19
+ feats = Stattleship::FootballFeats.fetch(params: query_params)
20
+
21
+ # the populated object
22
+ # pp feats.first
23
+
24
+ # can access friendly helpers
25
+ # pp feats.first.to_sentence
26
+
27
+ # "Cam Newton threw a 59 yard-long pass vs. the Packers on Sunday November 8, 2015 at 1:00pm"
28
+
29
+ # or, individual attributes
30
+ feats.each do |feat|
31
+ pp "#{feat.subject_name} (#{feat.team.name}) #{feat.actual.to_i} #{feat.humanized_stat_type} - Level #{feat.level}"
32
+ end
@@ -0,0 +1,26 @@
1
+ # Set your STATTLESHIP_ACCESS_TOKEN from https://www.stattleship.com in the examples/.env file
2
+
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require File.join(dir, 'stattleship')
8
+ require 'pp'
9
+
10
+ # Construct params for the fetch
11
+ query_params = Stattleship::Params::FootballScoringPlaysParams.new
12
+
13
+ # may need to adjust this depending on time of year
14
+ query_params.season_id = 'nfl-2015-2016'
15
+ query_params.game_id = 'nfl-2015-2016-nyj-dal-2015-12-19-1925'
16
+
17
+ # fetch will automatically traverse the paginated response links
18
+ scoring_plays = Stattleship::FootballScoringPlays.fetch(params: query_params)
19
+
20
+ # or, individual attributes
21
+ scoring_plays.each do |scoring_play|
22
+ # puts scoring_play.scoring_players.map(&:player).map(&:name)
23
+ # pp scoring_play.to_sentence if scoring_play.scoring_players.map(&:player).map(&:team_slug).include?('nfl-nyj')
24
+ puts scoring_play.to_sentence
25
+ end
26
+
@@ -1,13 +1,14 @@
1
1
  module Stattleship
2
2
  module Params
3
3
  class TotalTeamStatParams < Stattleship::Params::QueryParams
4
- attr_accessor :team_id, :stat
4
+ attr_accessor :interval_type, :team_id, :stat
5
5
  attr_reader :type
6
6
 
7
7
  private
8
8
 
9
9
  def params
10
10
  {
11
+ 'interval_type' => interval_type,
11
12
  'team_id' => team_id,
12
13
  'stat' => stat,
13
14
  'type' => type,
@@ -7,12 +7,18 @@ module Stattleship
7
7
  end
8
8
 
9
9
  def to_sentence
10
- "#{player.name} is in #{place.ordinalize} place with #{format_stat(stat)} #{stat_name}"
10
+ "#{player.name} is in #{place.ordinalize} place with #{format_stat(stat)} #{lowercase_stat}"
11
11
  end
12
12
 
13
13
  def format_stat(value)
14
14
  StatFormatter.stat(stat_name: stat_name, value: stat)
15
15
  end
16
+
17
+ def lowercase_stat
18
+ if humanized_stat
19
+ humanized_stat.downcase
20
+ end
21
+ end
16
22
  end
17
23
 
18
24
  class StatLeaders < Stattleship::Endpoint
@@ -20,6 +26,7 @@ module Stattleship
20
26
  stat_leaders.each do |leader|
21
27
  populate_players(leader)
22
28
  populate_player_teams(leader)
29
+ populate_season(leader)
23
30
  end
24
31
  end
25
32
  end
@@ -33,6 +40,10 @@ module Stattleship
33
40
  property :player_id
34
41
  property :stat, type: BigDecimal
35
42
  property :stat_name
43
+ property :season_id
44
+ property :humanized_stat
45
+ property :season_name
46
+ property :season_slug
36
47
  end
37
48
 
38
49
  collection :players, extend: Stattleship::Models::PlayerRepresenter,
@@ -1,7 +1,17 @@
1
1
  module Stattleship
2
2
  class TotalPlayerStat < Stattleship::Endpoint
3
3
  def to_sentence
4
- "#{player.name} has #{format_stat(total)} #{stat}"
4
+ if season_name.nil?
5
+ "#{player.name} has #{format_stat(total)} #{lowercase_stat}"
6
+ else
7
+ "#{player.name} had #{format_stat(total)} #{lowercase_stat} in the #{season_name} season"
8
+ end
9
+ end
10
+
11
+ def lowercase_stat
12
+ if humanized_stat
13
+ humanized_stat.downcase
14
+ end
5
15
  end
6
16
 
7
17
  def format_stat(value)
@@ -15,6 +25,7 @@ module Stattleship
15
25
  def populate
16
26
  populate_players(total_player_stat)
17
27
  populate_player_teams(total_player_stat)
28
+ populate_season(total_player_stat)
18
29
  total_player_stat
19
30
  end
20
31
  end
@@ -25,12 +36,20 @@ module Stattleship
25
36
 
26
37
  property :total_player_stat, class: Stattleship::TotalPlayerStat do
27
38
  property :player_id
39
+ property :season_id
40
+ property :interval_type
41
+ property :humanized_stat
42
+ property :season_name
43
+ property :since
28
44
  property :stat
29
45
  property :total, type: BigDecimal
46
+ property :week
30
47
  end
31
48
 
32
49
  collection :players, extend: Stattleship::Models::PlayerRepresenter,
33
50
  class: Stattleship::Models::Player
51
+ collection :seasons, extend: Stattleship::Models::SeasonRepresenter,
52
+ class: Stattleship::Models::Season
34
53
  collection :teams, extend: Stattleship::Models::TeamRepresenter,
35
54
  class: Stattleship::Models::Team
36
55
  end
@@ -1,7 +1,17 @@
1
1
  module Stattleship
2
2
  class TotalTeamStat < Stattleship::Endpoint
3
3
  def to_sentence
4
- "The #{team.full_name} have #{StatFormatter.stat(stat_name: stat, value: total)} #{stat}"
4
+ if season_name.nil?
5
+ "The #{team.full_name} have #{StatFormatter.stat(stat_name: stat, value: total)} #{lowercase_stat}"
6
+ else
7
+ "The #{team.full_name} had #{StatFormatter.stat(stat_name: stat, value: total)} #{lowercase_stat} in the #{season_name} season"
8
+ end
9
+ end
10
+
11
+ def lowercase_stat
12
+ if humanized_stat
13
+ humanized_stat.downcase
14
+ end
5
15
  end
6
16
 
7
17
  def self.fetch(path:, params:)
@@ -10,6 +20,8 @@ module Stattleship
10
20
 
11
21
  def populate
12
22
  populate_teams(total_team_stat)
23
+ populate_season(total_team_stat)
24
+
13
25
  total_team_stat
14
26
  end
15
27
  end
@@ -19,11 +31,20 @@ module Stattleship
19
31
  include Roar::Coercion
20
32
 
21
33
  property :total_team_stat, class: Stattleship::TotalTeamStat do
34
+ property :season_id
22
35
  property :team_id
23
36
  property :stat
37
+ property :interval_type
38
+ property :humanized_stat
39
+ property :season_name
40
+ property :since
24
41
  property :total, type: BigDecimal
42
+ property :week
25
43
  end
26
44
 
45
+ collection :seasons, extend: Stattleship::Models::SeasonRepresenter,
46
+ class: Stattleship::Models::Season
47
+
27
48
  collection :teams, extend: Stattleship::Models::TeamRepresenter,
28
49
  class: Stattleship::Models::Team
29
50
  end
@@ -1,5 +1,5 @@
1
1
  module Stattleship
2
2
  module Ruby
3
- VERSION = '0.1.21'.freeze
3
+ VERSION = '0.1.22'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stattleship-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stattleship
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-23 00:00:00.000000000 Z
12
+ date: 2016-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -256,6 +256,8 @@ files:
256
256
  - examples/bears_team_game_logs.rb
257
257
  - examples/football_feats.rb
258
258
  - examples/football_game_logs.rb
259
+ - examples/football_jets_v_cowboys_feats.rb
260
+ - examples/football_jets_v_cowboys_scoring_plays.rb
259
261
  - examples/football_players.rb
260
262
  - examples/football_stats.rb
261
263
  - examples/football_total_player_stat.rb