Class: WhatsappSdk::Resource::MediaComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_sdk/resource/media_component.rb

Defined Under Namespace

Modules: Type Classes: InvalidMedia

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id: nil, link: nil, caption: nil, filename: nil) ⇒ MediaComponent

Returns a new instance of MediaComponent.



50
51
52
53
54
55
56
57
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 50

def initialize(type:, id: nil, link: nil, caption: nil, filename: nil)
  @type = type
  @id = id
  @link = link
  @caption = caption
  @filename = filename
  validate_media
end

Instance Attribute Details

#captionObject

Describes the specified document or image media.



43
44
45
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 43

def caption
  @caption
end

#filenameObject

Describes the filename for the specific document. Use only with document media.



48
49
50
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 48

def filename
  @filename
end

#idObject

Returns media id.



21
22
23
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 21

def id
  @id
end

The protocol and URL of the media to be sent. Use only with HTTP/HTTPS URLs. Do not use this field when the message type is set to text.



38
39
40
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 38

def link
  @link
end

#typeObject

Returns the value of attribute type.



32
33
34
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 32

def type
  @type
end

Instance Method Details

#to_jsonObject



59
60
61
62
63
64
65
66
# File 'lib/whatsapp_sdk/resource/media_component.rb', line 59

def to_json
  json = {}
  json[:id] = id unless id.nil?
  json[:link] = link unless link.nil?
  json[:caption] = caption unless caption.nil?
  json[:filename] = filename unless filename.nil?
  json
end