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
-
.attachments_within_limit?(count) ⇒ Boolean
Only images can be batched; Meta accepts one audio or video per message.
- .image?(mime) ⇒ Boolean
-
.max_bytes_for(mime) ⇒ Object
The ceiling that applies to a given MIME type.
- .text_within_limit?(text) ⇒ Boolean
- .within_size?(mime, bytes) ⇒ Boolean
Class Method Details
.attachments_within_limit?(count) ⇒ Boolean
Only images can be batched; Meta accepts one audio or video per message.
37 38 39 |
# File 'lib/instagram_connect/media/limits.rb', line 37 def (count) count.to_i <= ATTACHMENTS_MAX end |
.image?(mime) ⇒ 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
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
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 |