mlb 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +2 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +115 -103
  5. data/bin/console +10 -0
  6. data/bin/setup +6 -0
  7. data/lib/mlb/client.rb +73 -0
  8. data/lib/mlb/connection.rb +80 -0
  9. data/lib/mlb/errors/bad_gateway.rb +5 -0
  10. data/lib/mlb/errors/bad_request.rb +5 -0
  11. data/lib/mlb/errors/client_error.rb +5 -0
  12. data/lib/mlb/errors/connection_exception.rb +5 -0
  13. data/lib/mlb/errors/error.rb +3 -0
  14. data/lib/mlb/errors/forbidden.rb +5 -0
  15. data/lib/mlb/errors/gateway_timeout.rb +5 -0
  16. data/lib/mlb/errors/gone.rb +5 -0
  17. data/lib/mlb/errors/http_error.rb +14 -0
  18. data/lib/mlb/errors/internal_server_error.rb +5 -0
  19. data/lib/mlb/errors/network_error.rb +5 -0
  20. data/lib/mlb/errors/not_acceptable.rb +5 -0
  21. data/lib/mlb/errors/not_found.rb +5 -0
  22. data/lib/mlb/errors/payload_too_large.rb +5 -0
  23. data/lib/mlb/errors/server_error.rb +5 -0
  24. data/lib/mlb/errors/service_unavailable.rb +5 -0
  25. data/lib/mlb/errors/too_many_redirects.rb +5 -0
  26. data/lib/mlb/errors/too_many_requests.rb +5 -0
  27. data/lib/mlb/errors/unauthorized.rb +5 -0
  28. data/lib/mlb/errors/unprocessable_entity.rb +5 -0
  29. data/lib/mlb/player.rb +17 -20
  30. data/lib/mlb/redirect_handler.rb +55 -0
  31. data/lib/mlb/request_builder.rb +48 -0
  32. data/lib/mlb/response_parser.rb +61 -0
  33. data/lib/mlb/team.rb +33 -131
  34. data/lib/mlb/transaction.rb +37 -0
  35. data/lib/mlb/version.rb +3 -13
  36. data/lib/mlb.rb +3 -3
  37. data/sig/mlb.rbs +191 -0
  38. metadata +55 -114
  39. checksums.yaml.gz.sig +0 -0
  40. data/.yardopts +0 -5
  41. data/CONTRIBUTING.md +0 -49
  42. data/LICENSE.md +0 -20
  43. data/Rakefile +0 -48
  44. data/lib/mlb/request.rb +0 -24
  45. data/mlb.gemspec +0 -27
  46. data/spec/helper.rb +0 -32
  47. data/spec/mlb_spec.rb +0 -114
  48. data.tar.gz.sig +0 -1
  49. metadata.gz.sig +0 -0
@@ -0,0 +1,55 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require_relative "connection"
4
+ require_relative "errors/too_many_redirects"
5
+ require_relative "request_builder"
6
+
7
+ module MLB
8
+ class RedirectHandler
9
+ DEFAULT_MAX_REDIRECTS = 10
10
+
11
+ attr_accessor :max_redirects
12
+ attr_reader :connection, :request_builder
13
+
14
+ def initialize(connection: Connection.new, request_builder: RequestBuilder.new,
15
+ max_redirects: DEFAULT_MAX_REDIRECTS)
16
+ @connection = connection
17
+ @request_builder = request_builder
18
+ @max_redirects = max_redirects
19
+ end
20
+
21
+ def handle(response:, request:, base_url:, redirect_count: 0)
22
+ if response.is_a?(Net::HTTPRedirection)
23
+ raise TooManyRedirects, "Too many redirects" if redirect_count > max_redirects
24
+
25
+ new_uri = build_new_uri(response, base_url)
26
+
27
+ new_request = build_request(request, new_uri, Integer(response.code))
28
+ new_response = connection.perform(request: new_request)
29
+
30
+ handle(response: new_response, request: new_request, base_url:, redirect_count: redirect_count + 1)
31
+ else
32
+ response
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def build_new_uri(response, base_url)
39
+ location = response.fetch("location")
40
+ # If location is relative, it will join with the original base URL, otherwise it will overwrite it
41
+ URI.join(base_url, location)
42
+ end
43
+
44
+ def build_request(request, uri, response_code)
45
+ http_method, body = case response_code
46
+ in 307 | 308
47
+ [request.method.downcase.to_sym, request.body]
48
+ else
49
+ [:get, nil]
50
+ end
51
+
52
+ request_builder.build(http_method:, uri:, body:)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,48 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require_relative "version"
4
+
5
+ module MLB
6
+ class RequestBuilder
7
+ DEFAULT_HEADERS = {
8
+ "Content-Type" => "application/json; charset=utf-8",
9
+ "User-Agent" => "MLB-Client/#{VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} (#{RUBY_PLATFORM})"
10
+ }.freeze
11
+ HTTP_METHODS = {
12
+ get: Net::HTTP::Get,
13
+ post: Net::HTTP::Post,
14
+ put: Net::HTTP::Put,
15
+ delete: Net::HTTP::Delete
16
+ }.freeze
17
+
18
+ def build(http_method:, uri:, body: nil, headers: {})
19
+ request = create_request(http_method:, uri:, body:)
20
+ add_headers(request:, headers:)
21
+ request
22
+ end
23
+
24
+ private
25
+
26
+ def create_request(http_method:, uri:, body:)
27
+ http_method_class = HTTP_METHODS[http_method]
28
+
29
+ raise ArgumentError, "Unsupported HTTP method: #{http_method}" unless http_method_class
30
+
31
+ escaped_uri = escape_query_params(uri)
32
+ request = http_method_class.new(escaped_uri)
33
+ request.body = body
34
+ request
35
+ end
36
+
37
+ def add_headers(request:, headers:)
38
+ DEFAULT_HEADERS.merge(headers).each do |key, value|
39
+ request.delete(key)
40
+ request.add_field(key, value)
41
+ end
42
+ end
43
+
44
+ def escape_query_params(uri)
45
+ URI(uri).tap { |u| u.query = URI.encode_www_form(URI.decode_www_form(u.query)) if u.query }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,61 @@
1
+ require "json"
2
+ require "net/http"
3
+ require_relative "errors/bad_gateway"
4
+ require_relative "errors/bad_request"
5
+ require_relative "errors/connection_exception"
6
+ require_relative "errors/http_error"
7
+ require_relative "errors/forbidden"
8
+ require_relative "errors/gateway_timeout"
9
+ require_relative "errors/gone"
10
+ require_relative "errors/internal_server_error"
11
+ require_relative "errors/not_acceptable"
12
+ require_relative "errors/not_found"
13
+ require_relative "errors/payload_too_large"
14
+ require_relative "errors/service_unavailable"
15
+ require_relative "errors/too_many_requests"
16
+ require_relative "errors/unauthorized"
17
+ require_relative "errors/unprocessable_entity"
18
+
19
+ module MLB
20
+ class ResponseParser
21
+ ERROR_MAP = {
22
+ 400 => BadRequest,
23
+ 401 => Unauthorized,
24
+ 403 => Forbidden,
25
+ 404 => NotFound,
26
+ 406 => NotAcceptable,
27
+ 409 => ConnectionException,
28
+ 410 => Gone,
29
+ 413 => PayloadTooLarge,
30
+ 422 => UnprocessableEntity,
31
+ 429 => TooManyRequests,
32
+ 500 => InternalServerError,
33
+ 502 => BadGateway,
34
+ 503 => ServiceUnavailable,
35
+ 504 => GatewayTimeout
36
+ }.freeze
37
+ JSON_CONTENT_TYPE_REGEXP = %r{application/json}
38
+
39
+ def parse(response:, array_class: nil, object_class: nil)
40
+ raise error(response) unless response.is_a?(Net::HTTPSuccess)
41
+
42
+ return unless json?(response)
43
+
44
+ JSON.parse(response.body, array_class:, object_class:, symbolize_names: true)
45
+ end
46
+
47
+ private
48
+
49
+ def error(response)
50
+ error_class(response).new(response:)
51
+ end
52
+
53
+ def error_class(response)
54
+ ERROR_MAP[Integer(response.code)] || HTTPError
55
+ end
56
+
57
+ def json?(response)
58
+ JSON_CONTENT_TYPE_REGEXP.match?(response["content-type"])
59
+ end
60
+ end
61
+ end
data/lib/mlb/team.rb CHANGED
@@ -1,136 +1,38 @@
1
- require 'faraday'
2
- require 'multi_json'
1
+ require "uri"
3
2
 
4
3
  module MLB
5
- class Team
6
- attr_reader :name, :league, :division, :manager, :wins, :losses, :founded, :mascot, :ballpark, :logo_url, :players
7
-
8
- # Returns an array of Team objects
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']
70
-
71
- new(:name => result['name'],
72
- :league => (league ? league['name'] : nil),
73
- :division => (division ? division['name'] : nil),
74
- :manager => (manager ? manager['name'] : nil),
75
- :wins => (stats ? stats['wins'].to_i : nil),
76
- :losses => (stats ? stats['losses'].to_i : nil),
77
- :founded => (founded ? founded['value'].to_i : nil),
78
- :mascot => (mascot ? mascot['name'] : nil),
79
- :ballpark => (ballpark ? ballpark['name'] : nil),
80
- :logo_url => (logo_suffix ? logo_prefix + logo_suffix['id'] : nil),
81
- :players => (players ? Player.all_from_roster(players) : []))
82
- end
83
- end
84
-
85
- # Returns the MQL query for teams, as a Ruby hash
86
- def self.mql_query # rubocop:disable MethodLength
87
- query = <<-eos
88
- [{
89
- "name": null,
90
- "league": {
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!(' ', '')
4
+ Team = Struct.new(:active_sw, :address, :address_city,
5
+ :address_country, :address_intl, :address_line1, :address_line2,
6
+ :address_line3, :address_province, :address_state, :address_zip, :all_star_sw,
7
+ :base_url, :bis_team_code, :city, :division, :division_abbrev, :division_full,
8
+ :division_id, :file_code, :first_year_of_play, :franchise_code, :home_opener,
9
+ :home_opener_time, :last_year_of_play, :league, :league_abbrev, :league_full,
10
+ :league_id, :mlb_org, :mlb_org_abbrev, :mlb_org_brief, :mlb_org_id,
11
+ :mlb_org_short, :name, :name_abbrev, :name_display_brief, :name_display_full,
12
+ :name_display_long, :name_display_short, :name_short, :phone_number, :season,
13
+ :sport_code, :sport_code_display, :sport_code_name, :sport_id, :spring_league,
14
+ :spring_league_abbrev, :spring_league_full, :spring_league_id, :state,
15
+ :store_url, :team_code, :team_id, :time_zone, :time_zone_alt,
16
+ :time_zone_generic, :time_zone_num, :time_zone_text, :venue_id, :venue_name,
17
+ :venue_short, :website_url, keyword_init: true) do
18
+ def self.all(season: Time.now.year, sort_order: "name_asc", all_star: false)
19
+ sport_code = "'mlb'"
20
+ season = "'#{season}'"
21
+ all_star_sw = all_star ? "'Y'" : "'N'"
22
+ params = {sport_code:, season:, sort_order:, all_star_sw:}
23
+ query_string = URI.encode_www_form(params)
24
+ response = CLIENT.get("named.team_all_season.bam?#{query_string}")
25
+ teams = response[:team_all_season][:queryResults][:row]
26
+ teams.collect { |team| Team.new(**team) }
27
+ end
28
+
29
+ def roster
30
+ require_relative "player"
31
+ params = {team_id:}
32
+ query_string = URI.encode_www_form(params)
33
+ response = CLIENT.get("named.roster_40.bam?#{query_string}")
34
+ players = response[:roster_40][:queryResults][:row]
35
+ players.collect { |player| Player.new(**player) }
134
36
  end
135
37
  end
136
38
  end
@@ -0,0 +1,37 @@
1
+ require "date"
2
+ require "uri"
3
+
4
+ module MLB
5
+ Transaction = Struct.new(:conditional_sw, :effective_date, :final_asset,
6
+ :final_asset_type, :from_team, :from_team_id, :name_display_first_last,
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
20
+
21
+ def team
22
+ require_relative "team"
23
+ teams = effective_date.to_s.empty? ? Team.all : Team.all(season: effective_date.to_s[0...4].to_i)
24
+ teams.find { |t| t[:team_id] == team_id.to_s }
25
+ end
26
+
27
+ def player
28
+ params = {team_id:}
29
+ query_string = URI.encode_www_form(params)
30
+ response = CLIENT.get("named.roster_40.bam?#{query_string}")
31
+ players = response[:roster_40][:queryResults][:row]
32
+ player = players.find { |p| p[:player_id] == player_id.to_s }
33
+ require_relative "player"
34
+ Player.new(**player)
35
+ end
36
+ end
37
+ end
data/lib/mlb/version.rb CHANGED
@@ -1,15 +1,5 @@
1
- module MLB
2
- class Version
3
- MAJOR = 0
4
- MINOR = 7
5
- PATCH = 0
6
- PRE = nil
1
+ require "rubygems/version"
7
2
 
8
- class << self
9
- # @return [String]
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.8.0")
15
5
  end
data/lib/mlb.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'mlb/request'
2
- require 'mlb/team'
3
- require 'mlb/player'
1
+ require_relative "mlb/client"
2
+ require_relative "mlb/team"
3
+ require_relative "mlb/transaction"
data/sig/mlb.rbs ADDED
@@ -0,0 +1,191 @@
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 ResponseParser
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, ?array_class: Class?, ?object_class: Class?) -> 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
+ DEFAULT_ARRAY_CLASS: singleton(Array)
145
+ DEFAULT_OBJECT_CLASS: singleton(Hash)
146
+ extend Forwardable
147
+ @connection: Connection
148
+ @request_builder: RequestBuilder
149
+ @redirect_handler: RedirectHandler
150
+ @response_parser: ResponseParser
151
+
152
+ attr_accessor base_url: String
153
+ attr_accessor default_array_class: singleton(Array)
154
+ attr_accessor default_object_class: singleton(Hash)
155
+ def initialize: (?base_url: String, ?open_timeout: Integer, ?read_timeout: Integer, ?write_timeout: Integer, ?debug_output: untyped, ?proxy_url: nil, ?default_array_class: singleton(Array), ?default_object_class: singleton(Hash), ?max_redirects: Integer) -> void
156
+ def get: (String endpoint, ?headers: Hash[String, String], ?array_class: Class, ?object_class: Class) -> untyped
157
+ def post: (String endpoint, ?String? body, ?headers: Hash[String, String], ?array_class: Class, ?object_class: Class) -> untyped
158
+ def put: (String endpoint, ?String? body, ?headers: Hash[String, String], ?array_class: Class, ?object_class: Class) -> untyped
159
+ def delete: (String endpoint, ?headers: Hash[String, String], ?array_class: Class, ?object_class: Class) -> untyped
160
+
161
+ private
162
+ def initialize_default_classes: (singleton(Array) default_array_class, singleton(Hash) default_object_class) -> singleton(Hash)
163
+ def execute_request: (:delete | :get | :post | :put http_method, String endpoint, ?body: String?, ?headers: Hash[String, String], ?array_class: Class, ?object_class: Class) -> nil
164
+ end
165
+
166
+ attr_accessor effective_date: String
167
+ attr_accessor player_id: String
168
+ attr_accessor team_id: String
169
+
170
+ class Team < Struct[untyped]
171
+ attr_accessor team_id: String
172
+ def self.new: -> void
173
+ def self.all: (?season: Integer, ?sort_order: String, ?all_star: false) -> Array[Team]
174
+ def roster: -> Array[Player]
175
+ end
176
+
177
+ class Transaction < Struct[untyped]
178
+ attr_accessor player_id: String
179
+ attr_accessor team_id: String
180
+ def self.new: -> void
181
+ def self.all: (?season: Integer, ?sort_order: String, ?all_star: false) -> Array[Team]
182
+ def team: -> Team
183
+ def player: -> Player
184
+ end
185
+
186
+ class Player < Struct[untyped]
187
+ attr_accessor player_id: String
188
+ def self.new: -> void
189
+ def team: -> Team
190
+ end
191
+ end