Class: RJR::Result
Overview
JSON-RPC result representation
Instance Attribute Summary collapse
-
#error_class ⇒ Object
Class of error raised (if any) during request invocation (this is extra metadata beyond standard json-rpc).
-
#error_code ⇒ Object
Code corresponding to json-rpc error if problem occured during request invocation.
-
#error_msg ⇒ Object
Message corresponding to json-rpc error if problem occured during request invocation.
-
#failed ⇒ Object
Boolean indicating if request failed in some manner.
-
#result ⇒ Object
Return value of the json-rpc call if successful.
-
#success ⇒ Object
Boolean indicating if request was successfully invoked.
Class Method Summary collapse
-
.invalid_request ⇒ Object
JSON-RPC -32600 / Invalid Request.
-
.method_not_found(name) ⇒ Object
JSON-RPC -32602 / Method not found.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare Result against other result, returning true if both correspond to equivalent json-rpc results else false.
-
#initialize(args = {}) ⇒ Result
constructor
RJR result intializer.
-
#to_s ⇒ Object
Convert Response to human consumable string.
Constructor Details
#initialize(args = {}) ⇒ Result
RJR result intializer
40 41 42 43 44 45 46 47 48 |
# File 'lib/rjr/dispatcher.rb', line 40 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 |
Instance Attribute Details
#error_class ⇒ Object
Class of error raised (if any) during request invocation (this is extra metadata beyond standard json-rpc)
32 33 34 |
# File 'lib/rjr/dispatcher.rb', line 32 def error_class @error_class end |
#error_code ⇒ Object
Code corresponding to json-rpc error if problem occured during request invocation
26 27 28 |
# File 'lib/rjr/dispatcher.rb', line 26 def error_code @error_code end |
#error_msg ⇒ Object
Message corresponding to json-rpc error if problem occured during request invocation
29 30 31 |
# File 'lib/rjr/dispatcher.rb', line 29 def error_msg @error_msg end |
#failed ⇒ Object
Boolean indicating if request failed in some manner
20 21 22 |
# File 'lib/rjr/dispatcher.rb', line 20 def failed @failed end |
#result ⇒ Object
Return value of the json-rpc call if successful
23 24 25 |
# File 'lib/rjr/dispatcher.rb', line 23 def result @result end |
#success ⇒ Object
Boolean indicating if request was successfully invoked
17 18 19 |
# File 'lib/rjr/dispatcher.rb', line 17 def success @success end |
Class Method Details
.invalid_request ⇒ Object
JSON-RPC -32600 / Invalid Request
69 70 71 72 |
# File 'lib/rjr/dispatcher.rb', line 69 def self.invalid_request return Result.new(:error_code => -32600, :error_msg => ' Invalid Request') end |
.method_not_found(name) ⇒ Object
JSON-RPC -32602 / Method not found
75 76 77 78 |
# File 'lib/rjr/dispatcher.rb', line 75 def self.method_not_found(name) return Result.new(:error_code => -32602, :error_msg => "Method '#{name}' not found") end |
Instance Method Details
#==(other) ⇒ Object
Compare Result against other result, returning true if both correspond to equivalent json-rpc results else false
52 53 54 55 56 57 58 59 |
# File 'lib/rjr/dispatcher.rb', line 52 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 ⇒ Object
Convert Response to human consumable string
62 63 64 |
# File 'lib/rjr/dispatcher.rb', line 62 def to_s "#{@success} #{@result} #{@error_code} #{@error_msg} #{@error_class}" end |