Class: APN::Device

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/apn_on_rails/app/models/apn/device.rb

Overview

Represents an iPhone (or other APN enabled device). An APN::Device can have many APN::Notification.

Example:

Device.create(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')

Instance Method Summary collapse

Instance Method Details

#to_hexaObject

Returns the hexadecimal representation of the device’s token.



28
29
30
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 28

def to_hexa
  [self.token.delete(' ')].pack('H*')
end

#token=(token) ⇒ Object

Stores the token (Apple’s device ID) of the iPhone (device).

If the token comes in like this:

'<5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz>'

Then the ‘<’ and ‘>’ will be stripped off.



19
20
21
22
23
24
25
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 19

def token=(token)
  res = token.scan(/\<(.+)\>/).first
  unless res.nil? || res.empty?
    token = res.first
  end
  write_attribute('token', token)
end