Class: BSV::Auth::SimplifiedFetchTransport
- Inherits:
-
Object
- Object
- BSV::Auth::SimplifiedFetchTransport
- Includes:
- Transport
- Defined in:
- lib/bsv/auth/simplified_fetch_transport.rb
Overview
BRC-104 client-side HTTP transport implementing Transport.
Maps BRC-103 auth message types to HTTP requests:
-
Non-general messages (
initialRequest,initialResponse,certificateRequest,certificateResponse) are POSTed as JSON to #{base_url}/.well-known/auth. Keys are converted to camelCase on the wire and back to snake_case symbols on receipt. -
General messages have their binary payload deserialised via AuthPayload.deserialize_request, sent as a real HTTP request with
x-bsv-auth-*headers attached, and the HTTP response serialised back to a binary payload via AuthPayload.serialize_response.
Instance Method Summary collapse
-
#initialize(base_url, http_client: nil) ⇒ SimplifiedFetchTransport
constructor
A new instance of SimplifiedFetchTransport.
-
#on_data {|message| ... } ⇒ Object
Registers the callback invoked when a response arrives.
-
#send(message) ⇒ Object
Sends an auth message to the remote peer.
Constructor Details
#initialize(base_url, http_client: nil) ⇒ SimplifiedFetchTransport
Returns a new instance of SimplifiedFetchTransport.
33 34 35 36 37 |
# File 'lib/bsv/auth/simplified_fetch_transport.rb', line 33 def initialize(base_url, http_client: nil) @base_url = base_url.chomp('/') @http_client = http_client || Net::HTTP @on_data_callback = nil end |
Instance Method Details
#on_data {|message| ... } ⇒ Object
Registers the callback invoked when a response arrives.
Must be called before #send.
44 45 46 |
# File 'lib/bsv/auth/simplified_fetch_transport.rb', line 44 def on_data(&block) @on_data_callback = block end |
#send(message) ⇒ Object
Sends an auth message to the remote peer.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bsv/auth/simplified_fetch_transport.rb', line 52 def send() raise "#{self.class}#send called before on_data callback was registered" if @on_data_callback.nil? type = fetch_key(, :message_type) if type == MSG_GENERAL send_general() else send_non_general() end end |