Module: Sinatra::JsonRpc::Helpers

Defined in:
lib/sinatra/json_rpc.rb

Instance Method Summary collapse

Instance Method Details

#send_error(code, data = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/json_rpc.rb', line 13

def send_error(code, data = nil)
  resp = Sinatra::JsonRpc::Response.new
  if @rpc_req
    resp.id = @rpc_req.id unless @rpc_req.id.nil?
  end
  resp.error = code
  resp.error.data = data unless data.nil?
  resp.to_json
end

#send_result(result) ⇒ Object



23
24
25
26
27
28
# File 'lib/sinatra/json_rpc.rb', line 23

def send_result(result)
  halt 204 if @rpc_req.id.nil? # JSON-RPC requests without an ID are notifications, requiring
  resp = Sinatra::JsonRpc::Response.new(@rpc_req.id)
  resp.result = result
  resp.to_json
end