Class: JsonRPC::Client
- Inherits:
-
Object
- Object
- JsonRPC::Client
- Defined in:
- lib/jsonrpc.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
- #request(method, params) ⇒ Object
Constructor Details
#initialize(url) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/jsonrpc.rb', line 12 def initialize(url) @address = Addressable::URI.parse(url) end |
Instance Method Details
#request(method, params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jsonrpc.rb', line 16 def request(method, params) result = {} params ||= {} h = {"Content-Type" => "application/json"} Net::HTTP.start(@address.host, @address.port) do |connection| result = JSON.parse(connection.post(@address.path, {:method => method.to_s, :params => params}.to_json, h).body) end if error = result["error"] raise JsonRPCError, error["message"] end result end |