Class: Expo::Push::Receipt
- Inherits:
-
Object
- Object
- Expo::Push::Receipt
- 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
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#receipt_id ⇒ Object
readonly
Returns the value of attribute receipt_id.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #explain ⇒ Object
-
#initialize(data:, receipt_id:) ⇒ Receipt
constructor
A new instance of Receipt.
- #message ⇒ Object
- #ok? ⇒ Boolean
- #original_push_token ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
15 16 17 |
# File 'lib/push/receipts.rb', line 15 def data @data end |
#receipt_id ⇒ Object
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
44 45 46 |
# File 'lib/push/receipts.rb', line 44 def error? data['status'] == 'error' end |
#explain ⇒ Object
36 37 38 |
# File 'lib/push/receipts.rb', line 36 def explain Expo::Push::Error.explain((data['details'] || {})['error']) end |
#message ⇒ Object
32 33 34 |
# File 'lib/push/receipts.rb', line 32 def data.fetch('message') end |
#ok? ⇒ Boolean
40 41 42 |
# File 'lib/push/receipts.rb', line 40 def ok? data['status'] == 'ok' end |
#original_push_token ⇒ Object
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 .include?('PushToken[') return /Expo(?:nent)?PushToken\[(?:[^\]]+?)\]/.match() { |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() { |match| match[0] } end |