Class: Basecamp::Webhooks::Event
- Inherits:
-
Object
- Object
- Basecamp::Webhooks::Event
- 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
-
#copy ⇒ Object
readonly
Returns the value of attribute copy.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#recording ⇒ Object
readonly
Returns the value of attribute recording.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Event
constructor
A new instance of Event.
-
#parsed_kind ⇒ Object
Parse "todo_created" -> { type: "todo", action: "created" }.
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
#copy ⇒ Object (readonly)
Returns the value of attribute copy.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def copy @copy end |
#created_at ⇒ Object (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 |
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def creator @creator end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def details @details end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def kind @kind end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
8 9 10 |
# File 'lib/basecamp/webhooks/event.rb', line 8 def raw @raw end |
#recording ⇒ Object (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_kind ⇒ Object
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 |