Class: Expo::Push::Ticket
- Inherits:
-
Object
- Object
- Expo::Push::Ticket
- Defined in:
- lib/push/tickets.rb
Overview
A ticket represents a single receipt ticket.
-
In case of an #ok? ticket, holds the receipt id in #id
-
In case of an #error? ticket, holds the #message, #explain
Some failed tickets 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.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #explain ⇒ Object
- #id ⇒ Object
-
#initialize(data) ⇒ Ticket
constructor
A new instance of Ticket.
- #message ⇒ Object
- #ok? ⇒ Boolean
- #original_push_token ⇒ Object
Constructor Details
#initialize(data) ⇒ Ticket
Returns a new instance of Ticket.
17 18 19 |
# File 'lib/push/tickets.rb', line 17 def initialize(data) self.data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
15 16 17 |
# File 'lib/push/tickets.rb', line 15 def data @data end |
Instance Method Details
#error? ⇒ Boolean
47 48 49 |
# File 'lib/push/tickets.rb', line 47 def error? data['status'] == 'error' end |
#explain ⇒ Object
39 40 41 |
# File 'lib/push/tickets.rb', line 39 def explain Expo::Push::Error.explain((data['details'] || {})['error']) end |
#id ⇒ Object
21 22 23 |
# File 'lib/push/tickets.rb', line 21 def id data.fetch('id') end |
#message ⇒ Object
35 36 37 |
# File 'lib/push/tickets.rb', line 35 def data.fetch('message') end |
#ok? ⇒ Boolean
43 44 45 |
# File 'lib/push/tickets.rb', line 43 def ok? data['status'] == 'ok' end |
#original_push_token ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/push/tickets.rb', line 25 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 |