Implements the basic server functions When implementing a new server type you must only give a jsonstring to the execute function.
Add Functions
server.add_method("run", methode(:test)) #adds methode test as "run" server.add_block("attack"){ |target, dir, times| #stuff }
Adds blocks that get executed Arguments can not checkt because they are procs no lambdas if you can provied a hack plz contribute.
# File lib/rawjsonrpc/server.rb, line 36 def add_block(name, &block) @rawjsonrpc_blocks ||= {} @rawjsonrpc_funcs ||= {} @rawjsonrpc_blocks[name] = block end
Handels json string input and calls the methode and returns a return string or nil if its a notification.
# File lib/rawjsonrpc/server.rb, line 44 def execute(input) begin request_data = JSON.load(input) @rawjsonrpc_noti = if request_data["id"] == nil then true else false end @rawjsonrpc_id = request_data["id"] if @rawjsonrpc_funcs.has_key?(request_data["method"]) ret = @rawjsonrpc_funcs[request_data["method"]].call(*request_data["params"]) elsif @rawjsonrpc_blocks.has_key?(request_data["method"]) ret = @rawjsonrpc_blocks[request_data["method"]].call(*request_data["params"]) else @rawjsonrpc_back = request_data raise("No Methode") end if request_data["id"] != nil response_data = {"result" => ret, "error" => nil, "id" => request_data["id"]} .to_json else nil end rescue => ex unless @rawjsonrpc_noti response = {"result" => nil, "error" => ex.message, "id" => @rawjsonrpc_id}.to_json end end end
Generated with the Darkfish Rdoc Generator 2.