Class: InstagramConnect::Ingest::Handlers::StoryInsights

Inherits:
Base
  • Object
show all
Defined in:
lib/instagram_connect/ingest/handlers/story_insights.rb

Overview

A story expired, and Meta sent its final metrics with the notification.

This is the only durable capture path there is. Story insights are retrievable from the API for 24 hours; after that the numbers do not exist anywhere. So the snapshot is written here, inside ingest, rather than handed to a job that might be delayed past the point of no return.

Instance Attribute Summary

Attributes inherited from Base

#notification

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from InstagramConnect::Ingest::Handlers::Base

Class Method Details

.dedupe_key(event) ⇒ Object



11
12
13
# File 'lib/instagram_connect/ingest/handlers/story_insights.rb', line 11

def self.dedupe_key(event)
  event.dig("value", "media_id").presence
end

.requires_dedupe_key?Boolean



15
16
17
# File 'lib/instagram_connect/ingest/handlers/story_insights.rb', line 15

def self.requires_dedupe_key?
  true
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/instagram_connect/ingest/handlers/story_insights.rb', line 19

def call
  # The story may well have been posted from a phone rather than through
  # this app, so its media row might not exist yet.
  InstagramConnect::MediaItem.record(
    account: , ig_media_id: media_id, media_product_type: "STORY"
  )

  InstagramConnect::InsightSnapshot.record(
    account: ,
    subject_type: "story",
    subject_ref: media_id,
    period: "lifetime",
    period_start: captured_at.to_date,
    source: "webhook",
    metrics: metrics,
    empty: metrics.empty?,
    captured_at: captured_at
  )
end