Class: Altertable::Adapters::FaradayAdapter
- Defined in:
- lib/altertable/adapters.rb,
sig/altertable/adapters.rbs
Instance Method Summary collapse
-
#initialize(base_url:, timeout:, headers: {}, proxy: nil) ⇒ FaradayAdapter
constructor
proxy left unset (default) follows Faraday's own env-based auto-detection (HTTP_PROXY/HTTPS_PROXY/NO_PROXY).
- #post(path, body: nil, params: {}) ⇒ Response
- #wrap_response(resp) ⇒ Response
Constructor Details
#initialize(base_url:, timeout:, headers: {}, proxy: nil) ⇒ FaradayAdapter
proxy left unset (default) follows Faraday's own env-based auto-detection
(HTTP_PROXY/HTTPS_PROXY/NO_PROXY). Pass false to disable proxying entirely for
fixed, trusted destinations, or a URI string to force a specific proxy.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/altertable/adapters.rb', line 21 def initialize(base_url:, timeout:, headers: {}, proxy: nil) super(base_url: base_url, timeout: timeout, headers: headers) require "faraday" @conn = Faraday.new(url: @base_url) do |f| @headers.each { |k, v| f.headers[k] = v } f..timeout = @timeout f.proxy = proxy unless proxy.nil? f.adapter Faraday.default_adapter end end |
Instance Method Details
#post(path, body: nil, params: {}) ⇒ Response
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/altertable/adapters.rb', line 33 def post(path, body: nil, params: {}) resp = @conn.post(path) do |req| req.params = params req.body = body end wrap_response(resp) rescue Faraday::ConnectionFailed => e raise Altertable::NetworkError.new(e., e) rescue Faraday::TimeoutError => e raise Altertable::NetworkError.new("Timeout: #{e.}", e) end |