Class: Factor::Runtime::ServiceCaller
- Inherits:
-
Object
- Object
- Factor::Runtime::ServiceCaller
- Defined in:
- lib/runtime/service_caller.rb
Instance Attribute Summary collapse
-
#reconnect ⇒ Object
Returns the value of attribute reconnect.
-
#retry_period ⇒ Object
Returns the value of attribute retry_period.
Instance Method Summary collapse
- #action(action_id, params = {}) ⇒ Object
- #close ⇒ Object
-
#initialize(connector_url, options = {}) ⇒ ServiceCaller
constructor
A new instance of ServiceCaller.
- #listen(listener_id, params = {}) ⇒ Object
- #on(event, &block) ⇒ Object
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, = {}) @url = connector_url @subscribers = {} @reconnect = [:reconnect] || true @retry_period = [:retry_period] || 5 @retry_count = 0 @offline_duration = 0 end |
Instance Attribute Details
#reconnect ⇒ Object
Returns the value of attribute reconnect.
7 8 9 |
# File 'lib/runtime/service_caller.rb', line 7 def reconnect @reconnect end |
#retry_period ⇒ Object
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 |
#close ⇒ Object
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 |