Class: Expo::Push::Receipt

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

Overview

A single receipt for a single notification.

  • In case of an #ok? receipt, no action need be taken

  • In case of an #error? receipt, holds the #message, #explain

Some failed receipts may expose which push token is not or no longer valid. This is exposed via #original_push_token.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, receipt_id:) ⇒ Receipt

Returns a new instance of Receipt.



17
18
19
20
# File 'lib/push/receipts.rb', line 17

def initialize(data:, receipt_id:)
  self.data = data
  self.receipt_id = receipt_id
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



15
16
17
# File 'lib/push/receipts.rb', line 15

def data
  @data
end

#receipt_idObject

Returns the value of attribute receipt_id.



15
16
17
# File 'lib/push/receipts.rb', line 15

def receipt_id
  @receipt_id
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/push/receipts.rb', line 44

def error?
  data['status'] == 'error'
end

#explainObject



36
37
38
# File 'lib/push/receipts.rb', line 36

def explain
  Expo::Push::Error.explain((data['details'] || {})['error'])
end

#messageObject



32
33
34
# File 'lib/push/receipts.rb', line 32

def message
  data.fetch('message')
end

#ok?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/push/receipts.rb', line 40

def ok?
  data['status'] == 'ok'
end

#original_push_tokenObject



22
23
24
25
26
27
28
29
30
# File 'lib/push/receipts.rb', line 22

def original_push_token
  return nil if ok?

  if message.include?('PushToken[')
    return /Expo(?:nent)?PushToken\[(?:[^\]]+?)\]/.match(message) { |match| match[0] }
  end

  /\A[a-z\d]{8}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{12}\z/i.match(message) { |match| match[0] }
end