class RJR::Result

JSON-RPC Result Representation

Attributes

error_class[RW]

Class of error raised (if any) during request invocation (this is extra metadata beyond standard json-rpc)

error_code[RW]

Code corresponding to json-rpc error if problem occured during request invocation

error_msg[RW]

Message corresponding to json-rpc error if problem occured during request invocation

failed[RW]

Boolean indicating if request failed in some manner

result[RW]

Return value of the json-rpc call if successful

success[RW]

Boolean indicating if request was successfully invoked

Public Class Methods

invalid_request() click to toggle source

JSON-RPC -32600 / Invalid Request

# File lib/rjr/result.rb, line 63
def self.invalid_request
   return Result.new(:error_code => -32600,
                     :error_msg => 'Invalid Request')
end
method_not_found(name) click to toggle source

JSON-RPC -32602 / Method not found

# File lib/rjr/result.rb, line 69
def self.method_not_found(name)
   return Result.new(:error_code => -32602,
                     :error_msg => "Method '#{name}' not found")
end
new(args = {}) click to toggle source

RJR result intializer @param [Hash] args options to set on result @option args [Object] :result result of json-rpc method handler if successfully returned @option args [Integer] :error_code code corresponding to json-rpc error if problem occured during request invocation @option args [String] :error_msg message corresponding to json-rpc error if problem occured during request invocation @option args [Class] :error_class class of error raised (if any) during request invocation (this is extra metadata beyond standard json-rpc)

# File lib/rjr/result.rb, line 34
def initialize(args = {})
  @result        = args[:result]      || args['result']
  @error_code    = args[:error_code]  || args['error_code']
  @error_msg     = args[:error_msg]   || args['error_msg']
  @error_class   = args[:error_class] || args['error_class']

  @success       =  @error_code.nil?
  @failed        = !@error_code.nil?
end

Public Instance Methods

==(other) click to toggle source

Compare Result against other result, returning true if both correspond to equivalent json-rpc results else false

# File lib/rjr/result.rb, line 46
def ==(other)
  @success     == other.success    &&
  @failed      == other.failed     &&
  @result      == other.result     &&
  @error_code  == other.error_code &&
  @error_msg   == other.error_msg  &&
  @error_class == other.error_class
end
to_s() click to toggle source

Convert Response to human consumable string

# File lib/rjr/result.rb, line 56
def to_s
  "#{@success} #{@result} #{@error_code} #{@error_msg} #{@error_class}"
end