Class: JSONRPC::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/jsonrpc/client.rb

Constant Summary

Constants inherited from Base

Base::JSON_RPC_VERSION

Instance Method Summary collapse

Methods inherited from Base

#class, #initialize, #inspect, make_id, #to_s

Constructor Details

This class inherits a constructor from JSONRPC::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



144
145
146
# File 'lib/jsonrpc/client.rb', line 144

def method_missing(method, *args, &block)
  invoke(method, args)
end

Instance Method Details

#invoke(method, args, options = nil) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/jsonrpc/client.rb', line 148

def invoke(method, args, options = nil)
  resp = send_single_request(method.to_s, args, options)

  begin
    data = ::MultiJson.decode(resp, ::JSONRPC.decode_options)
  rescue
    raise ::JSONRPC::Error::InvalidJSON.new(resp)
  end

  process_single_response(data)
rescue => e
  e.extend(::JSONRPC::Error)
  raise
end