Class: InstagramConnect::Ingest::Summary

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/instagram_connect/ingest/summary.rb

Overview

What one webhook delivery produced. Behaves as a Hash so the return value of Ingest.call stays compatible with hosts written against 0.2.x, which read summary and friends.

Constant Summary collapse

COUNTERS =
{
  "messages" => :messages,
  "message_echoes" => :messages,
  "messaging_postbacks" => :postbacks,
  "comments" => :comments,
  "live_comments" => :comments
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSummary

Returns a new instance of Summary.



18
19
20
21
22
23
24
25
26
# File 'lib/instagram_connect/ingest/summary.rb', line 18

def initialize
  @messages = 0
  @comments = 0
  @postbacks = 0
  @duplicates = 0
  @unhandled = 0
  @failed = 0
  @callback_errors = 0
end

Instance Attribute Details

#callback_errorsObject

Returns the value of attribute callback_errors.



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

def callback_errors
  @callback_errors
end

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#duplicatesObject

Returns the value of attribute duplicates.



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

def duplicates
  @duplicates
end

#failedObject

Returns the value of attribute failed.



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

def failed
  @failed
end

#messagesObject

Returns the value of attribute messages.



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

def messages
  @messages
end

#postbacksObject

Returns the value of attribute postbacks.



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

def postbacks
  @postbacks
end

#unhandledObject

Returns the value of attribute unhandled.



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

def unhandled
  @unhandled
end

Instance Method Details

#==(other) ⇒ Object



65
66
67
# File 'lib/instagram_connect/ingest/summary.rb', line 65

def ==(other)
  other.respond_to?(:to_h) ? to_h == other.to_h : super
end

#[](key) ⇒ Object



61
62
63
# File 'lib/instagram_connect/ingest/summary.rb', line 61

def [](key)
  to_h[key.to_sym]
end

#count(field) ⇒ Object



28
29
30
31
32
33
# File 'lib/instagram_connect/ingest/summary.rb', line 28

def count(field)
  counter = COUNTERS[field]
  return if counter.nil?

  public_send(:"#{counter}=", public_send(counter) + 1)
end

#each(&block) ⇒ Object



69
70
71
# File 'lib/instagram_connect/ingest/summary.rb', line 69

def each(&block)
  to_h.each(&block)
end

#skippedObject

0.2.x reported one skipped number covering both "we have seen this already" and "we do not parse this". They are different problems now — duplicates are healthy, unhandled events are a backlog to replay — but the combined figure is kept so existing hosts keep working.



39
40
41
# File 'lib/instagram_connect/ingest/summary.rb', line 39

def skipped
  duplicates + unhandled
end

#to_hObject Also known as: to_hash



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/instagram_connect/ingest/summary.rb', line 43

def to_h
  {
    messages: messages,
    comments: comments,
    postbacks: postbacks,
    skipped: skipped,
    duplicates: duplicates,
    unhandled: unhandled,
    failed: failed,
    callback_errors: callback_errors
  }
end