Class: MLB::Client
Overview
HTTP client for making requests to the MLB Stats API
Constant Summary collapse
- DEFAULT_BASE_URL =
Default base URL for the MLB Stats API
"https://statsapi.mlb.com/api/v1/".freeze
Instance Attribute Summary collapse
-
#base_url ⇒ String
Returns the base URL for API requests.
Instance Method Summary collapse
-
#delete(endpoint, headers: {}) ⇒ String?
Performs a DELETE request.
-
#get(endpoint, headers: {}) ⇒ String?
Performs a GET request.
-
#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
constructor
Initializes a new Client instance.
-
#post(endpoint, body = nil, headers: {}) ⇒ String?
Performs a POST request.
-
#put(endpoint, body = nil, headers: {}) ⇒ String?
Performs a PUT request.
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
Initializes a new Client instance
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mlb/client.rb', line 48 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_url ⇒ String
Returns the base URL for API requests
21 22 23 |
# File 'lib/mlb/client.rb', line 21 def base_url @base_url end |
Instance Method Details
#delete(endpoint, headers: {}) ⇒ String?
Performs a DELETE request
108 109 110 |
# File 'lib/mlb/client.rb', line 108 def delete(endpoint, headers: {}) execute_request(:delete, endpoint, headers:) end |
#get(endpoint, headers: {}) ⇒ String?
Performs a GET request
70 71 72 |
# File 'lib/mlb/client.rb', line 70 def get(endpoint, headers: {}) execute_request(:get, endpoint, headers:) end |
#post(endpoint, body = nil, headers: {}) ⇒ String?
Performs a POST request
83 84 85 |
# File 'lib/mlb/client.rb', line 83 def post(endpoint, body = nil, headers: {}) execute_request(:post, endpoint, body:, headers:) end |
#put(endpoint, body = nil, headers: {}) ⇒ String?
Performs a PUT request
96 97 98 |
# File 'lib/mlb/client.rb', line 96 def put(endpoint, body = nil, headers: {}) execute_request(:put, endpoint, body:, headers:) end |