Class: RubstApi::ServerSentEvent
- Inherits:
-
Data
- Object
- Data
- RubstApi::ServerSentEvent
- Defined in:
- lib/rubst_api/sse.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#retry ⇒ Object
readonly
Returns the value of attribute retry.
Instance Method Summary collapse
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment
4 5 6 |
# File 'lib/rubst_api/sse.rb', line 4 def comment @comment end |
#data ⇒ Object (readonly)
Returns the value of attribute data
4 5 6 |
# File 'lib/rubst_api/sse.rb', line 4 def data @data end |
#event ⇒ Object (readonly)
Returns the value of attribute event
4 5 6 |
# File 'lib/rubst_api/sse.rb', line 4 def event @event end |
#id ⇒ Object (readonly)
Returns the value of attribute id
4 5 6 |
# File 'lib/rubst_api/sse.rb', line 4 def id @id end |
#retry ⇒ Object (readonly)
Returns the value of attribute retry
4 5 6 |
# File 'lib/rubst_api/sse.rb', line 4 def retry @retry end |
Instance Method Details
#encode ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rubst_api/sse.rb', line 5 def encode lines = [] lines << ": #{comment}" if comment lines << "id: #{id}" if id lines << "event: #{event}" if event lines << "retry: #{self.retry}" if self.retry payload = data.is_a?(String) ? data : JSON.generate(Serializer.dump(data)) payload.each_line { |line| lines << "data: #{line.chomp}" } "#{lines.join("\n")}\n\n" end |