mlb 0.8.0 → 0.10.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/CHANGELOG.md +10 -1
- data/LICENSE.txt +1 -1
- data/README.md +109 -35
- data/lib/mlb/award.rb +48 -0
- data/lib/mlb/awards.rb +22 -0
- data/lib/mlb/client.rb +14 -25
- data/lib/mlb/conference.rb +32 -0
- data/lib/mlb/conferences.rb +25 -0
- data/lib/mlb/connection.rb +1 -1
- data/lib/mlb/division.rb +44 -0
- data/lib/mlb/divisions.rb +30 -0
- data/lib/mlb/{response_parser.rb → error_handler.rb} +3 -11
- data/lib/mlb/handedness.rb +16 -0
- data/lib/mlb/league.rb +68 -0
- data/lib/mlb/leagues.rb +30 -0
- data/lib/mlb/player.rb +68 -17
- data/lib/mlb/players.rb +45 -0
- data/lib/mlb/position.rb +20 -0
- data/lib/mlb/redirect_handler.rb +1 -1
- data/lib/mlb/roster.rb +22 -0
- data/lib/mlb/roster_entry.rb +25 -0
- data/lib/mlb/season.rb +63 -0
- data/lib/mlb/season_date_info.rb +52 -0
- data/lib/mlb/seasons.rb +30 -0
- data/lib/mlb/sky.rb +11 -0
- data/lib/mlb/sport.rb +33 -0
- data/lib/mlb/sports.rb +22 -0
- data/lib/mlb/status.rb +11 -0
- data/lib/mlb/team.rb +60 -29
- data/lib/mlb/teams.rb +30 -0
- data/lib/mlb/transaction.rb +27 -30
- data/lib/mlb/transactions.rb +18 -0
- data/lib/mlb/venue.rb +16 -0
- data/lib/mlb/venues.rb +30 -0
- data/lib/mlb/version.rb +1 -1
- data/lib/mlb/wind_direction.rb +11 -0
- data/lib/mlb.rb +11 -2
- metadata +65 -16
- data/sig/mlb.rbs +0 -191
data/lib/mlb/player.rb
CHANGED
@@ -1,21 +1,72 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
require_relative "position"
|
4
|
+
require_relative "handedness"
|
5
|
+
require_relative "team"
|
6
|
+
|
1
7
|
module MLB
|
2
|
-
Player
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
class Player < Shale::Mapper
|
9
|
+
include Equalizer.new(:id)
|
10
|
+
|
11
|
+
attribute :id, Shale::Type::Integer
|
12
|
+
attribute :full_name, Shale::Type::String
|
13
|
+
attribute :link, Shale::Type::String
|
14
|
+
attribute :first_name, Shale::Type::String
|
15
|
+
attribute :last_name, Shale::Type::String
|
16
|
+
attribute :primary_number, Shale::Type::Integer
|
17
|
+
attribute :birth_date, Shale::Type::Date
|
18
|
+
attribute :current_age, Shale::Type::Integer
|
19
|
+
attribute :birth_city, Shale::Type::String
|
20
|
+
attribute :birth_state_province, Shale::Type::String
|
21
|
+
attribute :birth_country, Shale::Type::String
|
22
|
+
attribute :height, Shale::Type::String
|
23
|
+
attribute :weight, Shale::Type::Integer
|
24
|
+
attribute :active, Shale::Type::Boolean
|
25
|
+
attribute :current_team, Team
|
26
|
+
attribute :primary_position, Position
|
27
|
+
attribute :use_name, Shale::Type::String
|
28
|
+
attribute :middle_name, Shale::Type::String
|
29
|
+
attribute :boxscore_name, Shale::Type::String
|
30
|
+
attribute :gender, Shale::Type::String
|
31
|
+
attribute :is_player, Shale::Type::Boolean
|
32
|
+
attribute :is_verified, Shale::Type::Boolean
|
33
|
+
attribute :draft_year, Shale::Type::Integer
|
34
|
+
attribute :mlb_debut_date, Shale::Type::Date
|
35
|
+
attribute :bat_side, Handedness
|
36
|
+
attribute :pitch_hand, Handedness
|
37
|
+
|
38
|
+
alias_method :verified?, :is_verified
|
39
|
+
alias_method :player?, :is_player
|
40
|
+
alias_method :active?, :active
|
41
|
+
|
42
|
+
json do
|
43
|
+
map "id", to: :id
|
44
|
+
map "fullName", to: :full_name
|
45
|
+
map "nameFirstLast", to: :full_name
|
46
|
+
map "link", to: :link
|
47
|
+
map "firstName", to: :first_name
|
48
|
+
map "lastName", to: :last_name
|
49
|
+
map "primaryNumber", to: :primary_number
|
50
|
+
map "birthDate", to: :birth_date
|
51
|
+
map "currentAge", to: :current_age
|
52
|
+
map "birthCity", to: :birth_city
|
53
|
+
map "birthStateProvince", to: :birth_state_province
|
54
|
+
map "birthCountry", to: :birth_country
|
55
|
+
map "height", to: :height
|
56
|
+
map "weight", to: :weight
|
57
|
+
map "active", to: :active
|
58
|
+
map "currentTeam", to: :current_team
|
59
|
+
map "primaryPosition", to: :primary_position
|
60
|
+
map "useName", to: :use_name
|
61
|
+
map "middleName", to: :middle_name
|
62
|
+
map "boxscoreName", to: :boxscore_name
|
63
|
+
map "gender", to: :gender
|
64
|
+
map "isPlayer", to: :is_player
|
65
|
+
map "isVerified", to: :is_verified
|
66
|
+
map "draftYear", to: :draft_year
|
67
|
+
map "mlbDebutDate", to: :mlb_debut_date
|
68
|
+
map "batSide", to: :bat_side
|
69
|
+
map "pitchHand", to: :pitch_hand
|
19
70
|
end
|
20
71
|
end
|
21
72
|
end
|
data/lib/mlb/players.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "sport"
|
4
|
+
require_relative "player"
|
5
|
+
|
6
|
+
module MLB
|
7
|
+
class Players < Shale::Mapper
|
8
|
+
attribute :copyright, Shale::Type::String
|
9
|
+
attribute :players, Player, collection: true
|
10
|
+
|
11
|
+
json do
|
12
|
+
map "copyright", to: :copyright
|
13
|
+
map "people", to: :players
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all(season: Time.now.year, sport: Sport.new(id: 1))
|
17
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
18
|
+
params = {season:}
|
19
|
+
query_string = URI.encode_www_form(params)
|
20
|
+
response = CLIENT.get("sports/#{sport_id}/players?#{query_string}")
|
21
|
+
players = from_json(response)
|
22
|
+
players.players
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find(player)
|
26
|
+
player_id = player.respond_to?(:id) ? player.id : player
|
27
|
+
params = {personIds: player_id}
|
28
|
+
query_string = URI.encode_www_form(params)
|
29
|
+
response = CLIENT.get("people?#{query_string}")
|
30
|
+
players = from_json(response)
|
31
|
+
players.players.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.find_all(*players)
|
35
|
+
return all if players.empty?
|
36
|
+
|
37
|
+
player_ids = players.map { |player| player.respond_to?(:id) ? player.id : player }.join(",")
|
38
|
+
params = {personIds: player_ids}
|
39
|
+
query_string = URI.encode_www_form(params)
|
40
|
+
response = CLIENT.get("people?#{query_string}")
|
41
|
+
players = from_json(response)
|
42
|
+
players.players
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/mlb/position.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
|
4
|
+
module MLB
|
5
|
+
class Position < Shale::Mapper
|
6
|
+
include Equalizer.new(:code)
|
7
|
+
|
8
|
+
attribute :code, Shale::Type::String
|
9
|
+
attribute :name, Shale::Type::String
|
10
|
+
attribute :type, Shale::Type::String
|
11
|
+
attribute :abbreviation, Shale::Type::String
|
12
|
+
|
13
|
+
json do
|
14
|
+
map "code", to: :code
|
15
|
+
map "name", to: :name
|
16
|
+
map "type", to: :type
|
17
|
+
map "abbreviation", to: :abbreviation
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/mlb/redirect_handler.rb
CHANGED
data/lib/mlb/roster.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "roster_entry"
|
4
|
+
require_relative "sport"
|
5
|
+
require_relative "team"
|
6
|
+
|
7
|
+
module MLB
|
8
|
+
class Roster < Shale::Mapper
|
9
|
+
attribute :copyright, Shale::Type::String
|
10
|
+
attribute :roster, RosterEntry, collection: true
|
11
|
+
|
12
|
+
def self.find(team:, season: Time.now.year, sport: Sport.new(id: 1))
|
13
|
+
team_id = team.respond_to?(:id) ? team.id : team
|
14
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
15
|
+
params = {season:, sportId: sport_id}
|
16
|
+
query_string = URI.encode_www_form(params)
|
17
|
+
response = CLIENT.get("teams/#{team_id}/roster?#{query_string}")
|
18
|
+
roster = from_json(response)
|
19
|
+
roster.roster
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
require_relative "player"
|
4
|
+
require_relative "position"
|
5
|
+
require_relative "status"
|
6
|
+
|
7
|
+
module MLB
|
8
|
+
class RosterEntry < Shale::Mapper
|
9
|
+
include Equalizer.new(:team_id, :player)
|
10
|
+
|
11
|
+
attribute :player, Player
|
12
|
+
attribute :jersey_number, Shale::Type::Integer
|
13
|
+
attribute :position, Position
|
14
|
+
attribute :status, Status
|
15
|
+
attribute :team_id, Shale::Type::Integer
|
16
|
+
|
17
|
+
json do
|
18
|
+
map "person", to: :player
|
19
|
+
map "jerseyNumber", to: :jersey_number
|
20
|
+
map "position", to: :position
|
21
|
+
map "status", to: :status
|
22
|
+
map "parentTeamId", to: :team_id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mlb/season.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
require_relative "league"
|
4
|
+
require_relative "sport"
|
5
|
+
|
6
|
+
module MLB
|
7
|
+
class Season < Shale::Mapper
|
8
|
+
include Comparable
|
9
|
+
include Equalizer.new(:id)
|
10
|
+
|
11
|
+
attribute :id, Shale::Type::Integer
|
12
|
+
attribute :has_wildcard, Shale::Type::Boolean
|
13
|
+
attribute :preseason_start_date, Shale::Type::Date
|
14
|
+
attribute :preseason_end_date, Shale::Type::Date
|
15
|
+
attribute :season_start_date, Shale::Type::Date
|
16
|
+
attribute :spring_start_date, Shale::Type::Date
|
17
|
+
attribute :spring_end_date, Shale::Type::Date
|
18
|
+
attribute :regular_season_start_date, Shale::Type::Date
|
19
|
+
attribute :last_date_first_half, Shale::Type::Date
|
20
|
+
attribute :all_star_date, Shale::Type::Date
|
21
|
+
attribute :first_date_second_half, Shale::Type::Date
|
22
|
+
attribute :regular_season_end_date, Shale::Type::Date
|
23
|
+
attribute :postseason_start_date, Shale::Type::Date
|
24
|
+
attribute :postseason_end_date, Shale::Type::Date
|
25
|
+
attribute :season_end_date, Shale::Type::Date
|
26
|
+
attribute :offseason_start_date, Shale::Type::Date
|
27
|
+
attribute :offseason_end_date, Shale::Type::Date
|
28
|
+
attribute :season_level_gameday_type, Shale::Type::String
|
29
|
+
attribute :game_level_gameday_type, Shale::Type::String
|
30
|
+
attribute :qualifier_plate_appearances, Shale::Type::Float
|
31
|
+
attribute :qualifier_outs_pitched, Shale::Type::Float
|
32
|
+
|
33
|
+
alias_method :wildcard?, :has_wildcard
|
34
|
+
|
35
|
+
json do
|
36
|
+
map "seasonId", to: :id
|
37
|
+
map "hasWildcard", to: :has_wildcard
|
38
|
+
map "preSeasonStartDate", to: :preseason_start_date
|
39
|
+
map "preSeasonEndDate", to: :preseason_end_date
|
40
|
+
map "seasonStartDate", to: :season_start_date
|
41
|
+
map "springStartDate", to: :spring_start_date
|
42
|
+
map "springEndDate", to: :spring_end_date
|
43
|
+
map "regularSeasonStartDate", to: :regular_season_start_date
|
44
|
+
map "lastDate1stHalf", to: :last_date_first_half
|
45
|
+
map "allStarDate", to: :all_star_date
|
46
|
+
map "firstDate2ndHalf", to: :first_date_second_half
|
47
|
+
map "regularSeasonEndDate", to: :regular_season_end_date
|
48
|
+
map "postSeasonStartDate", to: :postseason_start_date
|
49
|
+
map "postSeasonEndDate", to: :postseason_end_date
|
50
|
+
map "seasonEndDate", to: :season_end_date
|
51
|
+
map "offseasonStartDate", to: :offseason_start_date
|
52
|
+
map "offSeasonEndDate", to: :offseason_end_date
|
53
|
+
map "seasonLevelGamedayType", to: :season_level_gameday_type
|
54
|
+
map "gameLevelGamedayType", to: :game_level_gameday_type
|
55
|
+
map "qualifierPlateAppearances", to: :qualifier_plate_appearances
|
56
|
+
map "qualifierOutsPitched", to: :qualifier_outs_pitched
|
57
|
+
end
|
58
|
+
|
59
|
+
def <=>(other)
|
60
|
+
id <=> other.id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
|
4
|
+
module MLB
|
5
|
+
class SeasonDateInfo < Shale::Mapper
|
6
|
+
include Equalizer.new(:season_id)
|
7
|
+
|
8
|
+
attribute :season_id, Shale::Type::String
|
9
|
+
attribute :pre_season_start_date, Shale::Type::Date
|
10
|
+
attribute :pre_season_end_date, Shale::Type::Date
|
11
|
+
attribute :season_start_date, Shale::Type::Date
|
12
|
+
attribute :spring_start_date, Shale::Type::Date
|
13
|
+
attribute :spring_end_date, Shale::Type::Date
|
14
|
+
attribute :regular_season_start_date, Shale::Type::Date
|
15
|
+
attribute :last_date_1st_half, Shale::Type::Date
|
16
|
+
attribute :all_star_date, Shale::Type::Date
|
17
|
+
attribute :first_date_2nd_half, Shale::Type::Date
|
18
|
+
attribute :regular_season_end_date, Shale::Type::Date
|
19
|
+
attribute :post_season_start_date, Shale::Type::Date
|
20
|
+
attribute :post_season_end_date, Shale::Type::Date
|
21
|
+
attribute :season_end_date, Shale::Type::Date
|
22
|
+
attribute :offseason_start_date, Shale::Type::Date
|
23
|
+
attribute :off_season_end_date, Shale::Type::Date
|
24
|
+
attribute :season_level_gameday_type, Shale::Type::String
|
25
|
+
attribute :game_level_gameday_type, Shale::Type::String
|
26
|
+
attribute :qualifier_plate_appearances, Shale::Type::Float
|
27
|
+
attribute :qualifier_outs_pitched, Shale::Type::Float
|
28
|
+
|
29
|
+
json do
|
30
|
+
map "seasonId", to: :season_id
|
31
|
+
map "preSeasonStartDate", to: :pre_season_start_date
|
32
|
+
map "preSeasonEndDate", to: :pre_season_end_date
|
33
|
+
map "seasonStartDate", to: :season_start_date
|
34
|
+
map "springStartDate", to: :spring_start_date
|
35
|
+
map "springEndDate", to: :spring_end_date
|
36
|
+
map "regularSeasonStartDate", to: :regular_season_start_date
|
37
|
+
map "lastDate1stHalf", to: :last_date_1st_half
|
38
|
+
map "allStarDate", to: :all_star_date
|
39
|
+
map "firstDate2ndHalf", to: :first_date_2nd_half
|
40
|
+
map "regularSeasonEndDate", to: :regular_season_end_date
|
41
|
+
map "postSeasonStartDate", to: :post_season_start_date
|
42
|
+
map "postSeasonEndDate", to: :post_season_end_date
|
43
|
+
map "seasonEndDate", to: :season_end_date
|
44
|
+
map "offseasonStartDate", to: :offseason_start_date
|
45
|
+
map "offSeasonEndDate", to: :off_season_end_date
|
46
|
+
map "seasonLevelGamedayType", to: :season_level_gameday_type
|
47
|
+
map "gameLevelGamedayType", to: :game_level_gameday_type
|
48
|
+
map "qualifierPlateAppearances", to: :qualifier_plate_appearances
|
49
|
+
map "qualifierOutsPitched", to: :qualifier_outs_pitched
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/mlb/seasons.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "sport"
|
4
|
+
require_relative "season"
|
5
|
+
|
6
|
+
module MLB
|
7
|
+
class Seasons < Shale::Mapper
|
8
|
+
attribute :copyright, Shale::Type::String
|
9
|
+
attribute :seasons, Season, collection: true
|
10
|
+
|
11
|
+
def self.all(sport: Sport.new(id: 1))
|
12
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
13
|
+
params = {sportId: sport_id}
|
14
|
+
query_string = URI.encode_www_form(params)
|
15
|
+
response = CLIENT.get("seasons?#{query_string}")
|
16
|
+
seasons = from_json(response)
|
17
|
+
seasons.seasons.sort!
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(season, sport: Sport.new(id: 1))
|
21
|
+
id = season.respond_to?(:id) ? season.id : season
|
22
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
23
|
+
params = {sportId: sport_id}
|
24
|
+
query_string = URI.encode_www_form(params)
|
25
|
+
response = CLIENT.get("seasons/#{id}?#{query_string}")
|
26
|
+
seasons = from_json(response)
|
27
|
+
seasons.seasons.sort!.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/mlb/sky.rb
ADDED
data/lib/mlb/sport.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
|
4
|
+
module MLB
|
5
|
+
class Sport < Shale::Mapper
|
6
|
+
include Comparable
|
7
|
+
include Equalizer.new(:id)
|
8
|
+
|
9
|
+
attribute :id, Shale::Type::Integer
|
10
|
+
attribute :code, Shale::Type::String
|
11
|
+
attribute :link, Shale::Type::String
|
12
|
+
attribute :name, Shale::Type::String
|
13
|
+
attribute :abbreviation, Shale::Type::String
|
14
|
+
attribute :sort_order, Shale::Type::Integer
|
15
|
+
attribute :active, Shale::Type::Boolean
|
16
|
+
|
17
|
+
alias_method :active?, :active
|
18
|
+
|
19
|
+
json do
|
20
|
+
map "id", to: :id
|
21
|
+
map "code", to: :code
|
22
|
+
map "link", to: :link
|
23
|
+
map "name", to: :name
|
24
|
+
map "abbreviation", to: :abbreviation
|
25
|
+
map "sortOrder", to: :sort_order
|
26
|
+
map "activeStatus", to: :active
|
27
|
+
end
|
28
|
+
|
29
|
+
def <=>(other)
|
30
|
+
sort_order <=> other.sort_order
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/mlb/sports.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "shale"
|
2
|
+
require_relative "sport"
|
3
|
+
|
4
|
+
module MLB
|
5
|
+
class Sports < Shale::Mapper
|
6
|
+
attribute :copyright, Shale::Type::String
|
7
|
+
attribute :sports, Sport, collection: true
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
response = CLIENT.get("sports")
|
11
|
+
sports = from_json(response)
|
12
|
+
sports.sports.sort!
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(sport)
|
16
|
+
id = sport.respond_to?(:id) ? sport.id : sport
|
17
|
+
response = CLIENT.get("sports/#{id}")
|
18
|
+
sports = from_json(response)
|
19
|
+
sports.sports.sort!.first
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/mlb/status.rb
ADDED
data/lib/mlb/team.rb
CHANGED
@@ -1,38 +1,69 @@
|
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
1
3
|
require "uri"
|
4
|
+
require_relative "division"
|
5
|
+
require_relative "league"
|
6
|
+
require_relative "sport"
|
7
|
+
require_relative "venue"
|
2
8
|
|
3
9
|
module MLB
|
4
|
-
Team
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
10
|
+
class Team < Shale::Mapper
|
11
|
+
include Equalizer.new(:id)
|
12
|
+
|
13
|
+
attribute :id, Shale::Type::Integer
|
14
|
+
attribute :spring_league, League
|
15
|
+
attribute :all_star_status, Shale::Type::String
|
16
|
+
attribute :name, Shale::Type::String
|
17
|
+
attribute :link, Shale::Type::String
|
18
|
+
attribute :season, Shale::Type::Integer
|
19
|
+
attribute :venue, Venue
|
20
|
+
attribute :spring_venue, Venue
|
21
|
+
attribute :team_code, Shale::Type::String
|
22
|
+
attribute :file_code, Shale::Type::String
|
23
|
+
attribute :abbreviation, Shale::Type::String
|
24
|
+
attribute :team_name, Shale::Type::String
|
25
|
+
attribute :location_name, Shale::Type::String
|
26
|
+
attribute :first_year_of_play, Shale::Type::Integer
|
27
|
+
attribute :league, League
|
28
|
+
attribute :division, Division
|
29
|
+
attribute :sport, Sport
|
30
|
+
attribute :short_name, Shale::Type::String
|
31
|
+
attribute :franchise_name, Shale::Type::String
|
32
|
+
attribute :club_name, Shale::Type::String
|
33
|
+
attribute :active, Shale::Type::Boolean
|
34
|
+
|
35
|
+
alias_method :active?, :active
|
36
|
+
|
37
|
+
json do
|
38
|
+
map "springLeague", to: :spring_league
|
39
|
+
map "allStarStatus", to: :all_star_status
|
40
|
+
map "id", to: :id
|
41
|
+
map "name", to: :name
|
42
|
+
map "link", to: :link
|
43
|
+
map "season", to: :season
|
44
|
+
map "venue", to: :venue
|
45
|
+
map "springVenue", to: :spring_venue
|
46
|
+
map "teamCode", to: :team_code
|
47
|
+
map "fileCode", to: :file_code
|
48
|
+
map "abbreviation", to: :abbreviation
|
49
|
+
map "teamName", to: :team_name
|
50
|
+
map "locationName", to: :location_name
|
51
|
+
map "firstYearOfPlay", to: :first_year_of_play
|
52
|
+
map "league", to: :league
|
53
|
+
map "division", to: :division
|
54
|
+
map "sport", to: :sport
|
55
|
+
map "shortName", to: :short_name
|
56
|
+
map "franchiseName", to: :franchise_name
|
57
|
+
map "clubName", to: :club_name
|
58
|
+
map "active", to: :active
|
27
59
|
end
|
28
60
|
|
29
|
-
def roster
|
30
|
-
|
31
|
-
params = {team_id:}
|
61
|
+
def roster(season: Time.now.year)
|
62
|
+
params = {season:}
|
32
63
|
query_string = URI.encode_www_form(params)
|
33
|
-
response = CLIENT.get("
|
34
|
-
|
35
|
-
|
64
|
+
response = CLIENT.get("teams/#{id}/roster?#{query_string}")
|
65
|
+
roster = Roster.from_json(response)
|
66
|
+
roster.roster
|
36
67
|
end
|
37
68
|
end
|
38
69
|
end
|
data/lib/mlb/teams.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "sport"
|
4
|
+
require_relative "team"
|
5
|
+
|
6
|
+
module MLB
|
7
|
+
class Teams < Shale::Mapper
|
8
|
+
attribute :copyright, Shale::Type::String
|
9
|
+
attribute :teams, Team, collection: true
|
10
|
+
|
11
|
+
def self.all(season: Time.now.year, sport: Sport.new(id: 1))
|
12
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
13
|
+
params = {sportId: sport_id, season:}
|
14
|
+
query_string = URI.encode_www_form(params)
|
15
|
+
response = CLIENT.get("teams?#{query_string}")
|
16
|
+
teams = from_json(response)
|
17
|
+
teams.teams
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(team, season: Time.now.year, sport: Sport.new(id: 1))
|
21
|
+
id = team.respond_to?(:id) ? team.id : team
|
22
|
+
sport_id = sport.respond_to?(:id) ? sport.id : sport
|
23
|
+
params = {sportId: sport_id, season:}
|
24
|
+
query_string = URI.encode_www_form(params)
|
25
|
+
response = CLIENT.get("teams/#{id}?#{query_string}")
|
26
|
+
teams = from_json(response)
|
27
|
+
teams.teams.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/mlb/transaction.rb
CHANGED
@@ -1,37 +1,34 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
1
|
+
require "equalizer"
|
2
|
+
require "shale"
|
3
|
+
require_relative "player"
|
4
|
+
require_relative "team"
|
3
5
|
|
4
6
|
module MLB
|
5
|
-
Transaction
|
6
|
-
|
7
|
-
:name_display_last_first, :name_sort, :note, :orig_asset, :orig_asset_type,
|
8
|
-
:player, :player_id, :resolution_cd, :resolution_date, :team, :team_id,
|
9
|
-
:trans_date, :trans_date_cd, :transaction_id, :type, :type_cd, keyword_init: true) do
|
10
|
-
def self.all(start_date: Date.today, end_date: Date.today)
|
11
|
-
sport_code = "'mlb'"
|
12
|
-
start_date = Date.parse(start_date.to_s).strftime("%Y%m%d")
|
13
|
-
end_date = Date.parse(end_date.to_s).strftime("%Y%m%d")
|
14
|
-
params = {sport_code:, start_date:, end_date:}
|
15
|
-
query_string = URI.encode_www_form(params)
|
16
|
-
response = CLIENT.get("named.transaction_all.bam?#{query_string}")
|
17
|
-
transactions = response.fetch(:transaction_all, {}).fetch(:queryResults, {}).fetch(:row, [])
|
18
|
-
transactions.collect { |transaction| Transaction.new(**transaction) }
|
19
|
-
end
|
7
|
+
class Transaction < Shale::Mapper
|
8
|
+
include Equalizer.new(:id)
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
attribute :id, Shale::Type::Integer
|
11
|
+
attribute :player, Player
|
12
|
+
attribute :from_team, Team, default: nil
|
13
|
+
attribute :to_team, Team
|
14
|
+
attribute :date, Shale::Type::Date
|
15
|
+
attribute :effective_date, Shale::Type::Date
|
16
|
+
attribute :resolution_date, Shale::Type::Date
|
17
|
+
attribute :type_code, Shale::Type::String
|
18
|
+
attribute :type_desc, Shale::Type::String
|
19
|
+
attribute :description, Shale::Type::String
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
json do
|
22
|
+
map "id", to: :id
|
23
|
+
map "person", to: :player
|
24
|
+
map "fromTeam", to: :from_team
|
25
|
+
map "toTeam", to: :to_team
|
26
|
+
map "date", to: :date
|
27
|
+
map "effectiveDate", to: :effective_date
|
28
|
+
map "resolutionDate", to: :resolution_date
|
29
|
+
map "typeCode", to: :type_code
|
30
|
+
map "typeDesc", to: :type_desc
|
31
|
+
map "description", to: :description
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "transaction"
|
4
|
+
|
5
|
+
module MLB
|
6
|
+
class Transactions < Shale::Mapper
|
7
|
+
attribute :copyright, Shale::Type::String
|
8
|
+
attribute :transactions, Transaction, collection: true
|
9
|
+
|
10
|
+
def self.between(start_date: Date.today, end_date: start_date)
|
11
|
+
params = {startDate: start_date, endDate: end_date}
|
12
|
+
query_string = URI.encode_www_form(params)
|
13
|
+
response = CLIENT.get("transactions?#{query_string}")
|
14
|
+
transactions = from_json(response)
|
15
|
+
transactions.transactions
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|