lib/ui/fb_carousel.rb in rubotnik-0.1.1 vs lib/ui/fb_carousel.rb in rubotnik-0.2.0

- old
+ new

@@ -1,10 +1,12 @@ # rubocop:disable Metrics/MethodLength module UI ################## GENERIC TEMPLATE (aka CAROUSEL) ####################### # https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template - class FBCarousel + class FBCarousel < UI::BaseUiElement + include Common::HasButtons + def initialize(elements) @template = { recipient: { id: nil }, message: { attachment: { @@ -17,22 +19,10 @@ } } } end - # Sends the valid JSON to Messenger API - def send(user) - template = build(user) - Bot.deliver(template, access_token: ENV['ACCESS_TOKEN']) - end - - # Use this method to return a valid hash and save it for later - def build(user) - @template[:recipient][:id] = user.id - @template - end - # set image aspect ratio to 'square' def square_images @template[:message][:attachment][:payload][:image_aspect_ratio] = 'square' self end @@ -49,17 +39,9 @@ def parse_elements(elements) elements = [elements] if elements.class == Hash elements.map do |elt| elt[:buttons] = parse_buttons(elt[:buttons]) elt - end - end - - def parse_buttons(buttons) - return [] if buttons.nil? || buttons.empty? - buttons.map do |button| - button[:type] = button[:type].to_s - button end end end end