Class: EasyLabs::HTTP Private
- Inherits:
-
Object
- Object
- EasyLabs::HTTP
- Defined in:
- lib/easylabs/http.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal HTTP wrapper used by every resource. Delegates to Ruby’s stdlib ‘Net::HTTP` to avoid a runtime gem dependency.
Public interface mirrors ‘EasyApiClient#makeRequest` from @easylabs/common — same auth header, same error mapping, same Retry-After parsing.
Constant Summary collapse
- DEFAULT_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
seconds
30
Instance Method Summary collapse
-
#initialize(api_url:, api_key:, timeout: DEFAULT_TIMEOUT) ⇒ HTTP
constructor
private
A new instance of HTTP.
-
#request(method, path, query: nil, body: nil, skip_auth: false, idempotency_key: nil) ⇒ Object?
private
Issue an API request.
Constructor Details
#initialize(api_url:, api_key:, timeout: DEFAULT_TIMEOUT) ⇒ HTTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HTTP.
24 25 26 27 28 |
# File 'lib/easylabs/http.rb', line 24 def initialize(api_url:, api_key:, timeout: DEFAULT_TIMEOUT) @api_url = api_url @api_key = api_key @timeout = timeout end |
Instance Method Details
#request(method, path, query: nil, body: nil, skip_auth: false, idempotency_key: nil) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Issue an API request.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/easylabs/http.rb', line 46 def request(method, path, query: nil, body: nil, skip_auth: false, idempotency_key: nil) uri = build_uri(path, query) req = build_request(method, uri, body: body, skip_auth: skip_auth, idempotency_key: idempotency_key) res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", open_timeout: @timeout, read_timeout: @timeout) do |http| http.request(req) end handle_response(res) end |