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: {}, **options) ⇒ 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: {}, **options) ⇒ HttpxAdapter
Returns a new instance of HttpxAdapter.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/altertable/lakehouse/adapters.rb', line 85 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. = { timeout: { operation_timeout: @timeout, connect_timeout: @open_timeout }, headers: @headers, base_url: @base_url } [:proxy] = [:proxy] if .key?(:proxy) @client = HTTPX.plugin(:retries).with(**) end |
Instance Method Details
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument
126 127 128 129 |
# File 'lib/altertable/lakehouse/adapters.rb', line 126 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
99 100 101 102 |
# File 'lib/altertable/lakehouse/adapters.rb', line 99 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/altertable/lakehouse/adapters.rb', line 104 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
133 134 135 136 137 138 |
# File 'lib/altertable/lakehouse/adapters.rb', line 133 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 |