Class: BSV::Overlay::HTTPSBroadcastFacilitator
- Inherits:
-
BroadcastFacilitator
- Object
- BroadcastFacilitator
- BSV::Overlay::HTTPSBroadcastFacilitator
- Defined in:
- lib/bsv/overlay/broadcast_facilitator.rb
Overview
Default HTTPS-based broadcast facilitator using Net::HTTP.
POSTs to {url}/submit with a binary BEEF body, Content-Type: application/octet-stream, and an X-Topics header containing the JSON-encoded list of topics for the tagged BEEF.
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.
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Method Summary collapse
-
#initialize(allow_http: false, http_client: nil, timeout: DEFAULT_TIMEOUT) ⇒ HTTPSBroadcastFacilitator
constructor
A new instance of HTTPSBroadcastFacilitator.
-
#send_beef(url, tagged_beef) ⇒ Hash{String => AdmittanceInstructions}?
Send a tagged BEEF to {url}/submit and return the parsed STEAK hash.
Constructor Details
#initialize(allow_http: false, http_client: nil, timeout: DEFAULT_TIMEOUT) ⇒ HTTPSBroadcastFacilitator
Returns a new instance of HTTPSBroadcastFacilitator.
46 47 48 49 50 51 |
# File 'lib/bsv/overlay/broadcast_facilitator.rb', line 46 def initialize(allow_http: false, http_client: nil, timeout: DEFAULT_TIMEOUT) super() @allow_http = allow_http @http_client = http_client @timeout = timeout end |
Instance Method Details
#send_beef(url, tagged_beef) ⇒ Hash{String => AdmittanceInstructions}?
Send a tagged BEEF to {url}/submit and return the parsed STEAK hash.
61 62 63 64 65 66 67 68 69 |
# File 'lib/bsv/overlay/broadcast_facilitator.rb', line 61 def send_beef(url, tagged_beef) validate_url!(url) uri = URI("#{url.chomp('/')}/submit") request = build_request(uri, tagged_beef) response = execute(uri, request) parse_steak(response) end |