houdini/app/models/object_event_hook_config.rb

21 lines
698 B
Ruby
Raw Normal View History

2021-02-09 01:37:47 +00:00
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class ObjectEventHookConfig < ApplicationRecord
# :webhook_service, #str, webhook service to be called
# :configuration, #jsonb, configuration needed to connect to the webhook
2021-02-18 20:25:07 +00:00
# :object_event_types, #jsonb, must be an array
2021-02-09 01:37:47 +00:00
belongs_to :nonprofit
validates :webhook_service, presence: true
validates :configuration, presence: true
validates :object_event_types, presence: true, length: {minimum: 1}
2021-02-09 01:37:47 +00:00
def webhook
2021-02-09 23:46:19 +00:00
Houdini::WebhookAdapter.build(webhook_service, configuration.symbolize_keys)
2021-02-09 01:37:47 +00:00
end
end