Class: Altertable::Lakehouse::Adapters::FaradayAdapter
- 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: {}) ⇒ FaradayAdapter
constructor
A new instance of FaradayAdapter.
- #post(path, body: nil, params: {}, headers: {}, &block) ⇒ Object
Constructor Details
#initialize(base_url:, timeout:, headers: {}) ⇒ FaradayAdapter
Returns a new instance of FaradayAdapter.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/altertable/lakehouse/adapters.rb', line 27 def initialize(base_url:, 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.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) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
64 65 66 67 68 69 70 71 |
# File 'lib/altertable/lakehouse/adapters.rb', line 64 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) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
41 42 43 44 45 46 47 48 |
# File 'lib/altertable/lakehouse/adapters.rb', line 41 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) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/altertable/lakehouse/adapters.rb', line 50 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 |