Class: Line::Message::Builder::Flex::Image
- 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
alignproperty - Position::Vertical for
gravityproperty - Position::Margin for
marginproperty - Position::Offset for offset properties
- Size::Flex for
flexsizing property - Size::Image for
size,aspect_ratio, andaspect_modeproperties
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
The URL of the image (must be HTTPS).
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(url, context: nil, **options) ⇒ Image
constructor
Initializes a new Flex Message Image component.
Methods included from Size::Image
Methods included from Size::Flex
Methods included from Position::Offset
Methods included from Position::Margin
Methods included from Position::Vertical
Methods included from Position::Horizontal
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, **, &) @url = url # The image URL is mandatory. super(context: context, **, &) # 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
#url ⇒ Object (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 |