Class: JSONBroker::JsonRpcRequestor
- Inherits:
-
Object
- Object
- JSONBroker::JsonRpcRequestor
- Defined in:
- lib/jiji/util/json_rpc_requestor.rb
Overview
クライアント
Instance Method Summary collapse
-
#initialize(name, host = "http://localhost:8080", proxy = nil) ⇒ JsonRpcRequestor
constructor
A new instance of JsonRpcRequestor.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(name, host = "http://localhost:8080", proxy = nil) ⇒ JsonRpcRequestor
Returns a new instance of JsonRpcRequestor.
12 13 14 15 16 17 |
# File 'lib/jiji/util/json_rpc_requestor.rb', line 12 def initialize( name, host="http://localhost:8080", proxy=nil ) @client = HTTPClient.new( proxy, "JsonClientLib") @client.("cookie.dat") @name = name @host = host end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jiji/util/json_rpc_requestor.rb', line 18 def method_missing( name, *args ) body = CGI.escape("{\"method\":#{name.to_s},\"params\":#{args.to_json}}") result = @client.post("#{@host}/json/#{@name}", body ) json = JSON::Lexer.new(result.content).nextvalue[0] if json["error"] raise json["error"] else json["result"] end end |