Class: Expo::Push::Receipts

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

Overview

Receipts represent a single call to the receipts endpoint. It holds both the successfully retrieved receipts, as well as the still unresolved IDs.

You MUST iterate #each_error and first check if its an Error, which would be the case if the entire call failed. Otherwise, it will iterate through each receipt that indicates a failed push.

Keep calling the receipts endpoint until #unresolved_ids is empty, or a day has passed at least.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(results:, requested_ids:) ⇒ Receipts

Returns a new instance of Receipts.



67
68
69
70
# File 'lib/push/receipts.rb', line 67

def initialize(results:, requested_ids:)
  self.results = results
  self.requested_ids = requested_ids
end

Instance Method Details

#eachObject



72
73
74
75
76
77
78
# File 'lib/push/receipts.rb', line 72

def each
  results.each do |receipt|
    next unless receipt.ok?

    yield receipt
  end
end

#each_errorObject



80
81
82
83
84
85
86
87
# File 'lib/push/receipts.rb', line 80

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

    yield receipt
  end
end

#unresolved_idsObject



89
90
91
# File 'lib/push/receipts.rb', line 89

def unresolved_ids
  requested_ids - results.map(&:receipt_id)
end