Class: Basecamp::Webhooks::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/basecamp/webhooks/event.rb

Overview

Structured wrapper around webhook event payloads. Accepts any hash - does not reject unknown fields or event kinds.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Event

Returns a new instance of Event.



10
11
12
13
14
15
16
17
18
19
# File 'lib/basecamp/webhooks/event.rb', line 10

def initialize(hash)
  @raw = hash
  @id = hash["id"]
  @kind = hash["kind"]
  @details = hash["details"] || {}
  @created_at = hash["created_at"]
  @recording = hash["recording"] || {}
  @creator = hash["creator"] || {}
  @copy = hash["copy"]
end

Instance Attribute Details

#copyObject (readonly)

Returns the value of attribute copy.



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

def copy
  @copy
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#creatorObject (readonly)

Returns the value of attribute creator.



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

def creator
  @creator
end

#detailsObject (readonly)

Returns the value of attribute details.



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

def details
  @details
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#recordingObject (readonly)

Returns the value of attribute recording.



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

def recording
  @recording
end

Instance Method Details

#parsed_kindObject

Parse "todo_created" -> { type: "todo", action: "created" }



22
23
24
25
26
27
28
29
# File 'lib/basecamp/webhooks/event.rb', line 22

def parsed_kind
  return { type: kind, action: "" } unless kind&.include?("_")
  last_underscore = kind.rindex("_")
  {
    type: kind[0...last_underscore],
    action: kind[(last_underscore + 1)..]
  }
end