Class: BSV::Overlay::HTTPSLookupFacilitator
- Inherits:
-
LookupFacilitator
- Object
- LookupFacilitator
- BSV::Overlay::HTTPSLookupFacilitator
- Defined in:
- lib/bsv/overlay/lookup_facilitator.rb
Overview
Default HTTPS-based lookup facilitator using Net::HTTP.
POSTs to {url}/lookup with a JSON body and the X-Aggregation: yes header, as required by the BSV Overlay Services protocol.
HTTPS is enforced by default; pass allow_http: true to permit plain HTTP (useful for local development and testing).
An injectable http_client may be supplied for testing. It must respond to #request(uri, net_http_request) and return an object with #code and #body.
Instance Method Summary collapse
-
#initialize(allow_http: false, http_client: nil) ⇒ HTTPSLookupFacilitator
constructor
A new instance of HTTPSLookupFacilitator.
-
#lookup(url, question, timeout: 5) ⇒ LookupAnswer
Perform an HTTPS POST to {url}/lookup and return the parsed answer.
Constructor Details
#initialize(allow_http: false, http_client: nil) ⇒ HTTPSLookupFacilitator
Returns a new instance of HTTPSLookupFacilitator.
43 44 45 46 47 |
# File 'lib/bsv/overlay/lookup_facilitator.rb', line 43 def initialize(allow_http: false, http_client: nil) super() @allow_http = allow_http @http_client = http_client end |
Instance Method Details
#lookup(url, question, timeout: 5) ⇒ LookupAnswer
Perform an HTTPS POST to {url}/lookup and return the parsed answer.
57 58 59 60 61 62 63 64 65 |
# File 'lib/bsv/overlay/lookup_facilitator.rb', line 57 def lookup(url, question, timeout: 5) validate_url!(url) uri = URI("#{url.chomp('/')}/lookup") request = build_request(uri, question) response = execute(uri, request, timeout) handle_response(response) end |