Sha256: b60a37b3400707ca562cb8e296222a18e1b9d5e5f25f50fd842e813da6952106
Contents?: true
Size: 1 KB
Versions: 8
Compression:
Stored size: 1 KB
Contents
require 'json' module ApnsSimple class Notification attr_reader :token, :alert, :badge, :sound, :content_available, :custom_payload attr_accessor :error def initialize(options, custom_payload = {}) @token = options.fetch(:token) @alert = options[:alert] @badge = options[:badge] @sound = options[:sound] || 'default' @content_available = options[:content_available] @custom_payload = custom_payload 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 payload.merge! custom_payload 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
8 entries across 8 versions & 1 rubygems