Class: WebhookSystem::BaseEvent
- Inherits:
-
Object
- Object
- WebhookSystem::BaseEvent
- Includes:
- PhModel
- Defined in:
- lib/webhook_system/base_event.rb
Overview
This is the class meant to be used as the base class for any Events sent through the Webhook system
Instance Attribute Summary collapse
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #event_name ⇒ Object
-
#initialize(*args, &block) ⇒ BaseEvent
constructor
A new instance of BaseEvent.
- #payload_attributes ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ BaseEvent
Returns a new instance of BaseEvent.
7 8 9 10 |
# File 'lib/webhook_system/base_event.rb', line 7 def initialize(*args, &block) super(*args, &block) @event_id = SecureRandom.uuid.freeze end |
Instance Attribute Details
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
12 13 14 |
# File 'lib/webhook_system/base_event.rb', line 12 def event_id @event_id end |
Class Method Details
.key_is_reserved?(key) ⇒ Boolean
36 37 38 |
# File 'lib/webhook_system/base_event.rb', line 36 def self.key_is_reserved?(key) key.to_s.in? %w(event event_id) end |
Instance Method Details
#as_json ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/webhook_system/base_event.rb', line 24 def as_json result = { 'event_name' => event_name, 'event_id' => event_id, } each_attribute do |attribute_name, attribute_method| validate_attribute_name attribute_name result[attribute_name.to_s] = public_send(attribute_method).as_json end result.deep_stringify_keys end |
#event_name ⇒ Object
14 15 16 17 |
# File 'lib/webhook_system/base_event.rb', line 14 def event_name mesg = "class #{self.class.name} must implement abstract method `#{self.class.name}#event_name()'." raise with_caller_backtrace(RuntimeError.new(mesg), 2) end |
#payload_attributes ⇒ Object
19 20 21 22 |
# File 'lib/webhook_system/base_event.rb', line 19 def payload_attributes mesg = "class #{self.class.name} must implement abstract method `#{self.class.name}#payload_attributes()'." raise with_caller_backtrace(RuntimeError.new(mesg), 2) end |