Class: Expo::Push::Tickets

Inherits:
Object
  • Object
show all
Defined in:
lib/push/tickets.rb

Overview

Tickets are paged: each batch when sending the notifications is one tickets entry. Each tickets entry has many tickets.

To ease exploration and continuation of the tickets, use the folowing methods:

  • #batch_ids: slices all the receipts into chunks

  • #each: iterates over each single ticket that is NOT an error

  • #each_error: iterates over each errorered batch and failed ticket

You MUST handle each error, and you MUST first check if its an Error or not, because of the way an entire batch call can fail.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ Tickets

Returns a new instance of Tickets.



73
74
75
# File 'lib/push/tickets.rb', line 73

def initialize(results)
  self.results = results
end

Instance Method Details

#batch_idsObject



83
84
85
# File 'lib/push/tickets.rb', line 83

def batch_ids
  ids.each_slice(PUSH_NOTIFICATION_RECEIPT_CHUNK_LIMIT).to_a
end

#eachObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/push/tickets.rb', line 87

def each
  results.each do |tickets|
    next if tickets.is_a?(Error)

    tickets.each do |ticket|
      next unless ticket.ok?

      yield ticket
    end
  end
end

#each_errorObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/push/tickets.rb', line 99

def each_error
  results.each do |tickets|
    if tickets.is_a?(Error)
      yield tickets
    else
      tickets.each do |ticket|
        next unless ticket.error?

        yield ticket
      end
    end
  end
end

#idsObject



77
78
79
80
81
# File 'lib/push/tickets.rb', line 77

def ids
  [].tap do |ids|
    each { |ticket| ids << ticket.id }
  end
end