Class: Factor::Runtime::ServiceCaller

Inherits:
Object
  • Object
show all
Defined in:
lib/runtime/service_caller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connector_url, options = {}) ⇒ ServiceCaller

Returns a new instance of ServiceCaller.



9
10
11
12
13
14
15
16
# File 'lib/runtime/service_caller.rb', line 9

def initialize(connector_url, options = {})
  @url = connector_url
  @subscribers = {}
  @reconnect = options[:reconnect] || true
  @retry_period = options[:retry_period] || 5
  @retry_count = 0
  @offline_duration = 0
end

Instance Attribute Details

#reconnectObject

Returns the value of attribute reconnect.



7
8
9
# File 'lib/runtime/service_caller.rb', line 7

def reconnect
  @reconnect
end

#retry_periodObject

Returns the value of attribute retry_period.



7
8
9
# File 'lib/runtime/service_caller.rb', line 7

def retry_period
  @retry_period
end

Instance Method Details

#action(action_id, params = {}) ⇒ Object



23
24
25
26
# File 'lib/runtime/service_caller.rb', line 23

def action(action_id, params={})
  @reconnect = false
  call("#{@url}/actions/#{action_id}", params)
end

#closeObject



28
29
30
# File 'lib/runtime/service_caller.rb', line 28

def close
  @ws.close
end

#listen(listener_id, params = {}) ⇒ Object



18
19
20
21
# File 'lib/runtime/service_caller.rb', line 18

def listen(listener_id, params={})
  @reconnect = true
  call("#{@url}/listeners/#{listener_id}", params)
end

#on(event, &block) ⇒ Object



32
33
34
35
36
# File 'lib/runtime/service_caller.rb', line 32

def on(event, &block)
  @subscribers ||= {}
  @subscribers[event.to_sym] ||= []
  @subscribers[event.to_sym] << block
end