Class: Zaikio::Webhooks::Event

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/zaikio/webhooks/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_data) ⇒ Event

Returns a new instance of Event.



12
13
14
15
16
17
18
19
20
# File 'lib/zaikio/webhooks/event.rb', line 12

def initialize(event_data)
  event_data = event_data.to_h.stringify_keys

  event_data.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  @data = event_data
end

Instance Attribute Details

#client_nameObject (readonly)

Returns the value of attribute client_name.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def client_name
  @client_name
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def id
  @id
end

Returns the value of attribute link.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def name
  @name
end

#payloadObject (readonly)

Returns the value of attribute payload.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def payload
  @payload
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/zaikio/webhooks/event.rb', line 8

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/zaikio/webhooks/event.rb', line 38

def ==(other)
  data == other.data
end

#created_atObject



22
23
24
# File 'lib/zaikio/webhooks/event.rb', line 22

def created_at
  DateTime.parse(data["timestamp"])
end

#received_atObject



26
27
28
# File 'lib/zaikio/webhooks/event.rb', line 26

def received_at
  DateTime.parse(data["received_at"])
end

#subject_idObject



30
31
32
# File 'lib/zaikio/webhooks/event.rb', line 30

def subject_id
  data["subject"].split("/").last
end

#subject_typeObject



34
35
36
# File 'lib/zaikio/webhooks/event.rb', line 34

def subject_type
  data["subject"].split("/").first == "Org" ? "Organization" : "Person"
end