From 472596a328e09d4c6abb73a7645d23cbabb59c53 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 4 Oct 2011 14:00:56 -0600 Subject: [PATCH 1/2] allow query parameters in the endpoint URL --- lib/jsonrpc.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jsonrpc.rb b/lib/jsonrpc.rb index 4e8518c..a128888 100644 --- a/lib/jsonrpc.rb +++ b/lib/jsonrpc.rb @@ -18,7 +18,8 @@ def request(method, params) 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}" : "") + result = JSON.parse(connection.post(path, {:method => method.to_s, :params => params}.to_json, h).body) end if error = result["error"] raise JsonRPCError, error["message"] From d0a466fa22d6cf85eb6a353dab6252c6003b2e31 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 4 Oct 2011 14:17:00 -0600 Subject: [PATCH 2/2] add an 'id' parameter to requests to satisfy peers who follow the "spec" strictly Issues: - totally not threadsafe - ignores the id in the response --- lib/jsonrpc.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/jsonrpc.rb b/lib/jsonrpc.rb index a128888..5c7bd09 100644 --- a/lib/jsonrpc.rb +++ b/lib/jsonrpc.rb @@ -11,15 +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| path = @address.path + (@address.query ? "?#{@address.query}" : "") - result = JSON.parse(connection.post(path, {:method => method.to_s, :params => params}.to_json, h).body) + 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"]