Class: Kameleoon::RealTime::SseRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/real_time/sse_request.rb

Overview

SseRequest is used keep SSE connection and read from its stream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, headers, open_handler, close_handler, unexpected_status_code_handler) ⇒ SseRequest

Parametrized initializer.

is synchronously called for responses with not 200 status code.

Parameters:

  • url (String)
  • headers (Hash)
  • open_handler (Callable | NilClass)

    Handler which is synchronously called when SSE connection is open.

  • close_handler (Callable | NilClass)

    Handler which is synchronously called when SSE connection is closed.

  • unexpected_status_code_handler (Callable[Net::HTTPResponse] | NilClass)

    Handler whick



21
22
23
24
25
26
27
28
29
# File 'lib/kameleoon/real_time/sse_request.rb', line 21

def initialize(url, headers, open_handler, close_handler, unexpected_status_code_handler)
  @url = url
  @headers = headers
  @open_handler = open_handler
  @close_handler = close_handler
  @unexpected_status_code_handler = unexpected_status_code_handler

  @resp_char_handler = nil
end

Instance Attribute Details

#resp_char_handler=(value) ⇒ Object (writeonly)

Sets the attribute resp_char_handler

Parameters:

  • value

    the value to set the attribute resp_char_handler to.



10
11
12
# File 'lib/kameleoon/real_time/sse_request.rb', line 10

def resp_char_handler=(value)
  @resp_char_handler = value
end

Instance Method Details

#call_close_handlerObject

Calls @close_handler if it is not nil.



40
41
42
# File 'lib/kameleoon/real_time/sse_request.rb', line 40

def call_close_handler
  @close_handler&.call
end

#startObject

Starts SSE connection and stay in the loop until close.



33
34
35
36
# File 'lib/kameleoon/real_time/sse_request.rb', line 33

def start
  RestClient::Request.execute(method: :get, url: @url, headers: @headers, read_timeout: nil,
                              block_response: method(:handle_resp))
end