Class: WebhookSystem::BaseEvent

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_idObject (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

Returns:

  • (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_jsonObject



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_nameObject



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_attributesObject



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