pre_defined.rb 815 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Webhook::PreDefined
  3. include Mixin::RequiredSubPaths
  4. def self.pre_defined_webhooks
  5. descendants.sort_by(&:name)
  6. end
  7. def self.pre_defined_webhook_definitions
  8. pre_defined_webhooks.map { |x| x.new.definition }
  9. end
  10. def definition
  11. {
  12. id: self.class.name.demodulize,
  13. name: name,
  14. custom_payload: generated_custom_payload,
  15. fields: fields,
  16. field_names: field_names,
  17. }
  18. end
  19. def name
  20. raise NotImplementedError
  21. end
  22. def custom_payload
  23. raise NotImplementedError
  24. end
  25. def fields
  26. []
  27. end
  28. def field_names
  29. fields.pluck(:name)
  30. end
  31. private
  32. def generated_custom_payload
  33. JSON.pretty_generate(custom_payload)
  34. end
  35. end