diff --git a/lib/jsonrpc.rb b/lib/jsonrpc.rb index 4e8518c..5c7bd09 100644 --- a/lib/jsonrpc.rb +++ b/lib/jsonrpc.rb @@ -11,14 +11,18 @@ class Client def initialize(url) @address = Addressable::URI.parse(url) + @id = 0 end def request(method, params) + @id += 1 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) + path = @address.path + (@address.query ? "?#{@address.query}" : "") + body = {:method => method.to_s, :params => params, :id => @id} + result = JSON.parse(connection.post(path, body.to_json, h).body) end if error = result["error"] raise JsonRPCError, error["message"]