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.



89
90
91
# File 'lib/bmo/apns/notification.rb', line 89

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



87
88
89
# File 'lib/bmo/apns/notification.rb', line 87

def token
  @token
end

Instance Method Details

#to_packageObject



93
94
95
# File 'lib/bmo/apns/notification.rb', line 93

def to_package
  [1, 32, token].pack('cnH64')
end

#validate!Object



97
98
99
100
101
102
# File 'lib/bmo/apns/notification.rb', line 97

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