class Attio::WebhookUtils::Event
Represents a webhook event payload
def changes
def changes @data["changes"] || @data[:changes] end
def created_event?
def created_event? type&.end_with?(".created") end
def deleted_event?
def deleted_event? type&.end_with?(".deleted") end
def initialize(payload)
def initialize(payload) @raw_data = payload.is_a?(String) ? JSON.parse(payload) : payload @id = @raw_data["id"] || @raw_data[:id] @type = @raw_data["type"] || @raw_data[:type] @occurred_at = parse_timestamp(@raw_data["occurred_at"] || @raw_data[:occurred_at]) @data = @raw_data["data"] || @raw_data[:data] || {} end
def list_entry_event?
def list_entry_event? type&.start_with?("list_entry.") end
def note_event?
def note_event? type&.start_with?("note.") end
def object_type
def object_type @data["object"] || @data[:object] end
def parse_timestamp(timestamp_str)
def parse_timestamp(timestamp_str) return nil unless timestamp_str Time.parse(timestamp_str) rescue ArgumentError nil end
def present?
def present? true # Events are always present if they exist end
def record
def record @data["record"] || @data[:record] end
def record_data
def record_data record || {} end
def record_event?
def record_event? type&.start_with?("record.") end
def record_id
def record_id record_data = record return nil unless record_data record_data["id"] || record_data[:id] end
def task_event?
def task_event? type&.start_with?("task.") end
def to_h
def to_h { id: id, type: type, occurred_at: occurred_at&.iso8601, object_type: object_type, record_id: record_id, record_data: record_data, changes: changes, data: data }.compact end
def to_json(*args)
def to_json(*args) @raw_data.to_json(*args) end
def updated_event?
def updated_event? type&.end_with?(".updated") end