Class: MessengerClient::ListTemplate
- Defined in:
- lib/messenger_client/list_template.rb
Constant Summary collapse
- TEMPLATE_STYLES =
%w(LARGE COMPACT)
Instance Method Summary collapse
-
#initialize(template_items, buttons = [], style = "LARGE") ⇒ ListTemplate
constructor
A new instance of ListTemplate.
- #payload ⇒ Object
- #type ⇒ Object
Methods inherited from Template
Constructor Details
#initialize(template_items, buttons = [], style = "LARGE") ⇒ ListTemplate
Returns a new instance of ListTemplate.
5 6 7 8 9 |
# File 'lib/messenger_client/list_template.rb', line 5 def initialize(template_items, = [], style = "LARGE") @template_items = template_items @buttons = @style = style.upcase end |
Instance Method Details
#payload ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/messenger_client/list_template.rb', line 15 def payload data = { template_type: type, elements: @template_items.map(&:to_json), } raise ArgumentError, "#{@style} is not a valid template style. Your choices are #{TEMPLATE_STYLES.join(', ')}" unless TEMPLATE_STYLES.include?(@style) data.merge!(top_element_style: @style) data.merge!(buttons: @buttons.map(&:to_json)) if @buttons.any? data end |
#type ⇒ Object
11 12 13 |
# File 'lib/messenger_client/list_template.rb', line 11 def type "list" end |