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.
-
#json_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 |
#json_message ⇒ Object
Message string received from the source
16 17 18 |
# File 'lib/rjr/messages/response.rb', line 16 def 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 94 95 96 97 98 99 100 |
# File 'lib/rjr/messages/response.rb', line 91 def self.() begin # FIXME log error json = JSONParser.parse() json.has_key?('result') || json.has_key?('error') rescue Exception => e puts e.to_s false end end |
Instance Method Details
#error_json ⇒ Object
106 107 108 109 110 |
# File 'lib/rjr/messages/response.rb', line 106 def error_json {'error' => {'code' => @result.error_code, 'message' => @result.error_msg, 'class' => @result.error_class}} end |
#success_json ⇒ Object
102 103 104 |
# File 'lib/rjr/messages/response.rb', line 102 def success_json {'result' => @result.result} end |
#to_json(*a) ⇒ Object
Convert request message to json
113 114 115 116 117 118 119 |
# File 'lib/rjr/messages/response.rb', line 113 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
122 123 124 |
# File 'lib/rjr/messages/response.rb', line 122 def to_s to_json.to_s end |