Class: InstagramConnect::Ingest::Envelope
- Inherits:
-
Struct
- Object
- Struct
- InstagramConnect::Ingest::Envelope
- Defined in:
- lib/instagram_connect/ingest/envelope.rb
Overview
One webhook event, plus the context needed to interpret it: which account it belongs to, which field Meta delivered it under, and when it actually happened on the wire (as opposed to when we got round to storing it).
Constant Summary collapse
- MAX_SECONDS =
Anything outside this is not a timestamp Meta could have sent, and storing it would corrupt every ordering that reads occurred_at.
4_102_444_800- MILLIS_FLOOR =
Below this, a value can only be SECONDS since the epoch: the smallest millisecond timestamp Meta could send (year 2001+) is ~10^12, and a second-count will not reach 10^11 until the year 5138.
100_000_000_000
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#config ⇒ Object
Returns the value of attribute config.
-
#entry_id ⇒ Object
Returns the value of attribute entry_id.
-
#event ⇒ Object
Returns the value of attribute event.
-
#event_type ⇒ Object
Returns the value of attribute event_type.
-
#field ⇒ Object
Returns the value of attribute field.
-
#object ⇒ Object
Returns the value of attribute object.
-
#occurred_at ⇒ Object
Returns the value of attribute occurred_at.
Class Method Summary collapse
-
.time_from(value) ⇒ Object
Meta is inconsistent on the wire: messaging webhooks stamp in MILLISECONDS, comment/mention change webhooks stamp entry.time in SECONDS.
Instance Method Summary collapse
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def account @account end |
#config ⇒ Object
Returns the value of attribute config
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def config @config end |
#entry_id ⇒ Object
Returns the value of attribute entry_id
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def entry_id @entry_id end |
#event ⇒ Object
Returns the value of attribute event
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def event @event end |
#event_type ⇒ Object
Returns the value of attribute event_type
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def event_type @event_type end |
#field ⇒ Object
Returns the value of attribute field
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def field @field end |
#object ⇒ Object
Returns the value of attribute object
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def object @object end |
#occurred_at ⇒ Object
Returns the value of attribute occurred_at
6 7 8 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 6 def occurred_at @occurred_at end |
Class Method Details
.time_from(value) ⇒ Object
Meta is inconsistent on the wire: messaging webhooks stamp in MILLISECONDS, comment/mention change webhooks stamp entry.time in SECONDS. Dividing everything by 1000 turned every comment webhook's clock into January 1970 — which read as "older than Meta's 7-day reply window" and silently skipped every realtime comment automation. The magnitude decides the unit; no caller has to know which field it came from.
26 27 28 29 30 31 32 33 34 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 26 def self.time_from(value) return nil if value.nil? number = value.to_i seconds = number >= MILLIS_FLOOR ? number / 1000.0 : number.to_f return nil unless seconds.finite? && seconds >= 0 && seconds <= MAX_SECONDS Time.at(seconds).utc end |
Instance Method Details
#dig(*keys) ⇒ Object
36 37 38 |
# File 'lib/instagram_connect/ingest/envelope.rb', line 36 def dig(*keys) event.dig(*keys) end |