Class: Line::Bot::V2::MessagingApi::FlexImage

Inherits:
FlexComponent show all
Defined in:
lib/line/bot/v2/messaging_api/model/flex_image.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#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

Instance Attribute Details

#actionAction?

Returns:



65
66
67
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 65

def action
  @action
end

#alignString?

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

Returns:

  • (String, nil)

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



47
48
49
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 47

def align
  @align
end

#animatedBoolean?

Returns 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.

Returns:

  • (Boolean, nil)

    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.



68
69
70
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 68

def animated
  @animated
end

#aspect_modeString?

Returns (‘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.

Returns:

  • (String, 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.



59
60
61
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 59

def aspect_mode
  @aspect_mode
end

#aspect_ratioString?

Returns 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`.

Returns:

  • (String, 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`.



56
57
58
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 56

def aspect_ratio
  @aspect_ratio
end

#background_colorString?

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

Returns:

  • (String, nil)

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



62
63
64
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 62

def background_color
  @background_color
end

#flexInteger?

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

Returns:

  • (Integer, nil)

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



26
27
28
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 26

def flex
  @flex
end

#gravityString?

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

Returns:

  • (String, nil)

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



50
51
52
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 50

def gravity
  @gravity
end

#marginString?

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

Returns:

  • (String, nil)

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



29
30
31
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 29

def margin
  @margin
end

#offset_bottomString?

Returns Offset.

Returns:

  • (String, nil)

    Offset.



38
39
40
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 38

def offset_bottom
  @offset_bottom
end

#offset_endString?

Returns Offset.

Returns:

  • (String, nil)

    Offset.



44
45
46
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 44

def offset_end
  @offset_end
end

#offset_startString?

Returns Offset.

Returns:

  • (String, nil)

    Offset.



41
42
43
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 41

def offset_start
  @offset_start
end

#offset_topString?

Returns Offset.

Returns:

  • (String, nil)

    Offset.



35
36
37
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 35

def offset_top
  @offset_top
end

#positionString?

Returns (‘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.

Returns:

  • (String, 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.



32
33
34
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 32

def position
  @position
end

#sizeString?

Returns The maximum image width. This is md by default.

Returns:

  • (String, nil)

    The maximum image width. This is md by default.



53
54
55
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 53

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 20

def type
  @type
end

#urlString

Returns 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).

Returns:

  • (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)



23
24
25
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 23

def url
  @url
end

Class Method Details

.create(args) ⇒ Line::Bot::V2::MessagingApi::FlexImage

Create an instance of the class from a hash

Parameters:

  • args (Hash)

    Hash containing all the required attributes

Returns:



140
141
142
143
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 140

def self.create(args) # steep:ignore
  symbolized_args = Line::Bot::V2::Utils.deep_symbolize(args)
  return new(**symbolized_args) # steep:ignore
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if the objects are equal, false otherwise.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Boolean)

    true if the objects are equal, false otherwise



147
148
149
150
151
152
153
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 147

def ==(other)
  return false unless self.class == other.class

  instance_variables.all? do |var|
      instance_variable_get(var) == other.instance_variable_get(var)
  end
end

#hashInteger

Returns Hash code of the object.

Returns:

  • (Integer)

    Hash code of the object



156
157
158
# File 'lib/line/bot/v2/messaging_api/model/flex_image.rb', line 156

def hash
  [self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
end