Class: MLB::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mlb/client.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://statsapi.mlb.com/api/v1/".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: DEFAULT_BASE_URL, open_timeout: Connection::DEFAULT_OPEN_TIMEOUT, read_timeout: Connection::DEFAULT_READ_TIMEOUT, write_timeout: Connection::DEFAULT_WRITE_TIMEOUT, debug_output: Connection::DEFAULT_DEBUG_OUTPUT, proxy_url: nil, max_redirects: RedirectHandler::DEFAULT_MAX_REDIRECTS) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mlb/client.rb', line 20

def initialize(base_url: DEFAULT_BASE_URL,
  open_timeout: Connection::DEFAULT_OPEN_TIMEOUT,
  read_timeout: Connection::DEFAULT_READ_TIMEOUT,
  write_timeout: Connection::DEFAULT_WRITE_TIMEOUT,
  debug_output: Connection::DEFAULT_DEBUG_OUTPUT,
  proxy_url: nil,
  max_redirects: RedirectHandler::DEFAULT_MAX_REDIRECTS)

  @base_url = base_url
  @connection = Connection.new(open_timeout:, read_timeout:, write_timeout:, debug_output:, proxy_url:)
  @request_builder = RequestBuilder.new
  @redirect_handler = RedirectHandler.new(connection: @connection, request_builder: @request_builder, max_redirects:)
  @error_handler = ErrorHandler.new
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



13
14
15
# File 'lib/mlb/client.rb', line 13

def base_url
  @base_url
end

Instance Method Details

#delete(endpoint, headers: {}) ⇒ Object



47
48
49
# File 'lib/mlb/client.rb', line 47

def delete(endpoint, headers: {})
  execute_request(:delete, endpoint, headers:)
end

#get(endpoint, headers: {}) ⇒ Object



35
36
37
# File 'lib/mlb/client.rb', line 35

def get(endpoint, headers: {})
  execute_request(:get, endpoint, headers:)
end

#post(endpoint, body = nil, headers: {}) ⇒ Object



39
40
41
# File 'lib/mlb/client.rb', line 39

def post(endpoint, body = nil, headers: {})
  execute_request(:post, endpoint, body:, headers:)
end

#put(endpoint, body = nil, headers: {}) ⇒ Object



43
44
45
# File 'lib/mlb/client.rb', line 43

def put(endpoint, body = nil, headers: {})
  execute_request(:put, endpoint, body:, headers:)
end