Sha256: 8339c8f2953bb5320871b2c63ca7d85fd693f67d24042065e28c33bb1b246e34
Contents?: true
Size: 913 Bytes
Versions: 2
Compression:
Stored size: 913 Bytes
Contents
require 'json' module ApnsSimple class Notification attr_reader :token, :alert, :badge, :sound, :content_available attr_accessor :error def initialize(options) @token = options.fetch(:token) @alert = options[:alert] @badge = options[:badge] @sound = options[:sound] || 'default' @content_available = options[:content_available] end def payload payload = { aps: {} } payload[:aps][:alert] = alert if alert payload[:aps][:badge] = badge if badge payload[:aps][:sound] = sound if sound payload[:aps]['content-available'] = 1 if content_available packed_message = payload.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")} packed_token = [token.gsub(/[\s|<|>]/,'')].pack('H*') [0, 0, 32, packed_token, 0, packed_message.bytesize, packed_message].pack("ccca*cca*") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
apns_simple-0.2.0 | lib/apns_simple/notification.rb |
apns_simple-0.1.3 | lib/apns_simple/notification.rb |