Class: Igniter::Store::MCPAdapter::RemoteDispatch
- Inherits:
-
Object
- Object
- Igniter::Store::MCPAdapter::RemoteDispatch
- Defined in:
- lib/igniter/store/mcp_adapter.rb
Instance Method Summary collapse
- #dispatch(op:, packet:, request_id:) ⇒ Object
-
#initialize(endpoint) ⇒ RemoteDispatch
constructor
A new instance of RemoteDispatch.
Constructor Details
#initialize(endpoint) ⇒ RemoteDispatch
Returns a new instance of RemoteDispatch.
74 75 76 |
# File 'lib/igniter/store/mcp_adapter.rb', line 74 def initialize(endpoint) @uri = normalize_endpoint(endpoint) end |
Instance Method Details
#dispatch(op:, packet:, request_id:) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/igniter/store/mcp_adapter.rb', line 78 def dispatch(op:, packet:, request_id:) envelope = { protocol: :igniter_store, schema_version: SCHEMA_VERSION, request_id: request_id, op: op, packet: packet } request = Net::HTTP::Post.new(@uri) request["Content-Type"] = "application/json" request.body = JSON.generate(envelope) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = @uri.scheme == "https" response = http.request(request) unless response.code.to_i.between?(200, 299) raise "HTTP #{@uri} returned #{response.code}" end JSON.parse(response.body, symbolize_names: true) end |