Class: Altertable::Lakehouse::Adapters::HttpxAdapter
- Defined in:
- lib/altertable/lakehouse/adapters.rb
Instance Method Summary collapse
-
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#get(path, body: nil, params: {}, headers: {}, &_block) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(base_url:, timeout:, headers: {}) ⇒ HttpxAdapter
constructor
A new instance of HttpxAdapter.
- #post(path, body: nil, params: {}, headers: {}, &block) ⇒ Object
Constructor Details
#initialize(base_url:, timeout:, headers: {}) ⇒ HttpxAdapter
Returns a new instance of HttpxAdapter.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/altertable/lakehouse/adapters.rb', line 81 def initialize(base_url:, 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 }, headers: @headers, base_url: @base_url ) end |
Instance Method Details
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
120 121 122 123 |
# File 'lib/altertable/lakehouse/adapters.rb', line 120 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) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
93 94 95 96 |
# File 'lib/altertable/lakehouse/adapters.rb', line 93 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) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/altertable/lakehouse/adapters.rb', line 98 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 |