Class: InstagramConnect::Ingest::Envelope

Inherits:
Struct
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accountObject

Returns the value of attribute account

Returns:

  • (Object)

    the current value of account



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def 
  @account
end

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def config
  @config
end

#entry_idObject

Returns the value of attribute entry_id

Returns:

  • (Object)

    the current value of entry_id



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def entry_id
  @entry_id
end

#eventObject

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def event
  @event
end

#event_typeObject

Returns the value of attribute event_type

Returns:

  • (Object)

    the current value of event_type



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def event_type
  @event_type
end

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def field
  @field
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



6
7
8
# File 'lib/instagram_connect/ingest/envelope.rb', line 6

def object
  @object
end

#occurred_atObject

Returns the value of attribute occurred_at

Returns:

  • (Object)

    the current value of 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(millis) ⇒ Object

Meta timestamps are milliseconds since the epoch. Ordering off this rather than our own created_at is what stops a delayed webhook batch silently reordering a conversation.



17
18
19
20
21
22
23
24
# File 'lib/instagram_connect/ingest/envelope.rb', line 17

def self.time_from(millis)
  return nil if millis.nil?

  seconds = millis.to_i / 1000.0
  return nil unless seconds.finite? && seconds >= 0 && seconds <= MAX_SECONDS

  Time.at(seconds).utc
end

Instance Method Details

#dig(*keys) ⇒ Object



26
27
28
# File 'lib/instagram_connect/ingest/envelope.rb', line 26

def dig(*keys)
  event.dig(*keys)
end