Class: Altertable::Lakehouse::Adapters::FaradayAdapter
- 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: {}) ⇒ FaradayAdapter
constructor
A new instance of FaradayAdapter.
- #post(path, body: nil, params: {}, headers: {}, &block) ⇒ Response
- #wrap_response(resp) ⇒ Response
Constructor Details
#initialize(base_url:, timeout:, open_timeout:, headers: {}) ⇒ FaradayAdapter
Returns a new instance of FaradayAdapter.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/altertable/lakehouse/adapters.rb', line 28 def initialize(base_url:, timeout:, open_timeout:, headers: {}) super require "faraday" require "faraday/retry" require "faraday/net_http" @conn = Faraday.new(url: @base_url) do |f| @headers.each { |k, v| f.headers[k] = v } f..timeout = @timeout f..open_timeout = @open_timeout f.request :retry, max: 3, interval: 0.05, backoff_factor: 2 f.adapter Faraday.default_adapter end end |
Instance Method Details
#delete(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument
66 67 68 69 70 71 72 73 |
# File 'lib/altertable/lakehouse/adapters.rb', line 66 def delete(path, body: nil, params: {}, headers: {}, &_block) # rubocop:disable Lint/UnusedMethodArgument resp = @conn.delete(path, params, headers) wrap_response(resp) rescue Faraday::ConnectionFailed => e raise Altertable::Lakehouse::NetworkError, e. rescue Faraday::TimeoutError => e raise Altertable::Lakehouse::TimeoutError, e. end |
#get(path, body: nil, params: {}, headers: {}, &_block) ⇒ Response
rubocop:disable Lint/UnusedMethodArgument
43 44 45 46 47 48 49 50 |
# File 'lib/altertable/lakehouse/adapters.rb', line 43 def get(path, body: nil, params: {}, headers: {}, &_block) # rubocop:disable Lint/UnusedMethodArgument resp = @conn.get(path, params, headers) wrap_response(resp) rescue Faraday::ConnectionFailed => e raise Altertable::Lakehouse::NetworkError, e. rescue Faraday::TimeoutError => e raise Altertable::Lakehouse::TimeoutError, e. end |
#post(path, body: nil, params: {}, headers: {}, &block) ⇒ Response
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/altertable/lakehouse/adapters.rb', line 52 def post(path, body: nil, params: {}, headers: {}, &block) resp = @conn.post(path) do |req| req.params = params if params req.headers = req.headers.merge(headers) unless headers.empty? req.body = body req..on_data = block if block_given? end wrap_response(resp) rescue Faraday::ConnectionFailed => e raise Altertable::Lakehouse::NetworkError, e. rescue Faraday::TimeoutError => e raise Altertable::Lakehouse::TimeoutError, e. end |