Module: Messenger::Components::Attachment

Included in:
Elements::Image, Elements::Video, Templates::Buttons, Templates::Generic, Templates::Receipt
Defined in:
lib/messenger/components/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/messenger/components/attachment.rb', line 4

def type
  @type
end

Instance Method Details

#all_attributesObject



15
16
17
18
# File 'lib/messenger/components/attachment.rb', line 15

def all_attributes
  return instance_values unless defined?(flattened_attributes)
  instance_values.merge! flattened_attributes
end

#allowed_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/messenger/components/attachment.rb', line 24

def allowed_attribute?(attribute)
  self.class::ATTRIBUTES.include?(attribute)
end

#buildObject



6
7
8
9
10
11
12
13
# File 'lib/messenger/components/attachment.rb', line 6

def build
  {
    attachment: {
      type: @type,
      payload: payload
    }
  }
end

#build_elements(elements) ⇒ Object



28
29
30
# File 'lib/messenger/components/attachment.rb', line 28

def build_elements(elements)
  elements.map { |element| element.build } if elements.present?
end

#payloadObject



20
21
22
# File 'lib/messenger/components/attachment.rb', line 20

def payload
  all_attributes.select { |attribute, value| allowed_attribute?(attribute) && value.present? }
end