Class: BMO::APNS::Notification::DeviceToken

Inherits:
Object
  • Object
show all
Defined in:
lib/bmo/apns/notification.rb

Overview

The DeviceToken is the id of a Device for an App

Defined Under Namespace

Classes: MalformedDeviceToken

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ DeviceToken

Returns a new instance of DeviceToken.



75
76
77
# File 'lib/bmo/apns/notification.rb', line 75

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



73
74
75
# File 'lib/bmo/apns/notification.rb', line 73

def token
  @token
end

Instance Method Details

#to_packageObject



79
80
81
# File 'lib/bmo/apns/notification.rb', line 79

def to_package
  [token].pack('H*')
end

#validate!Object



83
84
85
86
87
88
# File 'lib/bmo/apns/notification.rb', line 83

def validate!
  unless token =~ /^[a-z0-9]{64}$/i
    fail(MalformedDeviceToken, 'Malformed Device Token')
  end
  true
end