Class: RJR::Messages::Response
Overview
Message sent from server to client in response to a JSON-RPC request
Instance Attribute Summary collapse
-
#headers ⇒ Object
Optional headers to add to json outside of standard json-rpc request.
-
#message ⇒ Object
Message string received from the source.
-
#msg_id ⇒ Object
ID of the message in accordance w/ json-rpc specification.
-
#result ⇒ Object
Result encapsulated in the response message.
Class Method Summary collapse
-
.is_response_message?(message) ⇒ true, false
Class helper to determine if the specified string is a valid json-rpc method response.
Instance Method Summary collapse
- #error_json ⇒ Object
-
#initialize(args = {}) ⇒ Response
constructor
ResponseMessage initializer.
- #success_json ⇒ Object
-
#to_json(*a) ⇒ Object
Convert request message to json.
-
#to_s ⇒ Object
Convert request to string format.
Constructor Details
#initialize(args = {}) ⇒ Response
ResponseMessage initializer
37 38 39 |
# File 'lib/rjr/messages/response.rb', line 37 def initialize(args = {}) parse_args(args) end |
Instance Attribute Details
#headers ⇒ Object
Optional headers to add to json outside of standard json-rpc request
26 27 28 |
# File 'lib/rjr/messages/response.rb', line 26 def headers @headers end |
#message ⇒ Object
Message string received from the source
16 17 18 |
# File 'lib/rjr/messages/response.rb', line 16 def @message end |
#msg_id ⇒ Object
ID of the message in accordance w/ json-rpc specification
19 20 21 |
# File 'lib/rjr/messages/response.rb', line 19 def msg_id @msg_id end |
#result ⇒ Object
Result encapsulated in the response message
23 24 25 |
# File 'lib/rjr/messages/response.rb', line 23 def result @result end |
Class Method Details
.is_response_message?(message) ⇒ true, false
Class helper to determine if the specified string is a valid json-rpc method response
91 92 93 |
# File 'lib/rjr/messages/response.rb', line 91 def self.() .has?('result') || .has?('error') end |
Instance Method Details
#error_json ⇒ Object
99 100 101 102 103 |
# File 'lib/rjr/messages/response.rb', line 99 def error_json {'error' => {'code' => @result.error_code, 'message' => @result.error_msg, 'class' => @result.error_class}} end |
#success_json ⇒ Object
95 96 97 |
# File 'lib/rjr/messages/response.rb', line 95 def success_json {'result' => @result.result} end |
#to_json(*a) ⇒ Object
Convert request message to json
106 107 108 109 110 111 112 |
# File 'lib/rjr/messages/response.rb', line 106 def to_json(*a) result_json = @result.success ? success_json : error_json {'jsonrpc' => '2.0', 'id' => @msg_id}.merge(@headers). merge(result_json).to_json(*a) end |
#to_s ⇒ Object
Convert request to string format
115 116 117 |
# File 'lib/rjr/messages/response.rb', line 115 def to_s to_json.to_s end |