Class: Kameleoon::RealTime::SseRequest
- Inherits:
-
Object
- Object
- Kameleoon::RealTime::SseRequest
- 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
-
#resp_char_handler ⇒ Object
writeonly
Sets the attribute resp_char_handler.
Instance Method Summary collapse
-
#call_close_handler ⇒ Object
Calls @close_handler if it is not nil.
-
#initialize(url, headers, open_handler, close_handler, unexpected_status_code_handler) ⇒ SseRequest
constructor
Parametrized initializer.
-
#start ⇒ Object
Starts SSE connection and stay in the loop until close.
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.
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
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_handler ⇒ Object
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 |
#start ⇒ Object
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 |