Class: Line::Message::Builder::Flex::Image

Inherits:
Base
  • Object
show all
Includes:
Actionable, Position::Horizontal, Position::Margin, Position::Offset, Position::Vertical, Size::Flex, Size::Image
Defined in:
lib/line/message/builder/flex/image.rb

Overview

Represents an "image" component in a LINE Flex Message.

Images are specified by a URL and can be included in various parts of a Flex Message, such as a box, a bubble's hero section, etc. They offer several properties to control their appearance, including size, aspect_ratio, aspect_mode and background_color. An image can also have an action to make it tappable.

Example

Line::Message::Builder.with do
flex alt_text: "Image Example" do
  bubble do
    body do
      image "https://example.com/image.png",
            aspect_ratio: "16:9",
            aspect_mode: :cover,
            size: :full
      end
    end
  end
end
end

Example: Playing an animated image on a tinted backdrop

Line::Message::Builder.with do
flex alt_text: "Image Example" do
  bubble do
    hero_image "https://example.com/loading.png",
               animated: true,
               background_color: "#FFFFFF"
  end
end
end

See also:

  • https://developers.line.biz/en/reference/messaging-api/#image
  • Actionable for making the image tappable
  • Position::Horizontal for align property
  • Position::Vertical for gravity property
  • Position::Margin for margin property
  • Position::Offset for offset properties
  • Size::Flex for flex sizing property
  • Size::Image for size, aspect_ratio, and aspect_mode properties

Instance Attribute Summary collapse

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods included from Size::Image

included

Methods included from Size::Flex

included

Methods included from Position::Offset

included

Methods included from Position::Margin

included

Methods included from Position::Vertical

included

Methods included from Position::Horizontal

included

Methods included from Actionable

included, #message, #postback, #uri

Methods inherited from Base

inherited, #method_missing, #quick_reply, #respond_to_missing?, #to_h

Constructor Details

#initialize(url, context: nil, **options) ⇒ Image

Initializes a new Flex Message Image component.

[url] The HTTPS URL of the image (required) [context] An optional context for the builder (default: nil) [options] A hash of options to set instance variables (e.g., :aspect_ratio, :aspect_mode, :size, and options from included modules) [block] An optional block, typically used to define an action for the image

Raises RequiredError if url is nil when building the message.

Example

image = Line::Message::Builder::Flex::Image.new(
"https://example.com/image.png",
aspect_ratio: "16:9",
aspect_mode: :cover
)


132
133
134
135
136
# File 'lib/line/message/builder/flex/image.rb', line 132

def initialize(url, context: nil, **options, &)
  @url = url # The image URL is mandatory.

  super(context: context, **options, &) # Sets options and evals block (for action).
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Line::Message::Builder::Base

Instance Attribute Details

#urlObject (readonly)

The URL of the image (must be HTTPS). This is a required attribute.



62
63
64
# File 'lib/line/message/builder/flex/image.rb', line 62

def url
  @url
end