Class: Zeridion::Flare::NetHttpTransport
- Inherits:
-
Object
- Object
- Zeridion::Flare::NetHttpTransport
- Defined in:
- lib/zeridion_flare/client.rb
Overview
Default HTTP transport backed by Ruby's stdlib Net::HTTP. Tests can swap in a custom object that responds to #send_request with the same signature to capture requests / queue responses without touching the network.
Instance Method Summary collapse
-
#send_request(method:, url:, headers:, body:, timeout:) ⇒ Hash{Symbol=>Object}
{ status:, headers:, body: }.
Instance Method Details
#send_request(method:, url:, headers:, body:, timeout:) ⇒ Hash{Symbol=>Object}
Returns { status:, headers:, body: }.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zeridion_flare/client.rb', line 19 def send_request(method:, url:, headers:, body:, timeout:) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") http.open_timeout = 10 http.read_timeout = timeout req = build_request(method, uri, headers, body) resp = http.request(req) parsed_headers = {} resp.each_header { |k, v| parsed_headers[k.downcase] = v } { status: resp.code.to_i, headers: parsed_headers, body: resp.body.to_s } end |