stattleship-ruby 0.1.25 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/examples/README.md +3 -1
- data/examples/at_bats.rb +25 -0
- data/examples/baseball_games.rb +2 -1
- data/examples/basketball_team_game_logs.rb +13 -6
- data/examples/line_ups.rb +21 -0
- data/examples/pitches.rb +26 -0
- data/lib/stattleship.rb +4 -0
- data/lib/stattleship/at_bats.rb +81 -0
- data/lib/stattleship/endpoint.rb +37 -0
- data/lib/stattleship/line_ups.rb +61 -0
- data/lib/stattleship/models.rb +4 -0
- data/lib/stattleship/models/at_bat.rb +51 -0
- data/lib/stattleship/models/line_up.rb +102 -0
- data/lib/stattleship/models/pitch.rb +369 -0
- data/lib/stattleship/models/player.rb +9 -1
- data/lib/stattleship/params.rb +4 -0
- data/lib/stattleship/params/at_bats_params.rb +23 -0
- data/lib/stattleship/params/line_ups_params.rb +18 -0
- data/lib/stattleship/params/pitches_params.rb +40 -0
- data/lib/stattleship/pitches.rb +70 -0
- data/lib/stattleship/validators.rb +14 -1
- data/lib/stattleship/validators/hit_location_validator.rb +9 -0
- data/lib/stattleship/validators/hit_type_validator.rb +9 -0
- data/lib/stattleship/validators/hitter_id_validator.rb +6 -0
- data/lib/stattleship/validators/inning_validator.rb +9 -0
- data/lib/stattleship/validators/lower_speed_validator.rb +9 -0
- data/lib/stattleship/validators/pitch_outcome_type_validator.rb +9 -0
- data/lib/stattleship/validators/pitch_type_validator.rb +9 -0
- data/lib/stattleship/validators/pitcher_id_validator.rb +6 -0
- data/lib/stattleship/validators/speed_and_over_validator.rb +9 -0
- data/lib/stattleship/validators/speed_and_under_validator.rb +9 -0
- data/lib/stattleship/validators/speed_validator.rb +10 -0
- data/lib/stattleship/validators/upper_speed_validator.rb +9 -0
- data/lib/stattleship/version.rb +1 -1
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf08d27f1671847b7e291b133334a1d5c5507214
|
4
|
+
data.tar.gz: 5974518881f4d88800e48d534962a7d83da92b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb0d73cb513109c77d66cc2403f7f657d73873b82069a01d8961dde5f6b52833e9c5acd2bec64a78e745e367fe2d818065ac4767e56c95db93a4953d8f09891
|
7
|
+
data.tar.gz: f515e94d71525cee607b59f0b1be0147dceb34fa0c5b723572947bc16849c49f38d132871854e759fe5a84a47b424ecc7a4c427f598775a476ef5e62df086412
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Check out the [Stattleship API](https://api.stattleship.com) - The Sports Data A
|
|
9
9
|
|
10
10
|
Meaningful. Developer-Friendly.
|
11
11
|
|
12
|
-
:football: :basketball: and :black_circle: :
|
12
|
+
:football: :basketball: and :black_circle: :black_circle: :snowflake: and :baseball: !
|
13
13
|
|
14
14
|
We're gonna need a bigger :boat:!
|
15
15
|
|
@@ -22,7 +22,7 @@ gem install stattleship-ruby
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
```
|
25
|
-
gem 'stattleship-ruby', '~> 0.1.
|
25
|
+
gem 'stattleship-ruby', '~> 0.1.25'
|
26
26
|
```
|
27
27
|
|
28
28
|
### Build
|
@@ -33,8 +33,8 @@ gem build stattleship-ruby.gemspec
|
|
33
33
|
|
34
34
|
### Install
|
35
35
|
|
36
|
-
```
|
37
|
-
gem install stattleship-ruby-0.1.
|
36
|
+
```rb
|
37
|
+
gem install stattleship-ruby-0.1.25.gem
|
38
38
|
```
|
39
39
|
## Prerequisites
|
40
40
|
|
@@ -46,7 +46,7 @@ You'll need
|
|
46
46
|
|
47
47
|
There are two ways to configure the gem.
|
48
48
|
|
49
|
-
```
|
49
|
+
```rb
|
50
50
|
Stattleship.configure do |config|
|
51
51
|
config.api_token = YOUR_TOKEN
|
52
52
|
end
|
@@ -74,7 +74,7 @@ It's dead simple.
|
|
74
74
|
|
75
75
|
The pattern is pretty much as follows:
|
76
76
|
|
77
|
-
```
|
77
|
+
```rb
|
78
78
|
query_params = Stattleship::Params::BasketballGameLogsParams.new
|
79
79
|
query_params.player_id = 'nba-stephen-curry'
|
80
80
|
query_params.since = '1 week ago'
|
data/examples/README.md
CHANGED
@@ -30,6 +30,8 @@ You'll need
|
|
30
30
|
|
31
31
|
* Stattleship API Access Token from https://www.stattleship.com
|
32
32
|
* Set that in your `.env` file as `STATTLESHIP_ACCESS_TOKEN=your_token`
|
33
|
+
* To build the gem: `gem build stattleship-ruby.gemspec`
|
34
|
+
* To install the gem (with the current version of the gem file): `gem install stattleship-ruby-0.1.xx.gem`
|
33
35
|
* To run examples, that .env file should be in the `/examples` dir.
|
34
36
|
* Copy the `sample.env` file, insert your token and save as `examples/.env`
|
35
37
|
* The `cd` to the `/examples` directory and `ruby <example>.rb` such that the .env loads
|
@@ -64,7 +66,7 @@ You'll need
|
|
64
66
|
|
65
67
|
* [Football Players](football_players.rb)
|
66
68
|
* Uses `FootballPlayersParams` and makes a `FootballPlayers` request
|
67
|
-
* Uses `team_id`
|
69
|
+
* Uses `team_id` parameters to return Denver Broncos players
|
68
70
|
* Demonstrates ability to filter and sort on a numeric `salary` to get list of players making more than $5M and where they went to `school`
|
69
71
|
|
70
72
|
* [Hockey Scoring Plays](hockey_scoring_plays.rb)
|
data/examples/at_bats.rb
ADDED
@@ -0,0 +1,25 @@
|
|
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::AtBatsParams.new
|
12
|
+
|
13
|
+
query_params.season_id = 'mlb-2016'
|
14
|
+
query_params.interval_type = 'regularseason'
|
15
|
+
query_params.hitter_id = 'mlb-mike-trout'
|
16
|
+
query_params.hit_type = 'GB'
|
17
|
+
|
18
|
+
# fetch will automatically traverse the paginated response links
|
19
|
+
at_bats = Stattleship::AtBats.fetch(params: query_params)
|
20
|
+
|
21
|
+
pp at_bats.map(&:to_sentence)
|
22
|
+
|
23
|
+
at_bats.each do |at_bat|
|
24
|
+
pp at_bat.pitches.map(&:to_sentence)
|
25
|
+
end
|
data/examples/baseball_games.rb
CHANGED
@@ -16,6 +16,7 @@ query_params.team_id = 'mlb-bos'
|
|
16
16
|
# may need to adjust this depending on time of year
|
17
17
|
query_params.season_id = 'mlb-2016'
|
18
18
|
query_params.status = 'upcoming'
|
19
|
+
query_params.on = 'today'
|
19
20
|
|
20
21
|
# fetch will automatically traverse the paginated response links
|
21
22
|
games = Stattleship::BaseballGames.fetch(params: query_params)
|
@@ -28,5 +29,5 @@ pp games.first.started_at.strftime('%b %e, %l:%M %p')
|
|
28
29
|
|
29
30
|
# or, individual attributes
|
30
31
|
games.each do |game|
|
31
|
-
pp game.
|
32
|
+
pp game.label
|
32
33
|
end
|
@@ -11,26 +11,33 @@ require 'pp'
|
|
11
11
|
query_params = Stattleship::Params::BasketballTeamGameLogsParams.new
|
12
12
|
|
13
13
|
# use a slug, typically 'league-team_abbreviation'
|
14
|
+
query_params.season_id = 'nba-2016-2017'
|
15
|
+
query_params.interval_type = 'regularseason'
|
14
16
|
query_params.team_id = 'nba-cle'
|
15
17
|
|
16
18
|
# may need to adjust this depending on time of year/NBA season
|
17
|
-
query_params.since = '1
|
19
|
+
# query_params.since = '1 month ago'
|
18
20
|
|
19
21
|
# fetch will automatically traverse the paginated response links
|
20
22
|
game_logs = Stattleship::BasketballTeamGameLogs.fetch(params: query_params)
|
21
23
|
|
22
24
|
# the populated object
|
23
|
-
pp game_logs.first
|
25
|
+
# pp game_logs.first
|
24
26
|
|
25
27
|
# can access friendly helpers
|
26
|
-
pp game_logs.first.to_sentence
|
28
|
+
# pp game_logs.first.to_sentence
|
27
29
|
|
28
30
|
# "Cleveland 42 FGM, 50.6 FG%, 115 PTS, 33 DRB, 14 ORB, 47 REB (Clippers vs Cavaliers January 21, 2016 at 8:00pm)"
|
29
31
|
|
30
32
|
# or, individual attributes
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
|
34
|
+
scores = game_logs.map(&:team_score)
|
35
|
+
|
36
|
+
pp scores
|
37
|
+
|
38
|
+
# game_logs.each do |game_log|
|
39
|
+
# pp game_log.to_sentence
|
40
|
+
# end
|
34
41
|
|
35
42
|
# 13
|
36
43
|
# 11
|
@@ -0,0 +1,21 @@
|
|
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::LineUpsParams.new
|
12
|
+
|
13
|
+
query_params.season_id = 'mlb-2017'
|
14
|
+
query_params.interval_type = 'preseason'
|
15
|
+
query_params.since = '1 week ago'
|
16
|
+
query_params.team_id = 'mlb-bos'
|
17
|
+
|
18
|
+
# fetch will automatically traverse the paginated response links
|
19
|
+
line_ups = Stattleship::LineUps.fetch(params: query_params)
|
20
|
+
|
21
|
+
pp line_ups.map(&:to_sentence)
|
data/examples/pitches.rb
ADDED
@@ -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::PitchesParams.new
|
12
|
+
|
13
|
+
query_params.season_id = 'mlb-2017'
|
14
|
+
query_params.interval_type = 'preseason'
|
15
|
+
query_params.game_id = 'mlb-2017-cin-kc-2017-03-20-1605'
|
16
|
+
|
17
|
+
|
18
|
+
# query_params.pitch_outcome_type = 'aHR'
|
19
|
+
# query_params.inning = 9
|
20
|
+
# query_params.speed_and_over = 103
|
21
|
+
# query_params.pitcher_id = 'mlb-aroldis-chapman'
|
22
|
+
|
23
|
+
# fetch will automatically traverse the paginated response links
|
24
|
+
pitches = Stattleship::Pitches.fetch(params: query_params)
|
25
|
+
|
26
|
+
pp pitches.map(&:to_sentence)
|
data/lib/stattleship.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Stattleship
|
2
|
+
class AtBats < Stattleship::Endpoint
|
3
|
+
AT_BATS = 'baseball/mlb/at_bats'.freeze
|
4
|
+
|
5
|
+
def self.fetch(params:)
|
6
|
+
super(path: AT_BATS,
|
7
|
+
params: params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def populate
|
11
|
+
at_bats.each do |model|
|
12
|
+
populate_games(model)
|
13
|
+
|
14
|
+
games.each do |game|
|
15
|
+
populate_game(game)
|
16
|
+
end
|
17
|
+
|
18
|
+
populate_hitters(model)
|
19
|
+
populate_hitter_teams(model)
|
20
|
+
|
21
|
+
(baseball_pitches || []).each do |pitch|
|
22
|
+
populate_pitchers(pitch)
|
23
|
+
populate_hitters(pitch)
|
24
|
+
populate_teams(pitch)
|
25
|
+
populate_hitter_teams(pitch)
|
26
|
+
end
|
27
|
+
|
28
|
+
populate_baseball_pitches(model)
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module AtBatsRepresenter
|
35
|
+
include Roar::JSON
|
36
|
+
include Stattleship::Models
|
37
|
+
|
38
|
+
collection :away_teams, extend: TeamRepresenter,
|
39
|
+
class: Team
|
40
|
+
|
41
|
+
collection :hitters, extend: PlayerRepresenter,
|
42
|
+
class: Player
|
43
|
+
|
44
|
+
collection :hitter_teams, extend: TeamRepresenter,
|
45
|
+
class: Team
|
46
|
+
|
47
|
+
collection :pitchers, extend: PlayerRepresenter,
|
48
|
+
class: Player
|
49
|
+
|
50
|
+
collection :home_teams, extend: TeamRepresenter,
|
51
|
+
class: Team
|
52
|
+
|
53
|
+
collection :winning_teams, extend: TeamRepresenter,
|
54
|
+
class: Team
|
55
|
+
|
56
|
+
collection :games, extend: GameRepresenter,
|
57
|
+
class: Game
|
58
|
+
|
59
|
+
collection :leagues, extend: LeagueRepresenter,
|
60
|
+
class: League
|
61
|
+
|
62
|
+
collection :officials, extend: OfficialRepresenter,
|
63
|
+
class: Official
|
64
|
+
|
65
|
+
collection :seasons, extend: SeasonRepresenter,
|
66
|
+
class: Season
|
67
|
+
|
68
|
+
collection :venues, extend: VenueRepresenter,
|
69
|
+
class: Venue
|
70
|
+
|
71
|
+
|
72
|
+
collection :teams, extend: TeamRepresenter,
|
73
|
+
class: Team
|
74
|
+
|
75
|
+
collection :baseball_pitches, extend: PitchRepresenter,
|
76
|
+
class: Pitch
|
77
|
+
|
78
|
+
collection :at_bats, extend: AtBatRepresenter,
|
79
|
+
class: AtBat
|
80
|
+
end
|
81
|
+
end
|
data/lib/stattleship/endpoint.rb
CHANGED
@@ -16,6 +16,19 @@ module Stattleship
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
+
def populate_baseball_pitches(model)
|
20
|
+
model.pitches = []
|
21
|
+
|
22
|
+
return if model.baseball_pitch_ids.nil?
|
23
|
+
return if baseball_pitches.nil?
|
24
|
+
|
25
|
+
model.baseball_pitch_ids.each do |baseball_pitch_id|
|
26
|
+
model.pitches << baseball_pitches.detect do |baseball_pitch|
|
27
|
+
baseball_pitch.id == baseball_pitch_id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
def populate_officials(model)
|
20
33
|
model.officials = []
|
21
34
|
|
@@ -37,6 +50,22 @@ module Stattleship
|
|
37
50
|
end
|
38
51
|
end
|
39
52
|
|
53
|
+
def populate_pitchers(model)
|
54
|
+
return if pitchers.nil?
|
55
|
+
|
56
|
+
model.pitcher = pitchers.detect do |pitcher|
|
57
|
+
pitcher.id == model.pitcher_id
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def populate_hitters(model)
|
62
|
+
return if hitters.nil?
|
63
|
+
|
64
|
+
model.hitter = hitters.detect do |hitter|
|
65
|
+
hitter.id == model.hitter_id
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
40
69
|
def populate_players(model)
|
41
70
|
return if players.nil?
|
42
71
|
|
@@ -179,6 +208,14 @@ module Stattleship
|
|
179
208
|
end
|
180
209
|
end
|
181
210
|
|
211
|
+
def populate_hitter_teams(model)
|
212
|
+
return if hitter_teams.nil?
|
213
|
+
|
214
|
+
model.hitter_team = hitter_teams.detect do |hitter_team|
|
215
|
+
hitter_team.id == model.hitter_team_id
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
182
219
|
def populate_venue(model)
|
183
220
|
return if venues.nil?
|
184
221
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Stattleship
|
2
|
+
class LineUps < Stattleship::Endpoint
|
3
|
+
LINE_UPS = 'baseball/mlb/lineups'.freeze
|
4
|
+
|
5
|
+
def self.fetch(params:)
|
6
|
+
super(path: LINE_UPS,
|
7
|
+
params: params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def populate
|
11
|
+
lineups.each do |model|
|
12
|
+
populate_games(model)
|
13
|
+
|
14
|
+
games.each do |game|
|
15
|
+
populate_game(game)
|
16
|
+
end
|
17
|
+
|
18
|
+
populate_players(model)
|
19
|
+
populate_teams(model)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module LineUpsRepresenter
|
25
|
+
include Roar::JSON
|
26
|
+
include Stattleship::Models
|
27
|
+
|
28
|
+
collection :away_teams, extend: TeamRepresenter,
|
29
|
+
class: Team
|
30
|
+
|
31
|
+
collection :home_teams, extend: TeamRepresenter,
|
32
|
+
class: Team
|
33
|
+
|
34
|
+
collection :winning_teams, extend: TeamRepresenter,
|
35
|
+
class: Team
|
36
|
+
|
37
|
+
collection :games, extend: GameRepresenter,
|
38
|
+
class: Game
|
39
|
+
|
40
|
+
collection :leagues, extend: LeagueRepresenter,
|
41
|
+
class: League
|
42
|
+
|
43
|
+
collection :officials, extend: OfficialRepresenter,
|
44
|
+
class: Official
|
45
|
+
|
46
|
+
collection :seasons, extend: SeasonRepresenter,
|
47
|
+
class: Season
|
48
|
+
|
49
|
+
collection :venues, extend: VenueRepresenter,
|
50
|
+
class: Venue
|
51
|
+
|
52
|
+
collection :teams, extend: TeamRepresenter,
|
53
|
+
class: Team
|
54
|
+
|
55
|
+
collection :players, extend: PlayerRepresenter,
|
56
|
+
class: Player
|
57
|
+
|
58
|
+
collection :lineups, extend: LineUpRepresenter,
|
59
|
+
class: LineUp
|
60
|
+
end
|
61
|
+
end
|
data/lib/stattleship/models.rb
CHANGED
@@ -13,6 +13,10 @@ require 'stattleship/models/team_outcome_streak'
|
|
13
13
|
require 'stattleship/models/venue'
|
14
14
|
require 'stattleship/models/ranking'
|
15
15
|
|
16
|
+
require 'stattleship/models/at_bat'
|
17
|
+
require 'stattleship/models/line_up'
|
18
|
+
require 'stattleship/models/pitch'
|
19
|
+
|
16
20
|
module Stattleship
|
17
21
|
module Models
|
18
22
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Stattleship
|
2
|
+
module Models
|
3
|
+
class AtBat < OpenStruct
|
4
|
+
def to_sentence
|
5
|
+
description
|
6
|
+
end
|
7
|
+
|
8
|
+
def dump
|
9
|
+
{
|
10
|
+
id: id,
|
11
|
+
description: description,
|
12
|
+
inning: inning,
|
13
|
+
inning_label: inning_label,
|
14
|
+
half: half,
|
15
|
+
baseball_pitch_ids: baseball_pitch_ids,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module AtBatRepresenter
|
21
|
+
include Roar::JSON
|
22
|
+
include Roar::Coercion
|
23
|
+
include Virtus.model
|
24
|
+
|
25
|
+
[
|
26
|
+
:id,
|
27
|
+
:description,
|
28
|
+
:inning_label,
|
29
|
+
:half,
|
30
|
+
].each do |attribute|
|
31
|
+
property attribute
|
32
|
+
end
|
33
|
+
|
34
|
+
[
|
35
|
+
:inning,
|
36
|
+
].each do |attribute|
|
37
|
+
property attribute, type: Integer
|
38
|
+
end
|
39
|
+
|
40
|
+
[
|
41
|
+
:game_id,
|
42
|
+
:hitter_id,
|
43
|
+
:hitter_team_id,
|
44
|
+
].each do |relationship|
|
45
|
+
property relationship
|
46
|
+
end
|
47
|
+
|
48
|
+
collection :baseball_pitch_ids
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|