Class: SSE::EventSource

Inherits:
Object
  • Object
show all
Defined in:
lib/sse-client.rb

Constant Summary collapse

CONNECTING =

The connection has not yet been established, or it was closed and the user agent is reconnecting.

0
OPEN =

The user agent has an open connection and is dispatching events as it receives them.

1
CLOSED =

The connection is not open, and the user agent is not trying to reconnect. Either there was a fatal error or the close() method was invoked.

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = "http://localhost:2333/portal/app_api_call_stats?begin=2017-09-30&end=2017-10-31&interval=day&app_id=8ab88b1d", query = {}, headers = {}) ⇒ EventSource

Returns a new instance of EventSource.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sse-client.rb', line 19

def initialize(url = "http://localhost:2333/portal/app_api_call_stats?begin=2017-09-30&end=2017-10-31&interval=day&app_id=8ab88b1d", query = {}, headers = {})
  @url = url
  @headers = headers
  @headers['params'] = query
  @ready_state = CLOSED

  @opens = []
  @errors = []
  @messages = []
  @on = {}
end

Instance Attribute Details

#ready_stateObject (readonly)

Get ready state



10
11
12
# File 'lib/sse-client.rb', line 10

def ready_state
  @ready_state
end

#urlObject (readonly)

Get API url



8
9
10
# File 'lib/sse-client.rb', line 8

def url
  @url
end

Instance Method Details

#error(&block) ⇒ Object



49
50
51
# File 'lib/sse-client.rb', line 49

def error(&block)
  @errors << block
end

#message(&block) ⇒ Object



45
46
47
# File 'lib/sse-client.rb', line 45

def message(&block)
  @messages << block
end

#on(name, &block) ⇒ Object



40
41
42
43
# File 'lib/sse-client.rb', line 40

def on(name, &block)
  @on[name] ||= []
  @on[name] << block
end

#open(&block) ⇒ Object



36
37
38
# File 'lib/sse-client.rb', line 36

def open(&block)
  @opens << block
end

#startObject



31
32
33
34
# File 'lib/sse-client.rb', line 31

def start
  @ready_state = CONNECTING
  listen
end