Permalink
Browse files

Added some rdoc.

  • Loading branch information...
1 parent a740b45 commit bae347d3dc50560d65161811c8e7ab7e20081ba2 @markbates markbates committed Jul 23, 2009
@@ -6,6 +6,9 @@ class APN::Device < ActiveRecord::Base
validates_uniqueness_of :token
validates_format_of :token, :with => /^[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}\s[a-z0-9]{8}$/
+ # If the token comes in like this:
+ # '<5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz>'
+ # Then the '<' and '>' will be stripped off.
def token=(token)
res = token.scan(/\<(.+)\>/).first
unless res.nil? || res.empty?
@@ -14,6 +17,7 @@ def token=(token)
write_attribute('token', token)
end
+ # Returns the hexadecimal representation of the device's token.
def to_hexa
[self.token.delete(' ')].pack('H*')
end
@@ -43,6 +43,7 @@ def to_apple_json
self.apple_hash.to_json
end
+ # Creates the binary message needed to send to Apple.
def message_for_sending
json = self.to_apple_json
message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
@@ -8,7 +8,7 @@ def self.up
t.string :device_language, :size => 5 # if you don't want to send localized strings
t.text :payload
t.string :sound
- t.string :alert
+ t.string :alert, :size => 150
t.integer :badge
t.datetime :sent_at
t.timestamps

0 comments on commit bae347d

Please sign in to comment.