Class: MessageQuickly::Messaging::ButtonTemplateAttachment

Inherits:
TemplateAttachment show all
Defined in:
lib/message_quickly/messaging/button_template_attachment.rb

Instance Attribute Summary collapse

Attributes inherited from TemplateAttachment

#template_type

Attributes inherited from Attachment

#payload, #type

Instance Method Summary collapse

Methods inherited from Attachment

#file?

Constructor Details

#initialize(params = {}) ⇒ ButtonTemplateAttachment

Returns a new instance of ButtonTemplateAttachment.



7
8
9
10
11
# File 'lib/message_quickly/messaging/button_template_attachment.rb', line 7

def initialize(params = {})
  self.buttons ||= []
  params['template_type'] ||= 'button'
  super(params)
end

Instance Attribute Details

#buttonsObject

Returns the value of attribute buttons.



5
6
7
# File 'lib/message_quickly/messaging/button_template_attachment.rb', line 5

def buttons
  @buttons
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/message_quickly/messaging/button_template_attachment.rb', line 5

def text
  @text
end

Instance Method Details

#build_button(button_type) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/message_quickly/messaging/button_template_attachment.rb', line 13

def build_button(button_type)
  case button_type
  when :web_url
    button = WebUrlButton.new
  when :postback
    button = PostbackButton.new
  when :account_link
    button = AccountLinkButton.new
  end
  buttons << button.tap { |button| yield button }
end

#to_hashObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/message_quickly/messaging/button_template_attachment.rb', line 25

def to_hash
  {
    type: type,
    payload: {
      template_type: template_type,
      text: text,
      buttons: buttons.collect { |button| button.to_hash }
    }
  }
end