Class: A2A::Transport::SSEEvent
- Inherits:
-
Object
- Object
- A2A::Transport::SSEEvent
- Defined in:
- lib/a2a/transport/sse.rb
Overview
SSE Event representation
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#retry ⇒ Object
readonly
Returns the value of attribute retry.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#has_data? ⇒ Boolean
Check if event has data.
-
#initialize(type:, data: nil, id: nil, retry_interval: nil) ⇒ SSEEvent
constructor
Initialize SSE event.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_sse_format ⇒ String
Convert event to SSE format.
-
#type?(event_type) ⇒ Boolean
Check if event is of specific type.
Constructor Details
#initialize(type:, data: nil, id: nil, retry_interval: nil) ⇒ SSEEvent
Initialize SSE event
436 437 438 439 440 441 442 |
# File 'lib/a2a/transport/sse.rb', line 436 def initialize(type:, data: nil, id: nil, retry_interval: nil) @type = type.to_s @data = data @id = id @retry = retry_interval @timestamp = Time.now end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
426 427 428 |
# File 'lib/a2a/transport/sse.rb', line 426 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
426 427 428 |
# File 'lib/a2a/transport/sse.rb', line 426 def id @id end |
#retry ⇒ Object (readonly)
Returns the value of attribute retry.
426 427 428 |
# File 'lib/a2a/transport/sse.rb', line 426 def retry @retry end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
426 427 428 |
# File 'lib/a2a/transport/sse.rb', line 426 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
426 427 428 |
# File 'lib/a2a/transport/sse.rb', line 426 def type @type end |
Instance Method Details
#has_data? ⇒ Boolean
Check if event has data
494 495 496 |
# File 'lib/a2a/transport/sse.rb', line 494 def has_data? !@data.nil? end |
#to_h ⇒ Hash
Convert to hash representation
469 470 471 472 473 474 475 476 477 |
# File 'lib/a2a/transport/sse.rb', line 469 def to_h { type: @type, data: @data, id: @id, retry: @retry, timestamp: @timestamp.iso8601 }.compact end |
#to_sse_format ⇒ String
Convert event to SSE format
449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/a2a/transport/sse.rb', line 449 def to_sse_format lines = [] lines << "event: #{@type}" if @type != "message" lines << "id: #{@id}" if @id lines << "retry: #{@retry}" if @retry data_json = @data.is_a?(String) ? @data : @data.to_json data_json.split("\n").each do |line| lines << "data: #{line}" end lines << "" lines.join("\n") end |
#type?(event_type) ⇒ Boolean
Check if event is of specific type
485 486 487 |
# File 'lib/a2a/transport/sse.rb', line 485 def type?(event_type) @type == event_type.to_s end |