class RJR::Messages::Notification
Message sent to a JSON-RPC server to invoke a rpc method but indicate the result should not be returned
Attributes
Optional headers to add to json outside of standard json-rpc request
Arguments
source is passing to destination method
Method source is invoking on the destination
Message string received from the source
Public Class Methods
Class
helper to determine if the specified string is a valid json-rpc notification
@param [String] message string message to check @return [true,false] indicating if message is a notification message
# File lib/rjr/messages/notification.rb, line 71 def self.is_notification_message?(message) message.has?('method') && !message.has?('id') end
RJR
Notification
Message initializer
No message id will be generated in accordance w/ the jsonrpc standard
@param [Hash] args options to set on request @option args [String] :message json string received from sender @option args [Hash] :headers optional headers to set in request and subsequent messages @option args [String] :method method to invoke on server @option args [Array<Object>] :args to pass to server method, all must be convertable to/from json
# File lib/rjr/messages/notification.rb, line 36 def initialize(args = {}) parse_args(args) end
Public Instance Methods
Convert notification message to json
# File lib/rjr/messages/notification.rb, line 76 def to_json(*a) {'jsonrpc' => '2.0', 'method' => @jr_method, 'params' => @jr_args}.merge(@headers).to_json(*a) end
Convert request to string format
# File lib/rjr/messages/notification.rb, line 83 def to_s to_json.to_s end
Private Instance Methods
# File lib/rjr/messages/notification.rb, line 42 def parse_args(args) @jr_method = args[:method] @jr_args = args[:args] || [] @headers = args[:headers] || {} parse_message(args[:message]) if args.has_key?(:message) end
# File lib/rjr/messages/notification.rb, line 58 def parse_headers(message) message.keys.select { |k| !['jsonrpc', 'method', 'params'].include?(k) }.each { |k| @headers[k] = message[k] } end
# File lib/rjr/messages/notification.rb, line 50 def parse_message(message) @message = message @jr_method = message['method'] @jr_args = message['params'] parse_headers(message) end