diff options
Diffstat (limited to 'app/models/concerns/integrations/has_web_hook.rb')
-rw-r--r-- | app/models/concerns/integrations/has_web_hook.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/concerns/integrations/has_web_hook.rb b/app/models/concerns/integrations/has_web_hook.rb new file mode 100644 index 00000000000..dabe7152b18 --- /dev/null +++ b/app/models/concerns/integrations/has_web_hook.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Integrations + module HasWebHook + extend ActiveSupport::Concern + + included do + after_save :update_web_hook!, if: :activated? + end + + # Return the URL to be used for the webhook. + def hook_url + raise NotImplementedError + end + + # Return whether the webhook should use SSL verification. + def hook_ssl_verification + true + end + + # Create or update the webhook, raising an exception if it cannot be saved. + def update_web_hook! + hook = service_hook || build_service_hook + hook.url = hook_url if hook.url != hook_url # avoid reencryption + hook.enable_ssl_verification = hook_ssl_verification + hook.save! if hook.changed? + hook + end + + # Execute the webhook, creating it if necessary. + def execute_web_hook!(*args) + update_web_hook! + service_hook.execute(*args) + end + end +end |