Class: RJR::Messages::Notification
- Defined in:
- lib/rjr/messages/notification.rb
Overview
Message sent to a JSON-RPC server 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 = {}) ⇒ Notification
constructor
RJR Notification Message initializer.
-
#to_json(*a) ⇒ Object
Convert notification message to json.
-
#to_s ⇒ Object
Convert request to string format.
Constructor Details
#initialize(args = {}) ⇒ Notification
RJR Notification Message initializer
No message id will be generated in accordance w/ the jsonrpc standard
36 37 38 |
# File 'lib/rjr/messages/notification.rb', line 36 def initialize(args = {}) parse_args(args) end |
Instance Attribute Details
#headers ⇒ Object
Optional headers to add to json outside of standard json-rpc request
25 26 27 |
# File 'lib/rjr/messages/notification.rb', line 25 def headers @headers end |
#jr_args ⇒ Object
Arguments source is passing to destination method
22 23 24 |
# File 'lib/rjr/messages/notification.rb', line 22 def jr_args @jr_args end |
#jr_method ⇒ Object
Method source is invoking on the destination
19 20 21 |
# File 'lib/rjr/messages/notification.rb', line 19 def jr_method @jr_method end |
#json_message ⇒ Object
Message string received from the source
16 17 18 |
# File 'lib/rjr/messages/notification.rb', line 16 def @json_message end |
Class Method Details
.is_notification_message?(message) ⇒ true, false
Class helper to determine if the specified string is a valid json-rpc notification
72 73 74 75 76 77 78 79 80 |
# File 'lib/rjr/messages/notification.rb', line 72 def self.() begin # FIXME log error parsed = JSONParser.parse() parsed.has_key?('method') && !parsed.has_key?('id') rescue Exception => e false end end |
Instance Method Details
#to_json(*a) ⇒ Object
Convert notification message to json
83 84 85 86 87 |
# File 'lib/rjr/messages/notification.rb', line 83 def to_json(*a) {'jsonrpc' => '2.0', 'method' => @jr_method, 'params' => @jr_args}.merge(@headers).to_json(*a) end |
#to_s ⇒ Object
Convert request to string format
90 91 92 |
# File 'lib/rjr/messages/notification.rb', line 90 def to_s to_json.to_s end |