Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow endpoints with query parameters, include request id #3

Open
wants to merge 2 commits into from

2 participants

@bct
bct commented

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

bct added some commits
@murb

Nice additions: @dbussink: if you're looking for an endpoint that actually requires an 'id' parameter, try http://uitinenschede.nl/api/json/

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
    
    Issues:
    - 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
View
6 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"]
Something went wrong with that request. Please try again.