Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


allow endpoints with query parameters, include request id #3

wants to merge 2 commits into from

2 participants

bct commented

just some minor tweaks i had to do to get this working with Mashery's API.

bct added some commits

Nice additions: @dbussink: if you're looking for an endpoint that actually requires an 'id' parameter, try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2011
  1. @bct
  2. @bct

    add an 'id' parameter to requests to satisfy peers who follow the "sp…

    bct authored
    …ec" strictly
    - totally not threadsafe
    - ignores the id in the response
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/jsonrpc.rb
6 lib/jsonrpc.rb
@@ -11,14 +11,18 @@ class Client
def initialize(url)
@address = Addressable::URI.parse(url)
+ @id = 0
def request(method, params)
+ @id += 1
result = {}
params ||= {}
h = {"Content-Type" => "application/json"}
Net::HTTP.start(, @address.port) do |connection|
- result = JSON.parse(, {: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(, body.to_json, h).body)
if error = result["error"]
raise JsonRPCError, error["message"]
Something went wrong with that request. Please try again.