Created
October 16, 2011 12:58
-
-
Save naquad/1290847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts the supplied options into the JSON needed for Apple's push notification servers. | |
# Extracts :alert, :badge, and :sound keys into the 'aps' hash, merges any other hash data | |
# into the root of the hash to encode and send to apple. | |
def packaged_message | |
opts = @options.clone # Don't destroy our pristine copy | |
hsh = {'aps' => {}} | |
hsh['aps']['alert'] = opts.delete(:alert).to_s if opts[:alert] | |
hsh['aps']['badge'] = opts.delete(:badge).to_i if opts[:badge] | |
if sound = opts.delete(:sound) | |
hsh['aps']['sound'] = sound.is_a?(TrueClass) ? 'default' : sound.to_s | |
end | |
hsh.merge!(opts) | |
ActiveSupport::JSON::encode(hsh) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment