Module: ActiveWebhook

Defined in:
lib/active_webhook.rb,
lib/active_webhook/hook.rb,
lib/active_webhook/topic.rb,
lib/active_webhook/logger.rb,
lib/active_webhook/adapter.rb,
lib/active_webhook/version.rb,
lib/active_webhook/callbacks.rb,
lib/active_webhook/error_log.rb,
lib/active_webhook/subscription.rb,
lib/active_webhook/configuration.rb,
lib/generators/install_generator.rb,
lib/generators/migrations_generator.rb,
lib/active_webhook/models/configuration.rb,
lib/active_webhook/delivery/base_adapter.rb,
lib/active_webhook/queueing/base_adapter.rb,
lib/active_webhook/delivery/configuration.rb,
lib/active_webhook/models/topic_additions.rb,
lib/active_webhook/queueing/configuration.rb,
lib/active_webhook/formatting/base_adapter.rb,
lib/active_webhook/formatting/json_adapter.rb,
lib/active_webhook/delivery/faraday_adapter.rb,
lib/active_webhook/formatting/configuration.rb,
lib/active_webhook/queueing/sidekiq_adapter.rb,
lib/active_webhook/delivery/net_http_adapter.rb,
lib/active_webhook/verification/base_adapter.rb,
lib/active_webhook/models/error_log_additions.rb,
lib/active_webhook/verification/configuration.rb,
lib/active_webhook/queueing/active_job_adapter.rb,
lib/active_webhook/queueing/syncronous_adapter.rb,
lib/active_webhook/queueing/delayed_job_adapter.rb,
lib/active_webhook/models/subscription_additions.rb,
lib/active_webhook/verification/unsigned_adapter.rb,
lib/active_webhook/formatting/url_encoded_adapter.rb,
lib/active_webhook/verification/hmac_sha256_adapter.rb

Defined Under Namespace

Modules: Callbacks, Delivery, Formatting, Generators, Models, Queueing, Verification Classes: Adapter, Configuration, ErrorLog, Hook, InvalidAdapterError, Logger, Subscription, Topic

Constant Summary collapse

IDENTIFIER =
"Active Webhook v#{VERSION}"
VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabled=(value) ⇒ Object (writeonly)

Sets the attribute enabled

Parameters:

  • value

    the value to set the attribute enabled to.



33
34
35
# File 'lib/active_webhook.rb', line 33

def enabled=(value)
  @enabled = value
end

Class Method Details

.configurationObject



35
36
37
# File 'lib/active_webhook.rb', line 35

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



39
40
41
42
43
# File 'lib/active_webhook.rb', line 39

def configure
  yield(configuration)

  configuration.after_configure
end

.disableObject



83
84
85
86
87
88
89
90
# File 'lib/active_webhook.rb', line 83

def disable
  state = enabled?
  configuration.enabled = false
  value = yield
ensure
  configuration.enabled = state
  value
end

.disabled?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/active_webhook.rb', line 70

def disabled?
  !enabled?
end

.enableObject



74
75
76
77
78
79
80
81
# File 'lib/active_webhook.rb', line 74

def enable
  state = enabled?
  configuration.enabled = true
  value = yield
ensure
  configuration.enabled = state
  value
end

.enabled?Boolean

TODO: change the next 4 methods to use memoized thread safe class var rather than configuration.enabled

Returns:

  • (Boolean)


66
67
68
# File 'lib/active_webhook.rb', line 66

def enabled?
  configuration.enabled
end

.loggerObject



45
46
47
# File 'lib/active_webhook.rb', line 45

def logger
  defined?(Rails) ? Rails.logger : (@logger ||= Logger.new($stdout))
end

.originObject



57
58
59
60
61
62
63
# File 'lib/active_webhook.rb', line 57

def origin
  return @@origin if defined? @@origin

  @@origin = (Rails.application.config.action_mailer.default_url_options[:host] if defined?(Rails))
rescue StandardError
  @@origin = ""
end

.subscription_modelObject



49
50
51
# File 'lib/active_webhook.rb', line 49

def subscription_model
  configuration.models.subscription
end

.topic_modelObject



53
54
55
# File 'lib/active_webhook.rb', line 53

def topic_model
  configuration.models.topic
end

.trigger(key:, version: nil, **context) ⇒ Object



98
99
100
101
# File 'lib/active_webhook.rb', line 98

def trigger(key:, version: nil, **context)
  queueing_adapter.call(key: key, version: version, **context) if enabled?
  true
end