Class: Altertable::Lakehouse::Adapters::HttpxAdapter
- Defined in:
- lib/altertable/lakehouse/adapters.rb,
sig/altertable/lakehouse/adapters.rbs
Instance Method Summary collapse
-
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument.
-
#get(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(base_url:, timeout:, open_timeout:, headers: {}) ⇒ HttpxAdapter
constructor
A new instance of HttpxAdapter.
- #post(path, body: nil, params: {}, headers: {}, &block) ⇒ Response
- #wrap_response(resp) ⇒ Response
Constructor Details
#initialize(base_url:, timeout:, open_timeout:, headers: {}) ⇒ HttpxAdapter
Returns a new instance of HttpxAdapter.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/altertable/lakehouse/adapters.rb', line 83 def initialize(base_url:, timeout:, open_timeout:, headers: {}) super require "httpx" # Configure retries plugin if available or implement manual retries? # Httpx has built-in retries via plugin. @client = HTTPX.plugin(:retries).with( timeout: { operation_timeout: @timeout, connect_timeout: @open_timeout }, headers: @headers, base_url: @base_url ) end |
Instance Method Details
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument
122 123 124 125 |
# File 'lib/altertable/lakehouse/adapters.rb', line 122 def delete(path, body: nil, params: {}, headers: {}, &_block) # rubocop:disable Lint/UnusedMethodArgument resp = @client.with(headers: headers).delete(path, params: params) wrap_response(resp) end |
#get(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument
95 96 97 98 |
# File 'lib/altertable/lakehouse/adapters.rb', line 95 def get(path, body: nil, params: {}, headers: {}, &_block) # rubocop:disable Lint/UnusedMethodArgument resp = @client.with(headers: headers).get(path, params: params) wrap_response(resp) end |
#post(path, body: nil, params: {}, headers: {}, &block) ⇒ Response
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/altertable/lakehouse/adapters.rb', line 100 def post(path, body: nil, params: {}, headers: {}, &block) client = @client.with(headers: headers) if block_given? # Stream response body # HTTPX response streaming: response = client.request("POST", path, body: body, params: params, stream: true) # Check for error immediately if response.is_a?(HTTPX::ErrorResponse) raise Altertable::Lakehouse::NetworkError, response.error. end response.body.each do |chunk| block.call(chunk, response.headers["content-length"]) end wrap_response(response) else resp = client.post(path, body: body, params: params) wrap_response(resp) end end |
#wrap_response(resp) ⇒ Response
129 130 131 132 133 134 |
# File 'lib/altertable/lakehouse/adapters.rb', line 129 def wrap_response(resp) if resp.is_a?(HTTPX::ErrorResponse) raise Altertable::Lakehouse::NetworkError, resp.error. end Response.new(resp.status, resp.to_s, resp.headers) end |