Class: RJR::NotificationMessage
Overview
Message sent to a jsonrpc node to invoke a rpc method but indicate the result should not be returned
Instance Attribute Summary collapse
-
#headers ⇒ Object
Optional headers to add to json outside of standard json-rpc request.
-
#jr_args ⇒ Object
Arguments source is passing to destination method.
-
#jr_method ⇒ Object
Method source is invoking on the destination.
-
#json_message ⇒ Object
Message string received from the source.
Class Method Summary collapse
-
.is_notification_message?(message) ⇒ true, false
Class helper to determine if the specified string is a valid json-rpc notification.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ NotificationMessage
constructor
RJR Notification Message initializer.
-
#to_s ⇒ Object
Convert notification message to string json format.
Constructor Details
#initialize(args = {}) ⇒ NotificationMessage
RJR Notification Message initializer
This should be invoked with one of two argument sets. If creating a new message to send to the server, specify :method, :args, and :headers to include in the message If handling an new request message sent from the client, simply specify :message and optionally any additional headers (they will be merged with the headers contained in the message)
No message id will be generated in accordance w/ the jsonrpc standard
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/rjr/message.rb', line 227 def initialize(args = {}) if args.has_key?(:message) begin = args[:message] notification = RJR.parse_json() @jr_method = notification['method'] @jr_args = notification['params'] @headers = args.has_key?(:headers) ? {}.merge!(args[:headers]) : {} notification.keys.select { |k| !['jsonrpc', 'method', 'params'].include?(k) }.each { |k| @headers[k] = notification[k] } rescue Exception => e #puts "Exception Parsing Notification #{e}" raise e end elsif args.has_key?(:method) @jr_method = args[:method] @jr_args = args[:args] @headers = args[:headers] end end |
Instance Attribute Details
#headers ⇒ Object
Optional headers to add to json outside of standard json-rpc request
210 211 212 |
# File 'lib/rjr/message.rb', line 210 def headers @headers end |
#jr_args ⇒ Object
Arguments source is passing to destination method
207 208 209 |
# File 'lib/rjr/message.rb', line 207 def jr_args @jr_args end |
#jr_method ⇒ Object
Method source is invoking on the destination
204 205 206 |
# File 'lib/rjr/message.rb', line 204 def jr_method @jr_method end |
#json_message ⇒ Object
Message string received from the source
201 202 203 |
# File 'lib/rjr/message.rb', line 201 def end |
Class Method Details
.is_notification_message?(message) ⇒ true, false
Class helper to determine if the specified string is a valid json-rpc notification
258 259 260 261 262 263 264 265 266 |
# File 'lib/rjr/message.rb', line 258 def self.() begin # FIXME log error parsed = RJR.parse_json() parsed.has_key?('method') && !parsed.has_key?('id') rescue Exception => e false end end |
Instance Method Details
#to_s ⇒ Object
Convert notification message to string json format
269 270 271 272 273 274 275 |
# File 'lib/rjr/message.rb', line 269 def to_s notification = { 'jsonrpc' => '2.0', 'method' => @jr_method, 'params' => @jr_args } notification.merge!(@headers) unless @headers.nil? notification.to_json.to_s end |