Class: Startback::Websocket::Hub::Message
- Inherits:
-
Object
- Object
- Startback::Websocket::Hub::Message
- Defined in:
- lib/startback/websocket/hub/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(data, socket) ⇒ Message
constructor
A new instance of Message.
- #reply(message) ⇒ Object
Constructor Details
#initialize(data, socket) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 |
# File 'lib/startback/websocket/hub/message.rb', line 7 def initialize(data, socket) data = JSON.parse(data, symbolize_names: true) @headers = data[:headers] || {} @body = data[:body] || {} @socket = socket end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/startback/websocket/hub/message.rb', line 13 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
13 14 15 |
# File 'lib/startback/websocket/hub/message.rb', line 13 def headers @headers end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
13 14 15 |
# File 'lib/startback/websocket/hub/message.rb', line 13 def socket @socket end |
Instance Method Details
#reply(message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/startback/websocket/hub/message.rb', line 15 def reply() raise "No reply-to header found" unless headers[:'reply-to'] response = { headers: { :'in-reply-to' => headers[:'reply-to'] }, body: } @socket.send(response.to_json) end |