Class: InstagramConnect::MediaItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- InstagramConnect::MediaItem
- Defined in:
- app/models/instagram_connect/media_item.rb
Overview
A post, reel or story on the connected account — "IG Media" in Meta's vocabulary. Named MediaItem because InstagramConnect::Media is already the namespace for inbound file handling (Media::Limits, Media::Attaching); the table keeps Meta's noun.
Constant Summary collapse
- PRODUCT_TYPES =
%w[FEED STORY REELS AD].freeze
Class Method Summary collapse
-
.record(account:, ig_media_id:, **attributes) ⇒ Object
Upserts by Meta's id.
Instance Method Summary collapse
Class Method Details
.record(account:, ig_media_id:, **attributes) ⇒ Object
Upserts by Meta's id. Media arrives from several directions — a webhook about a comment, a story expiring, a sync — and whichever gets there first should create the row without the others having to care.
25 26 27 28 29 30 31 32 |
# File 'app/models/instagram_connect/media_item.rb', line 25 def self.record(account:, ig_media_id:, **attributes) media = find_or_initialize_by(account_id: account.id, ig_media_id: ig_media_id.to_s) media.assign_attributes(attributes.compact) media.save! media rescue ActiveRecord::RecordNotUnique find_by!(account_id: account.id, ig_media_id: ig_media_id.to_s) end |
Instance Method Details
#story? ⇒ Boolean
34 35 36 |
# File 'app/models/instagram_connect/media_item.rb', line 34 def story? media_product_type == "STORY" end |