Class: Whatsapp::Webhook::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/whatsapp/webhook/notification.rb

Overview

Top-level deserialization entry point for an incoming webhook POST body.

Examples:

Whatsapp::Webhook::Notification.deserialize(JSON.parse(request.body.read))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:, entry:) ⇒ Notification

Returns a new instance of Notification.



17
18
19
20
# File 'lib/ruby/whatsapp/webhook/notification.rb', line 17

def initialize(object:, entry:)
  @object = object
  @entry = entry
end

Instance Attribute Details

#entryArray<Entry>

Returns:



15
16
17
# File 'lib/ruby/whatsapp/webhook/notification.rb', line 15

def entry
  @entry
end

#objectString

Returns:

  • (String)


11
12
13
# File 'lib/ruby/whatsapp/webhook/notification.rb', line 11

def object
  @object
end

Class Method Details

.deserialize(data) ⇒ Notification

Parameters:

  • data (Hash)

    The parsed JSON request body.

Returns:



25
26
27
28
29
30
31
32
# File 'lib/ruby/whatsapp/webhook/notification.rb', line 25

def deserialize(data)
  data ||= {}

  new(
    object: data["object"],
    entry: Array(data["entry"]).map { |entry_data| Entry.deserialize(entry_data) }
  )
end