Class: MLB::Client
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://statsapi.mlb.com/api/v1/".freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
Instance Method Summary collapse
- #delete(endpoint, headers: {}) ⇒ Object
- #get(endpoint, headers: {}) ⇒ Object
-
#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
A new instance of Client.
- #post(endpoint, body = nil, headers: {}) ⇒ Object
- #put(endpoint, body = nil, headers: {}) ⇒ Object
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 |
# 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_url ⇒ Object
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
46 47 48 |
# File 'lib/mlb/client.rb', line 46 def delete(endpoint, headers: {}) execute_request(:delete, endpoint, headers:) end |
#get(endpoint, headers: {}) ⇒ Object
34 35 36 |
# File 'lib/mlb/client.rb', line 34 def get(endpoint, headers: {}) execute_request(:get, endpoint, headers:) end |
#post(endpoint, body = nil, headers: {}) ⇒ Object
38 39 40 |
# File 'lib/mlb/client.rb', line 38 def post(endpoint, body = nil, headers: {}) execute_request(:post, endpoint, body:, headers:) end |
#put(endpoint, body = nil, headers: {}) ⇒ Object
42 43 44 |
# File 'lib/mlb/client.rb', line 42 def put(endpoint, body = nil, headers: {}) execute_request(:put, endpoint, body:, headers:) end |