mlb 0.7.0 → 0.9.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 +5 -5
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +113 -103
- data/bin/console +10 -0
- data/bin/setup +6 -0
- data/lib/mlb/client.rb +63 -0
- data/lib/mlb/connection.rb +80 -0
- data/lib/mlb/division.rb +42 -0
- data/lib/mlb/divisions.rb +30 -0
- data/lib/mlb/error_handler.rb +53 -0
- data/lib/mlb/errors/bad_gateway.rb +5 -0
- data/lib/mlb/errors/bad_request.rb +5 -0
- data/lib/mlb/errors/client_error.rb +5 -0
- data/lib/mlb/errors/connection_exception.rb +5 -0
- data/lib/mlb/errors/error.rb +3 -0
- data/lib/mlb/errors/forbidden.rb +5 -0
- data/lib/mlb/errors/gateway_timeout.rb +5 -0
- data/lib/mlb/errors/gone.rb +5 -0
- data/lib/mlb/errors/http_error.rb +14 -0
- data/lib/mlb/errors/internal_server_error.rb +5 -0
- data/lib/mlb/errors/network_error.rb +5 -0
- data/lib/mlb/errors/not_acceptable.rb +5 -0
- data/lib/mlb/errors/not_found.rb +5 -0
- data/lib/mlb/errors/payload_too_large.rb +5 -0
- data/lib/mlb/errors/server_error.rb +5 -0
- data/lib/mlb/errors/service_unavailable.rb +5 -0
- data/lib/mlb/errors/too_many_redirects.rb +5 -0
- data/lib/mlb/errors/too_many_requests.rb +5 -0
- data/lib/mlb/errors/unauthorized.rb +5 -0
- data/lib/mlb/errors/unprocessable_entity.rb +5 -0
- data/lib/mlb/handedness.rb +13 -0
- data/lib/mlb/league.rb +66 -0
- data/lib/mlb/leagues.rb +30 -0
- data/lib/mlb/player.rb +62 -18
- data/lib/mlb/players.rb +25 -0
- data/lib/mlb/position.rb +17 -0
- data/lib/mlb/redirect_handler.rb +55 -0
- data/lib/mlb/request_builder.rb +48 -0
- data/lib/mlb/roster.rb +22 -0
- data/lib/mlb/roster_entry.rb +22 -0
- data/lib/mlb/season_date_info.rb +49 -0
- data/lib/mlb/sport.rb +31 -0
- data/lib/mlb/sports.rb +22 -0
- data/lib/mlb/status.rb +8 -0
- data/lib/mlb/team.rb +56 -127
- data/lib/mlb/teams.rb +30 -0
- data/lib/mlb/transaction.rb +31 -0
- data/lib/mlb/transactions.rb +18 -0
- data/lib/mlb/venue.rb +13 -0
- data/lib/mlb/venues.rb +30 -0
- data/lib/mlb/version.rb +3 -13
- data/lib/mlb.rb +9 -3
- data/sig/mlb.rbs +186 -0
- metadata +74 -102
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +0 -5
- data/CONTRIBUTING.md +0 -49
- data/LICENSE.md +0 -20
- data/Rakefile +0 -48
- data/lib/mlb/request.rb +0 -24
- data/mlb.gemspec +0 -27
- data/spec/helper.rb +0 -32
- data/spec/mlb_spec.rb +0 -114
- data.tar.gz.sig +0 -1
- metadata.gz.sig +0 -0
data/lib/mlb/team.rb
CHANGED
@@ -1,136 +1,65 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "shale"
|
2
|
+
require_relative "division"
|
3
|
+
require_relative "league"
|
4
|
+
require_relative "sport"
|
5
|
+
require_relative "venue"
|
3
6
|
|
4
7
|
module MLB
|
5
|
-
class Team
|
6
|
-
|
8
|
+
class Team < Shale::Mapper
|
9
|
+
attribute :spring_league, League
|
10
|
+
attribute :all_star_status, Shale::Type::String
|
11
|
+
attribute :id, Shale::Type::Integer
|
12
|
+
attribute :name, Shale::Type::String
|
13
|
+
attribute :link, Shale::Type::String
|
14
|
+
attribute :season, Shale::Type::Integer
|
15
|
+
attribute :venue, Venue
|
16
|
+
attribute :spring_venue, Venue
|
17
|
+
attribute :team_code, Shale::Type::String
|
18
|
+
attribute :file_code, Shale::Type::String
|
19
|
+
attribute :abbreviation, Shale::Type::String
|
20
|
+
attribute :team_name, Shale::Type::String
|
21
|
+
attribute :location_name, Shale::Type::String
|
22
|
+
attribute :first_year_of_play, Shale::Type::Integer
|
23
|
+
attribute :league, League
|
24
|
+
attribute :division, Division
|
25
|
+
attribute :sport, Sport
|
26
|
+
attribute :short_name, Shale::Type::String
|
27
|
+
attribute :franchise_name, Shale::Type::String
|
28
|
+
attribute :club_name, Shale::Type::String
|
29
|
+
attribute :active, Shale::Type::Boolean
|
7
30
|
|
8
|
-
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# MLB::Team.all.first.name # => "Arizona Diamondbacks"
|
12
|
-
# MLB::Team.all.first.league # => "National League"
|
13
|
-
# MLB::Team.all.first.division # => "National League West"
|
14
|
-
# MLB::Team.all.first.manager # => "Bob Melvin"
|
15
|
-
# MLB::Team.all.first.wins # => 82
|
16
|
-
# MLB::Team.all.first.losses # => 80
|
17
|
-
# MLB::Team.all.first.founded # => 1998
|
18
|
-
# MLB::Team.all.first.mascot # => nil
|
19
|
-
# MLB::Team.all.first.ballpark # => "Chase Field"
|
20
|
-
# MLB::Team.all.first.logo_url # => "http://img.freebase.com/api/trans/image_thumb/wikipedia/images/en_id/13104064"
|
21
|
-
# MLB::Team.all.first.players.first.name # => "Alex Romero"
|
22
|
-
# MLB::Team.all.first.players.first.number # => 28
|
23
|
-
# MLB::Team.all.first.players.first.position # => "Right fielder"
|
24
|
-
def self.all
|
25
|
-
# Attempt to fetch the result from the Freebase API unless there is a
|
26
|
-
# connection error, in which case read from a fixture file
|
27
|
-
@all ||= begin
|
28
|
-
results_to_team(results_from_freebase)
|
29
|
-
rescue Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError
|
30
|
-
results_to_team(results_from_cache)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.reset
|
35
|
-
@all = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def initialize(attributes = {})
|
41
|
-
attributes.each do |key, value|
|
42
|
-
instance_variable_set("@#{key}", value) if self.respond_to?(key)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.results_from_freebase
|
47
|
-
Request.get('/freebase/v1/mqlread', :query => mql_query)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.results_from_cache
|
51
|
-
JSON.load(file_from_cache('teams.json').read)
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.file_from_cache(file_name)
|
55
|
-
File.new(File.expand_path('../../../cache', __FILE__) + '/' + file_name)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.results_to_team(results) # rubocop:disable CyclomaticComplexity, MethodLength
|
59
|
-
results['result'].map do |result|
|
60
|
-
league = result['league']
|
61
|
-
division = result['division']
|
62
|
-
manager = result['current_manager']
|
63
|
-
stats = result['team_stats'].first
|
64
|
-
founded = result['/sports/sports_team/founded'].first
|
65
|
-
mascot = result['/sports/sports_team/team_mascot'].first
|
66
|
-
ballpark = result['/sports/sports_team/arena_stadium'].first
|
67
|
-
logo_prefix = 'http://img.freebase.com/api/trans/image_thumb'
|
68
|
-
logo_suffix = result['/common/topic/image'].first
|
69
|
-
players = result['/sports/sports_team/roster']
|
31
|
+
alias_method :active?, :active
|
70
32
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
33
|
+
json do
|
34
|
+
map "springLeague", to: :spring_league
|
35
|
+
map "allStarStatus", to: :all_star_status
|
36
|
+
map "id", to: :id
|
37
|
+
map "name", to: :name
|
38
|
+
map "link", to: :link
|
39
|
+
map "season", to: :season
|
40
|
+
map "venue", to: :venue
|
41
|
+
map "springVenue", to: :spring_venue
|
42
|
+
map "teamCode", to: :team_code
|
43
|
+
map "fileCode", to: :file_code
|
44
|
+
map "abbreviation", to: :abbreviation
|
45
|
+
map "teamName", to: :team_name
|
46
|
+
map "locationName", to: :location_name
|
47
|
+
map "firstYearOfPlay", to: :first_year_of_play
|
48
|
+
map "league", to: :league
|
49
|
+
map "division", to: :division
|
50
|
+
map "sport", to: :sport
|
51
|
+
map "shortName", to: :short_name
|
52
|
+
map "franchiseName", to: :franchise_name
|
53
|
+
map "clubName", to: :club_name
|
54
|
+
map "active", to: :active
|
83
55
|
end
|
84
56
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
"name": null
|
92
|
-
},
|
93
|
-
"division": {
|
94
|
-
"name": null
|
95
|
-
},
|
96
|
-
"current_manager": {
|
97
|
-
"optional": true,
|
98
|
-
"name": null
|
99
|
-
},
|
100
|
-
"team_stats": [{
|
101
|
-
"wins": null,
|
102
|
-
"losses": null,
|
103
|
-
"season": null,
|
104
|
-
"limit": 1,
|
105
|
-
"sort": "-season"
|
106
|
-
}],
|
107
|
-
"/sports/sports_team/roster": [{
|
108
|
-
"player": null,
|
109
|
-
"number": null,
|
110
|
-
"from": null,
|
111
|
-
"to": null,
|
112
|
-
"position": [],
|
113
|
-
"sort": "player"
|
114
|
-
}],
|
115
|
-
"/sports/sports_team/founded": [{
|
116
|
-
"value": null
|
117
|
-
}],
|
118
|
-
"/sports/sports_team/team_mascot": [{}],
|
119
|
-
"/sports/sports_team/arena_stadium": [{
|
120
|
-
"name": null
|
121
|
-
}],
|
122
|
-
"/common/topic/image": [{
|
123
|
-
"optional": true,
|
124
|
-
"id": null,
|
125
|
-
"timestamp": null,
|
126
|
-
"sort": "-timestamp",
|
127
|
-
"limit": 1
|
128
|
-
}],
|
129
|
-
"sort": "name",
|
130
|
-
"type": "/baseball/baseball_team"
|
131
|
-
}]
|
132
|
-
eos
|
133
|
-
query.gsub!("\n", '').gsub!(' ', '')
|
57
|
+
def roster(season: Time.now.year)
|
58
|
+
params = {season:}
|
59
|
+
query_string = URI.encode_www_form(params)
|
60
|
+
response = CLIENT.get("teams/#{id}/roster?#{query_string}")
|
61
|
+
roster = Roster.from_json(response)
|
62
|
+
roster.roster
|
134
63
|
end
|
135
64
|
end
|
136
65
|
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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "shale"
|
2
|
+
require_relative "player"
|
3
|
+
require_relative "team"
|
4
|
+
|
5
|
+
module MLB
|
6
|
+
class Transaction < Shale::Mapper
|
7
|
+
attribute :id, Shale::Type::Integer
|
8
|
+
attribute :player, Player
|
9
|
+
attribute :from_team, Team, default: nil
|
10
|
+
attribute :to_team, Team
|
11
|
+
attribute :date, Shale::Type::Date
|
12
|
+
attribute :effective_date, Shale::Type::Date
|
13
|
+
attribute :resolution_date, Shale::Type::Date
|
14
|
+
attribute :type_code, Shale::Type::String
|
15
|
+
attribute :type_desc, Shale::Type::String
|
16
|
+
attribute :description, Shale::Type::String
|
17
|
+
|
18
|
+
json do
|
19
|
+
map "id", to: :id
|
20
|
+
map "person", to: :player
|
21
|
+
map "fromTeam", to: :from_team
|
22
|
+
map "toTeam", to: :to_team
|
23
|
+
map "date", to: :date
|
24
|
+
map "effectiveDate", to: :effective_date
|
25
|
+
map "resolutionDate", to: :resolution_date
|
26
|
+
map "typeCode", to: :type_code
|
27
|
+
map "typeDesc", to: :type_desc
|
28
|
+
map "description", to: :description
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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
|
data/lib/mlb/venue.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "shale"
|
2
|
+
|
3
|
+
module MLB
|
4
|
+
class Venue < Shale::Mapper
|
5
|
+
attribute :id, Shale::Type::Integer
|
6
|
+
attribute :name, Shale::Type::String
|
7
|
+
attribute :link, Shale::Type::String
|
8
|
+
attribute :active, Shale::Type::Boolean
|
9
|
+
attribute :season, Shale::Type::Integer
|
10
|
+
|
11
|
+
alias_method :active?, :active
|
12
|
+
end
|
13
|
+
end
|
data/lib/mlb/venues.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "shale"
|
2
|
+
require "uri"
|
3
|
+
require_relative "sport"
|
4
|
+
require_relative "venue"
|
5
|
+
|
6
|
+
module MLB
|
7
|
+
class Venues < Shale::Mapper
|
8
|
+
attribute :copyright, Shale::Type::String
|
9
|
+
attribute :venues, Venue, 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("venues?#{query_string}")
|
16
|
+
venues = from_json(response)
|
17
|
+
venues.venues
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(venue, season: Time.now.year, sport: Sport.new(id: 1))
|
21
|
+
id = venue.respond_to?(:id) ? venue.id : venue
|
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("venues/#{id}?#{query_string}")
|
26
|
+
venues = from_json(response)
|
27
|
+
venues.venues.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/mlb/version.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
|
-
|
2
|
-
class Version
|
3
|
-
MAJOR = 0
|
4
|
-
MINOR = 7
|
5
|
-
PATCH = 0
|
6
|
-
PRE = nil
|
1
|
+
require "rubygems/version"
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
3
|
+
module MLB
|
4
|
+
VERSION = Gem::Version.create("0.9.0")
|
15
5
|
end
|
data/lib/mlb.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative "mlb/client"
|
2
|
+
require_relative "mlb/divisions"
|
3
|
+
require_relative "mlb/leagues"
|
4
|
+
require_relative "mlb/players"
|
5
|
+
require_relative "mlb/roster"
|
6
|
+
require_relative "mlb/sports"
|
7
|
+
require_relative "mlb/teams"
|
8
|
+
require_relative "mlb/transactions"
|
9
|
+
require_relative "mlb/venues"
|
data/sig/mlb.rbs
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
module MLB
|
2
|
+
CLIENT: Client
|
3
|
+
VERSION: Gem::Version
|
4
|
+
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class ClientError < HTTPError
|
9
|
+
end
|
10
|
+
|
11
|
+
class BadGateway < ClientError
|
12
|
+
end
|
13
|
+
|
14
|
+
class BadRequest < ClientError
|
15
|
+
end
|
16
|
+
|
17
|
+
class ConnectionException < ClientError
|
18
|
+
end
|
19
|
+
|
20
|
+
class HTTPError < Error
|
21
|
+
attr_reader response : Net::HTTPResponse
|
22
|
+
attr_reader code : String
|
23
|
+
|
24
|
+
def initialize: (response: Net::HTTPResponse) -> void
|
25
|
+
end
|
26
|
+
|
27
|
+
class Forbidden < ClientError
|
28
|
+
end
|
29
|
+
|
30
|
+
class GatewayTimeout < ClientError
|
31
|
+
end
|
32
|
+
|
33
|
+
class Gone < ClientError
|
34
|
+
end
|
35
|
+
|
36
|
+
class InternalServerError < ServerError
|
37
|
+
end
|
38
|
+
|
39
|
+
class NetworkError < Error
|
40
|
+
end
|
41
|
+
|
42
|
+
class NotAcceptable < ClientError
|
43
|
+
end
|
44
|
+
|
45
|
+
class NotFound < ClientError
|
46
|
+
end
|
47
|
+
|
48
|
+
class PayloadTooLarge < ClientError
|
49
|
+
end
|
50
|
+
|
51
|
+
class ServerError < HTTPError
|
52
|
+
end
|
53
|
+
|
54
|
+
class ServiceUnavailable < ServerError
|
55
|
+
end
|
56
|
+
|
57
|
+
class TooManyRedirects < Error
|
58
|
+
end
|
59
|
+
|
60
|
+
class TooManyRequests < ClientError
|
61
|
+
end
|
62
|
+
|
63
|
+
class Unauthorized < ClientError
|
64
|
+
end
|
65
|
+
|
66
|
+
class UnprocessableEntity < ClientError
|
67
|
+
end
|
68
|
+
|
69
|
+
class Connection
|
70
|
+
DEFAULT_HOST: String
|
71
|
+
DEFAULT_PORT: Integer
|
72
|
+
DEFAULT_OPEN_TIMEOUT: Integer
|
73
|
+
DEFAULT_READ_TIMEOUT: Integer
|
74
|
+
DEFAULT_WRITE_TIMEOUT: Integer
|
75
|
+
DEFAULT_DEBUG_OUTPUT: IO
|
76
|
+
NETWORK_ERRORS: Array[(singleton(Errno::ECONNREFUSED) | singleton(Errno::ECONNRESET) | singleton(Net::OpenTimeout) | singleton(Net::ReadTimeout) | singleton(OpenSSL::SSL::SSLError))]
|
77
|
+
|
78
|
+
@proxy_url: URI::Generic | String
|
79
|
+
|
80
|
+
extend Forwardable
|
81
|
+
|
82
|
+
attr_accessor open_timeout : Float | Integer
|
83
|
+
attr_accessor read_timeout : Float | Integer
|
84
|
+
attr_accessor write_timeout : Float | Integer
|
85
|
+
attr_accessor debug_output : IO
|
86
|
+
|
87
|
+
attr_reader proxy_uri: URI::Generic?
|
88
|
+
attr_reader proxy_host : String?
|
89
|
+
attr_reader proxy_port : Integer?
|
90
|
+
attr_reader proxy_user : String?
|
91
|
+
attr_reader proxy_pass : String?
|
92
|
+
|
93
|
+
def initialize: (?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?proxy_url: URI::Generic? | String?, ?debug_output: IO) -> void
|
94
|
+
def proxy_url=: (URI::Generic | String proxy_url) -> void
|
95
|
+
def perform: (request: Net::HTTPRequest) -> Net::HTTPResponse
|
96
|
+
|
97
|
+
private
|
98
|
+
def build_http_client: (?String host, ?Integer port) -> Net::HTTP
|
99
|
+
def configure_http_client: (Net::HTTP http_client) -> Net::HTTP
|
100
|
+
end
|
101
|
+
|
102
|
+
class RequestBuilder
|
103
|
+
HTTP_METHODS: Hash[Symbol, (singleton(Net::HTTP::Get) | singleton(Net::HTTP::Post) | singleton(Net::HTTP::Put) | singleton(Net::HTTP::Delete))]
|
104
|
+
DEFAULT_HEADERS: Hash[String, String]
|
105
|
+
|
106
|
+
def initialize: (?content_type: String, ?user_agent: String) -> void
|
107
|
+
def build: (http_method: Symbol, uri: URI::Generic, ?body: String?, ?headers: Hash[String, String]) -> (Net::HTTPRequest)
|
108
|
+
|
109
|
+
private
|
110
|
+
def create_request: (http_method: Symbol, uri: URI::Generic, body: String?) -> (Net::HTTPRequest)
|
111
|
+
def add_headers: (request: Net::HTTPRequest, headers: Hash[String, String]) -> void
|
112
|
+
def escape_query_params: (URI::Generic uri) -> URI::Generic
|
113
|
+
end
|
114
|
+
|
115
|
+
class RedirectHandler
|
116
|
+
DEFAULT_MAX_REDIRECTS: Integer
|
117
|
+
|
118
|
+
attr_reader connection: Connection
|
119
|
+
attr_reader request_builder: RequestBuilder
|
120
|
+
attr_reader max_redirects: Integer
|
121
|
+
def initialize: (?connection: Connection, ?request_builder: RequestBuilder, ?max_redirects: Integer) -> void
|
122
|
+
def handle: (response: Net::HTTPResponse, request: Net::HTTPRequest, base_url: String, ?redirect_count: Integer) -> Net::HTTPResponse
|
123
|
+
|
124
|
+
private
|
125
|
+
def build_new_uri: (Net::HTTPResponse response, String base_url) -> URI::Generic
|
126
|
+
def build_request: (Net::HTTPRequest request, URI::Generic new_uri, Integer response_code) -> Net::HTTPRequest
|
127
|
+
def send_new_request: (URI::Generic new_uri, Net::HTTPRequest new_request) -> Net::HTTPResponse
|
128
|
+
end
|
129
|
+
|
130
|
+
class ErrorHandler
|
131
|
+
ERROR_MAP: Hash[Integer, singleton(BadGateway) | singleton(BadRequest) | singleton(ConnectionException) | singleton(Forbidden) | singleton(GatewayTimeout) | singleton(Gone) | singleton(InternalServerError) | singleton(NotAcceptable) | singleton(NotFound) | singleton(PayloadTooLarge) | singleton(ServiceUnavailable) | singleton(TooManyRequests) | singleton(Unauthorized) | singleton(UnprocessableEntity)]
|
132
|
+
JSON_CONTENT_TYPE_REGEXP: Regexp
|
133
|
+
|
134
|
+
def parse: (response: Net::HTTPResponse) -> untyped
|
135
|
+
|
136
|
+
private
|
137
|
+
def error: (Net::HTTPResponse response) -> HTTPError
|
138
|
+
def error_class: (Net::HTTPResponse response) -> (singleton(BadGateway) | singleton(BadRequest) | singleton(ConnectionException) | singleton(Forbidden) | singleton(GatewayTimeout) | singleton(Gone) | singleton(InternalServerError) | singleton(NotAcceptable) | singleton(NotFound) | singleton(PayloadTooLarge) | singleton(ServiceUnavailable) | singleton(TooManyRequests) | singleton(Unauthorized) | singleton(UnprocessableEntity))
|
139
|
+
def json?: (Net::HTTPResponse response) -> bool
|
140
|
+
end
|
141
|
+
|
142
|
+
class Client
|
143
|
+
DEFAULT_BASE_URL: String
|
144
|
+
extend Forwardable
|
145
|
+
@connection: Connection
|
146
|
+
@request_builder: RequestBuilder
|
147
|
+
@redirect_handler: RedirectHandler
|
148
|
+
@error_handler: ErrorHandler
|
149
|
+
|
150
|
+
attr_accessor base_url: String
|
151
|
+
def initialize: (?base_url: String, ?open_timeout: Integer, ?read_timeout: Integer, ?write_timeout: Integer, ?debug_output: untyped, ?proxy_url: nil, ?max_redirects: Integer) -> void
|
152
|
+
def get: (String endpoint, ?headers: Hash[String, String]) -> untyped
|
153
|
+
def post: (String endpoint, ?String? body, ?headers: Hash[String, String]) -> untyped
|
154
|
+
def put: (String endpoint, ?String? body, ?headers: Hash[String, String]) -> untyped
|
155
|
+
def delete: (String endpoint, ?headers: Hash[String, String]) -> untyped
|
156
|
+
|
157
|
+
private
|
158
|
+
def execute_request: (:delete | :get | :post | :put http_method, String endpoint, ?body: String?, ?headers: Hash[String, String]) -> nil
|
159
|
+
end
|
160
|
+
|
161
|
+
attr_accessor effective_date: String
|
162
|
+
attr_accessor player_id: String
|
163
|
+
attr_accessor team_id: String
|
164
|
+
|
165
|
+
class Team < Struct[untyped]
|
166
|
+
attr_accessor team_id: String
|
167
|
+
def self.new: -> void
|
168
|
+
def self.all: (?season: Integer, ?sort_order: String, ?all_star: false) -> Array[Team]
|
169
|
+
def roster: -> Array[Player]
|
170
|
+
end
|
171
|
+
|
172
|
+
class Transaction < Struct[untyped]
|
173
|
+
attr_accessor player_id: String
|
174
|
+
attr_accessor team_id: String
|
175
|
+
def self.new: -> void
|
176
|
+
def self.all: (?season: Integer, ?sort_order: String, ?all_star: false) -> Array[Team]
|
177
|
+
def team: -> Team
|
178
|
+
def player: -> Player
|
179
|
+
end
|
180
|
+
|
181
|
+
class Player < Struct[untyped]
|
182
|
+
attr_accessor player_id: String
|
183
|
+
def self.new: -> void
|
184
|
+
def team: -> Team
|
185
|
+
end
|
186
|
+
end
|