Class: Spikard::SseEvent
- Inherits:
-
Object
- Object
- Spikard::SseEvent
- Defined in:
- lib/spikard/sse.rb
Overview
Represents a Server-Sent Event.
Instance Attribute Summary collapse
-
#data ⇒ Hash
Event data (will be JSON serialized).
-
#event_type ⇒ String?
Optional event type.
-
#id ⇒ String?
Optional event ID for client reconnection support.
-
#retry_ms ⇒ Integer?
Optional retry timeout in milliseconds.
Instance Method Summary collapse
-
#initialize(data:, event_type: nil, id: nil, retry_ms: nil) ⇒ SseEvent
constructor
Create a new SSE event.
-
#to_h ⇒ Hash
Convert to hash for JSON serialization.
Constructor Details
#initialize(data:, event_type: nil, id: nil, retry_ms: nil) ⇒ SseEvent
Create a new SSE event.
23 24 25 26 27 28 |
# File 'lib/spikard/sse.rb', line 23 def initialize(data:, event_type: nil, id: nil, retry_ms: nil) @data = data @event_type = event_type @id = id @retry_ms = retry_ms end |
Instance Attribute Details
#data ⇒ Hash
Returns Event data (will be JSON serialized).
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spikard/sse.rb', line 14 class SseEvent attr_accessor :data, :event_type, :id, :retry_ms # Create a new SSE event. # # @param data [Hash] Event data (will be JSON serialized) # @param event_type [String, nil] Optional event type # @param id [String, nil] Optional event ID for client reconnection support # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds def initialize(data:, event_type: nil, id: nil, retry_ms: nil) @data = data @event_type = event_type @id = id @retry_ms = retry_ms end # Convert to hash for JSON serialization. # # @return [Hash] Hash representation of the event def to_h { data: @data, event_type: @event_type, id: @id, retry: @retry_ms }.compact end end |
#event_type ⇒ String?
Returns Optional event type.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spikard/sse.rb', line 14 class SseEvent attr_accessor :data, :event_type, :id, :retry_ms # Create a new SSE event. # # @param data [Hash] Event data (will be JSON serialized) # @param event_type [String, nil] Optional event type # @param id [String, nil] Optional event ID for client reconnection support # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds def initialize(data:, event_type: nil, id: nil, retry_ms: nil) @data = data @event_type = event_type @id = id @retry_ms = retry_ms end # Convert to hash for JSON serialization. # # @return [Hash] Hash representation of the event def to_h { data: @data, event_type: @event_type, id: @id, retry: @retry_ms }.compact end end |
#id ⇒ String?
Returns Optional event ID for client reconnection support.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spikard/sse.rb', line 14 class SseEvent attr_accessor :data, :event_type, :id, :retry_ms # Create a new SSE event. # # @param data [Hash] Event data (will be JSON serialized) # @param event_type [String, nil] Optional event type # @param id [String, nil] Optional event ID for client reconnection support # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds def initialize(data:, event_type: nil, id: nil, retry_ms: nil) @data = data @event_type = event_type @id = id @retry_ms = retry_ms end # Convert to hash for JSON serialization. # # @return [Hash] Hash representation of the event def to_h { data: @data, event_type: @event_type, id: @id, retry: @retry_ms }.compact end end |
#retry_ms ⇒ Integer?
Returns Optional retry timeout in milliseconds.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spikard/sse.rb', line 14 class SseEvent attr_accessor :data, :event_type, :id, :retry_ms # Create a new SSE event. # # @param data [Hash] Event data (will be JSON serialized) # @param event_type [String, nil] Optional event type # @param id [String, nil] Optional event ID for client reconnection support # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds def initialize(data:, event_type: nil, id: nil, retry_ms: nil) @data = data @event_type = event_type @id = id @retry_ms = retry_ms end # Convert to hash for JSON serialization. # # @return [Hash] Hash representation of the event def to_h { data: @data, event_type: @event_type, id: @id, retry: @retry_ms }.compact end end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash for JSON serialization.
33 34 35 36 37 38 39 40 |
# File 'lib/spikard/sse.rb', line 33 def to_h { data: @data, event_type: @event_type, id: @id, retry: @retry_ms }.compact end |