Module: Zaikio::Webhooks
- Defined in:
- lib/zaikio/webhooks.rb,
lib/zaikio/webhooks/event.rb,
lib/zaikio/webhooks/engine.rb,
lib/zaikio/webhooks/version.rb,
lib/zaikio/webhooks/configuration.rb,
lib/zaikio/webhooks/event_serializer.rb,
lib/zaikio/webhooks/client_configuration.rb,
app/controllers/zaikio/webhooks/webhooks_controller.rb
Defined Under Namespace
Classes: ClientConfiguration, Configuration, Engine, Event, EventSerializer, WebhooksController
Constant Summary
collapse
- VERSION =
"0.2.0".freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
10
11
12
|
# File 'lib/zaikio/webhooks.rb', line 10
def configuration
@configuration
end
|
.webhooks ⇒ Object
Returns the value of attribute webhooks.
11
12
13
|
# File 'lib/zaikio/webhooks.rb', line 11
def webhooks
@webhooks
end
|
Class Method Details
.after_configuration(&block) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/zaikio/webhooks.rb', line 21
def after_configuration(&block)
if configuration
yield
else
@after_configuration_callbacks ||= []
@after_configuration_callbacks << block
end
end
|
13
14
15
16
17
18
19
|
# File 'lib/zaikio/webhooks.rb', line 13
def configure
self.configuration ||= Configuration.new
yield(configuration)
@after_configuration_callbacks ||= []
(@after_configuration_callbacks || []).each(&:call)
@after_configuration_callbacks = []
end
|
.on(event_name, job_klass, client_name: nil, perform_now: false, options: {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/zaikio/webhooks.rb', line 38
def on(event_name, job_klass, client_name: nil, perform_now: false, options: {})
@webhooks ||= {}
after_configuration do
client_names = Array(client_name || configuration.all_client_names).map(&:to_s)
client_names.each do |name|
@webhooks[name] ||= {}
@webhooks[name][event_name.to_s] ||= {}
@webhooks[name][event_name.to_s][job_klass] = {
perform_now: perform_now,
options: options
}
end
end
end
|
.reset ⇒ Object
30
31
32
|
# File 'lib/zaikio/webhooks.rb', line 30
def reset
@webhooks = {}
end
|
.webhooks_for(client_name, event_name) ⇒ Object
34
35
36
|
# File 'lib/zaikio/webhooks.rb', line 34
def webhooks_for(client_name, event_name)
(@webhooks.dig(client_name.to_s, event_name.to_s) || {})
end
|