Class: Whatsapp::Webhook::Message::Media
- Defined in:
- lib/ruby/whatsapp/webhook/message/media.rb
Overview
Shared shape for the media-backed message types (image, video, audio, document, sticker) — a media asset id you can resolve via Media, plus its mime type and content hash.
Instance Attribute Summary collapse
- #caption ⇒ String?
-
#media_id ⇒ String?
The media asset id (resolve via Media#url).
- #mime_type ⇒ String?
- #sha256 ⇒ String?
Attributes inherited from Base
#context, #from, #id, #referral, #timestamp, #type
Class Method Summary collapse
-
.media_attributes(data, key) ⇒ Hash
Extracts the media-specific fields nested under the given key (e.g.
"image","video"), for subclasses to merge with their own extra attributes before callingnew.
Instance Method Summary collapse
-
#initialize(media_id:, mime_type:, sha256:, caption: nil, **base_attributes) ⇒ Media
constructor
A new instance of Media.
Methods inherited from Base
Constructor Details
#initialize(media_id:, mime_type:, sha256:, caption: nil, **base_attributes) ⇒ Media
Returns a new instance of Media.
26 27 28 29 30 31 32 33 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 26 def initialize(media_id:, mime_type:, sha256:, caption: nil, **base_attributes) super(**base_attributes) @media_id = media_id @mime_type = mime_type @sha256 = sha256 @caption = caption end |
Instance Attribute Details
#caption ⇒ String?
24 25 26 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 24 def caption @caption end |
#media_id ⇒ String?
Returns The media asset id (resolve via Media#url).
12 13 14 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 12 def media_id @media_id end |
#mime_type ⇒ String?
16 17 18 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 16 def mime_type @mime_type end |
#sha256 ⇒ String?
20 21 22 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 20 def sha256 @sha256 end |
Class Method Details
.media_attributes(data, key) ⇒ Hash
Extracts the media-specific fields nested under the given key
(e.g. "image", "video"), for subclasses to merge with their own
extra attributes before calling new.
42 43 44 45 46 47 48 49 |
# File 'lib/ruby/whatsapp/webhook/message/media.rb', line 42 def media_attributes(data, key) { media_id: data.dig(key, "id"), mime_type: data.dig(key, "mime_type"), sha256: data.dig(key, "sha256"), caption: data.dig(key, "caption"), } end |