rlibs/json_client.rb
def call(methodname, arghash={})
        arghash.is_a?(Hash) or raise "must pass hash args"
    
        envelope = {
          'method' => methodname,
          'params' => arghash
        }
        
        puts '--------------------'
        puts envelope.to_json
        puts '--------------------'
        
        body = Net::HTTP.new(@uri.host, @uri.port).post(@uri.path, envelope.to_json, {'Content-Type' => 'application/json'}).body
        jr = JSON.parse(body) || {} rescue {}
        
        puts '--------------------'
        puts body
        puts '--------------------'
        
        if jr['error']
          # some lazy jsonrpc implementations just have a string here
          raise JSONRPCError, jr['error'].to_s if !jr['error'].is_a?(Hash)
    
          e = JSONRPCError.new(jr['error']['message'])
          e.code = jr['error']['code']
          e.error = jr['error']['error']
          raise e
        end
        
        return jr['result'] || "JSON parse error... (#{body})"
      end
# can use symbols for arg names if you want
can use symbols for arg names if you want
can use symbols for arg names if you want
def call(methodname, arghash={})
        arghash.is_a?(Hash) or raise "must pass hash args"
        envelope = {
          'method' => methodname,
          'params' => arghash
        }
        puts '--------------------'
        puts envelope.to_json
        puts '--------------------'
        body = Net::HTTP.new(@uri.host, @uri.port).post(@uri.path, envelope.to_json, {'Content-Type' => 'application/json'}).body
        jr = JSON.parse(body) || {} rescue {}
        puts '--------------------'
        puts body
        puts '--------------------'
        if jr['error']
          raise JSONRPCError, jr['error'].to_s if !jr['error'].is_a?(Hash)
          e = JSONRPCError.new(jr['error']['message'])
          e.code = jr['error']['code']
          e.error = jr['error']['error']
          raise e
        end
        return jr['result'] || "JSON parse error... (#{body})"
      end
def call ( methodname , arghash = { } ) arghash . is_a? ( Hash ) or raise "must pass hash args" envelope = { 'method' => methodname , 'params' => arghash } puts '--------------------' puts envelope . to_json puts '--------------------' body = Net :: HTTP . new ( @uri . host , @uri . port ) . post ( @uri . path , envelope . to_json , { 'Content-Type' => 'application/json' } ) . body jr = JSON . parse ( body ) || { } rescue { } puts '--------------------' puts body puts '--------------------' if jr [ 'error' ] raise JSONRPCError , jr [ 'error' ] . to_s if ! jr [ 'error' ] . is_a? ( Hash ) e = JSONRPCError . new ( jr [ 'error' ] [ 'message' ] ) e . code = jr [ 'error' ] [ 'code' ] e . error = jr [ 'error' ] [ 'error' ] raise e end return jr [ 'result' ] || "JSON parse error... (#{body})" end
can use symbols for arg names if you want
can use symbols for arg names if you want
# some lazy jsonrpc implementations just have a string here
methodname
arghash