Method: Line::Bot::V2::MessagingApi::FlexImage#initialize

Defined in:
lib/line/bot/v2/messaging_api/model/flex_image.rb

#initialize(url:, flex: nil, margin: nil, position: nil, offset_top: nil, offset_bottom: nil, offset_start: nil, offset_end: nil, align: nil, gravity: nil, size: 'md', aspect_ratio: nil, aspect_mode: nil, background_color: nil, action: nil, animated: false, **dynamic_attributes) ⇒ FlexImage

Returns a new instance of FlexImage.

Parameters:

  • url (String)

    Image URL (Max character limit: 2000) Protocol: HTTPS (TLS 1.2 or later) Image format: JPEG or PNG Maximum image size: 1024×1024 pixels Maximum file size: 10 MB (300 KB when the animated property is true)

  • flex (Integer, nil) (defaults to: nil)

    The ratio of the width or height of this component within the parent box.

  • margin (String, nil) (defaults to: nil)

    The minimum amount of space to include before this component in its parent container.

  • position (String, nil) (defaults to: nil)

    (‘relative’|‘absolute’) Reference for offsetTop, offsetBottom, offsetStart, and offsetEnd. Specify one of the following values: relative: Use the previous box as reference. absolute: Use the top left of parent element as reference. The default value is relative.

  • offset_top (String, nil) (defaults to: nil)

    Offset.

  • offset_bottom (String, nil) (defaults to: nil)

    Offset.

  • offset_start (String, nil) (defaults to: nil)

    Offset.

  • offset_end (String, nil) (defaults to: nil)

    Offset.

  • align (String, nil) (defaults to: nil)

    (‘start’|‘end’|‘center’) Alignment style in horizontal direction.

  • gravity (String, nil) (defaults to: nil)

    (‘top’|‘bottom’|‘center’) Alignment style in vertical direction.

  • size (String, nil) (defaults to: 'md')

    The maximum image width. This is md by default.

  • aspect_ratio (String, nil) (defaults to: nil)

    Aspect ratio of the image. ‘width:height` format. Specify the value of `width` and `height` in the range from 1 to 100000. However, you cannot set `height` to a value that is more than three times the value of `width`. The default value is 1:1.

  • aspect_mode (String, nil) (defaults to: nil)

    (‘fit’|‘cover’) The display style of the image if the aspect ratio of the image and that specified by the aspectRatio property do not match.

  • background_color (String, nil) (defaults to: nil)

    Background color of the image. Use a hexadecimal color code.

  • action (Action, Hash[Symbol, untyped], nil) (defaults to: nil)
  • animated (Boolean, nil) (defaults to: false)

    When this is true, an animated image (APNG) plays. You can specify a value of true up to 10 images in a single message. You can’t send messages that exceed this limit. This is false by default. Animated images larger than 300 KB aren’t played back.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 86

def initialize(
  url:,
  flex: nil,
  margin: nil,
  position: nil,
  offset_top: nil,
  offset_bottom: nil,
  offset_start: nil,
  offset_end: nil,
  align: nil,
  gravity: nil,
  size: 'md',
  aspect_ratio: nil,
  aspect_mode: nil,
  background_color: nil,
  action: nil,
  animated: false,
  **dynamic_attributes
)
  @type = "image"
  
  @url = url
  @flex = flex
  @margin = margin
  @position = position
  @offset_top = offset_top
  @offset_bottom = offset_bottom
  @offset_start = offset_start
  @offset_end = offset_end
  @align = align
  @gravity = gravity
  @size = size
  @aspect_ratio = aspect_ratio
  @aspect_mode = aspect_mode
  @background_color = background_color
  @action = action.is_a?(Line::Bot::V2::MessagingApi::Action) || action.nil? ? action : Line::Bot::V2::MessagingApi::Action.create(**action) # steep:ignore
  @animated = animated

  dynamic_attributes.each do |key, value|
    self.class.attr_accessor key

    if value.is_a?(Hash)
      struct_klass = Struct.new(*value.keys.map(&:to_sym))
      struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
      instance_variable_set("@#{key}", struct_klass.new(*struct_values))
    else
      instance_variable_set("@#{key}", value)
    end
  end
end