Object
Implements the base class for all Clients. The class get all methode calls generate the json data from it
Every client must implement get_response and send_request.
client.request("run", [1,2,3]) # calls: run params: 1 2 3 ret = client.request("attack", "alpha", 1, 3.0) # calls: attack # params "alpha", 1, 3.0 # returns data into ret
client.run([1,2,3]) ret = client.attack("alpha", 1, 3.0)
client.notification("beat", [:alpha, 123], "fast")
returns the server response must be implmented
# File lib/rawjsonrpc/client.rb, line 52 def get_response raise NotImplementedError.new("method not overriden") end
redirect calls
# File lib/rawjsonrpc/client.rb, line 36 def method_missing(name, *args) if args.empty? request(name) else request(name, *args) end end
Sends a notification to server. A Notifications don’t return any value
# File lib/rawjsonrpc/client.rb, line 65 def notification(function_name, *para) para = {'method' => function_name, 'params' => para, 'id' => nil} .to_json send_request para nil end
Sends a request to server return a value or raise an RpcException if server sends an error.
# File lib/rawjsonrpc/client.rb, line 73 def request(function_name, *para) id_count = id para = {'method' => function_name, 'params' => para, 'id' => id_count} .to_json send_request(para) result = get_response if result.empty? or result == nil raise(RpcError.new("empty respons")) end response = JSON.load(result) if response["error"] != nil raise(RpcError.new(response["error"])) elsif response["id"] != id_count raise(RpcError.new("server send wrong data.")) end response["result"] end
Generated with the Darkfish Rdoc Generator 2.