class ApnsKit::Notification
Constants
- MAXIMUM_PAYLOAD_SIZE
Attributes
alert[RW]
custom_data[RW]
id[RW]
token[RW]
topic[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/apns_kit/notification.rb, line 18 def initialize(options) @token = options.delete(:token) || options.delete(:device) @alert = options.delete(:alert) @badge = options.delete(:badge) @sound = options.delete(:sound) @category = options.delete(:category) @expiry = options.delete(:expiry) @id = options.delete(:id) @priority = options.delete(:priority) @content_available = options.delete(:content_available) @topic = options.delete(:topic) @custom_data = options end
Public Instance Methods
header()
click to toggle source
# File lib/apns_kit/notification.rb, line 41 def header json = { ':scheme' => 'https', ':method' => 'POST', ':path' => "/3/device/#{token}", 'apns-id' => id, 'content-length' => payload.bytesize.to_s, 'apns-topic' => topic } json.merge!({ "apns-expiry" => @expiry }) if @expiry json.merge!({ "apns-priority" => @priority }) if @priority return json end
payload()
click to toggle source
# File lib/apns_kit/notification.rb, line 56 def payload json = {}.merge(@custom_data || {}).inject({}){|h,(k,v)| h[k.to_s] = v; h} json['aps'] ||= {} json['aps']['alert'] = @alert if @alert json['aps']['badge'] = @badge.to_i rescue 0 if @badge json['aps']['sound'] = @sound if @sound json['aps']['category'] = @category if @category json['aps']['content-available'] = 1 if @content_available JSON.dump(json) end
valid?()
click to toggle source
# File lib/apns_kit/notification.rb, line 37 def valid? payload.bytesize <= MAXIMUM_PAYLOAD_SIZE end