Class: Expo::Push::Ticket

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject

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

Returns:

  • (Boolean)


47
48
49
# File 'lib/push/tickets.rb', line 47

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

#explainObject



39
40
41
# File 'lib/push/tickets.rb', line 39

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

#idObject



21
22
23
# File 'lib/push/tickets.rb', line 21

def id
  data.fetch('id')
end

#messageObject



35
36
37
# File 'lib/push/tickets.rb', line 35

def message
  data.fetch('message')
end

#ok?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/push/tickets.rb', line 43

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

#original_push_tokenObject



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 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