Sha256: 20cc2ace2db52982101070f77a59c2493f25abcbfa6d4cba6b4c5cffabc388c5

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Line
  module Bot
    module MessageBuilder
      class Template::Buttons < Template
        attr_accessor :thumbnail_image_url, :image_aspect_ratio,
                      :image_size, :image_background_color, :title,
                      :text, :default_action, :actions

        def initialize(thumbnail_image_url: nil, image_aspect_ratio: nil,
                      image_size: nil, image_background_color: nil, title: nil,
                      text: nil, default_action: nil, actions: [])
          super 'buttons' do
            @thumbnail_image_url = thumbnail_image_url
            @image_aspect_ratio = image_aspect_ratio
            @image_size = image_size
            @image_background_color = image_background_color
            @title = title
            @text = text
            @default_action = default_action
            @actions = actions
            yield self if block_given?
          end
        end

        def self.required
          {
            'type' => String,
            'text' => String,
            'actions' => Array
          }
        end

        def to_h
          result = super
          result['actions'] = result['actions'].map { |action| action.to_h }
          result
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
line-bot-message-builder-0.1.2 lib/line/bot/message_builder/templates/buttons.rb