Class: Factor::Connector::ListenerInstance
- Inherits:
-
Instance
- Object
- Instance
- Factor::Connector::ListenerInstance
show all
- Includes:
- Celluloid
- Defined in:
- lib/instances/listener_instance.rb
Instance Attribute Summary collapse
Attributes inherited from Instance
#callback, #definition, #instance_id
Instance Method Summary
collapse
Methods inherited from Instance
#debug, #error, #id, #info, #log, #respond, #warn
Constructor Details
Returns a new instance of ListenerInstance.
12
13
14
15
|
# File 'lib/instances/listener_instance.rb', line 12
def initialize(options = {})
@web_hooks = {}
super(options)
end
|
Instance Attribute Details
#service_id ⇒ Object
Returns the value of attribute service_id.
10
11
12
|
# File 'lib/instances/listener_instance.rb', line 10
def service_id
@service_id
end
|
#web_hooks ⇒ Object
Returns the value of attribute web_hooks.
10
11
12
|
# File 'lib/instances/listener_instance.rb', line 10
def web_hooks
@web_hooks
end
|
Instance Method Details
#call_web_hook(web_hook_id, hook_params, request, response) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/instances/listener_instance.rb', line 53
def call_web_hook(web_hook_id, hook_params, request, response)
web_hook = @web_hooks[web_hook_id]
begin
self.instance_exec @params, hook_params, request, response, &web_hook.start
rescue Factor::Connector::Error => ex
error ex.message
exception ex.exception, params: hook_params, hook_id: web_hook_id if ex.exception
rescue => ex
error "Couldn't call webhook for unexpected reason. We've been informed and looking into it."
exception ex, params: @params
end
end
|
#fail(message, params = {}) ⇒ Object
76
77
78
|
# File 'lib/instances/listener_instance.rb', line 76
def fail(message, params = {})
raise Factor::Connector::Error, exception: params[:exception], message: message
end
|
#get_web_hook(web_hook_id) ⇒ Object
72
73
74
|
# File 'lib/instances/listener_instance.rb', line 72
def get_web_hook(web_hook_id)
hook_url(@service_id, self.id, @instance_id, web_hook_id)
end
|
#start(params) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/instances/listener_instance.rb', line 17
def start(params)
@params = params
begin
instance_exec @params, &@definition.start if @definition && @definition.start
respond type: 'return'
rescue Factor::Connector::Error => ex
error ex.message
respond type: 'fail'
exception ex.exception, params: @params if ex.exception
rescue => ex
error "Couldn't start listener for unexpected reason. We've been informed and looking into it."
respond type: 'fail'
exception ex, params: @params
end
end
|
#start_workflow(params) ⇒ Object
49
50
51
|
# File 'lib/instances/listener_instance.rb', line 49
def start_workflow(params)
@callback.call(type: 'start_workflow', payload: params) if @callback
end
|
#stop ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/instances/listener_instance.rb', line 34
def stop
begin
instance_exec @params, &@definition.stop if @definition && @definition.stop
respond type: 'stopped'
rescue Factor::Connector::Error => ex
error ex.message
respond type: 'fail'
exception ex.exception, params: @params if ex.exception
rescue ex
error "Couldn't stop listener for unexpected reason. We've been informed and looking into it."
respond type: 'fail'
exception ex, params: @params
end
end
|
#web_hook(vals = {}, &block) ⇒ Object
66
67
68
69
70
|
# File 'lib/instances/listener_instance.rb', line 66
def web_hook(vals = {}, &block)
web_hook = WebHookBuilder.new(vals, &block).build
@web_hooks[web_hook.id] = web_hook
hook_url(@service_id, self.id, @instance_id, web_hook.id)
end
|