Module: InstagramConnect::Media::Limits

Defined in:
lib/instagram_connect/media/limits.rb

Overview

Meta's ceilings, in one place, read by the composer, the send path and the client so the numbers cannot drift apart.

Constant Summary collapse

IMAGE_MAX_BYTES =
8 * 1024 * 1024
AUDIO_VIDEO_MAX_BYTES =
25 * 1024 * 1024
ATTACHMENTS_MAX =
10
TEXT_MAX_BYTES =

BYTES, not characters. An emoji-heavy 400-character reply is over the limit and Meta rejects the whole send, so anything measuring this with String#length is measuring the wrong thing.

1000
IMAGE_TYPES =
%w[image/jpeg image/png image/gif].freeze
AUDIO_TYPES =
%w[audio/aac audio/mp4 audio/mpeg audio/ogg audio/wav].freeze
VIDEO_TYPES =
%w[video/mp4 video/ogg video/avi video/quicktime video/webm].freeze

Class Method Summary collapse

Class Method Details

.attachments_within_limit?(count) ⇒ Boolean

Only images can be batched; Meta accepts one audio or video per message.

Returns:

  • (Boolean)


37
38
39
# File 'lib/instagram_connect/media/limits.rb', line 37

def attachments_within_limit?(count)
  count.to_i <= ATTACHMENTS_MAX
end

.image?(mime) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/instagram_connect/media/limits.rb', line 28

def image?(mime)
  IMAGE_TYPES.include?(mime.to_s)
end

.max_bytes_for(mime) ⇒ Object

The ceiling that applies to a given MIME type. Images get a tighter one than audio and video, and an unknown type is held to the tighter of the two rather than waved through.



24
25
26
# File 'lib/instagram_connect/media/limits.rb', line 24

def max_bytes_for(mime)
  image?(mime) ? IMAGE_MAX_BYTES : AUDIO_VIDEO_MAX_BYTES
end

.text_within_limit?(text) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/instagram_connect/media/limits.rb', line 41

def text_within_limit?(text)
  text.to_s.bytesize <= TEXT_MAX_BYTES
end

.within_size?(mime, bytes) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/instagram_connect/media/limits.rb', line 32

def within_size?(mime, bytes)
  bytes.to_i.positive? && bytes.to_i <= max_bytes_for(mime)
end