Skip to content

Commit

Permalink
Added some rdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jul 23, 2009
1 parent a740b45 commit bae347d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/apn_on_rails/app/models/apn/device.rb
Expand Up @@ -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?
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/apn_on_rails/app/models/apn/notification.rb
Expand Up @@ -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}"
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit bae347d

Please sign in to comment.