Class: Altertable::Adapters::HttpxAdapter
- Defined in:
- lib/altertable/adapters.rb,
sig/altertable/adapters.rbs
Instance Method Summary collapse
-
#initialize(base_url:, timeout:, headers: {}, proxy: nil) ⇒ HttpxAdapter
constructor
This adapter never auto-detects HTTP_PROXY/HTTPS_PROXY (httpx requires the :proxy plugin to be loaded explicitly).
- #post(path, body: nil, params: {}) ⇒ Response
- #wrap_response(resp) ⇒ Response
Constructor Details
#initialize(base_url:, timeout:, headers: {}, proxy: nil) ⇒ HttpxAdapter
This adapter never auto-detects HTTP_PROXY/HTTPS_PROXY (httpx requires the :proxy
plugin to be loaded explicitly). proxy: false and the default (unset) are
therefore equivalent; pass a URI string to force a specific proxy.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/altertable/adapters.rb', line 56 def initialize(base_url:, timeout:, headers: {}, proxy: nil) super(base_url: base_url, timeout: timeout, headers: headers) require "httpx" client = proxy ? HTTPX.plugin(:proxy).plugin(:retries).with(proxy: { uri: proxy }) : HTTPX.plugin(:retries) @client = client.with( timeout: { operation_timeout: @timeout }, headers: @headers, base_url: @base_url ) end |
Instance Method Details
#post(path, body: nil, params: {}) ⇒ Response
67 68 69 70 71 72 |
# File 'lib/altertable/adapters.rb', line 67 def post(path, body: nil, params: {}) resp = @client.post(path, body: body, params: params) wrap_response(resp) rescue HTTPX::Error => e raise Altertable::NetworkError.new(e., e) end |
#wrap_response(resp) ⇒ Response
76 77 78 79 80 81 |
# File 'lib/altertable/adapters.rb', line 76 def wrap_response(resp) if resp.is_a?(HTTPX::ErrorResponse) raise Altertable::NetworkError.new(resp.error., resp.error) end Response.new(resp.status, resp.to_s, resp.headers) end |