Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Adds category to notifications payload #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/apns/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module APNS
require 'openssl'

class Notification
attr_accessor :device_token, :alert, :badge, :sound, :other, :priority
attr_accessor :device_token, :alert, :badge, :sound, :other, :priority, :category
attr_accessor :message_identifier, :expiration_date
attr_accessor :content_available

Expand All @@ -13,6 +13,7 @@ def initialize(device_token, message)
self.badge = message[:badge]
self.sound = message[:sound]
self.other = message[:other]
self.category = message[:category]
self.message_identifier = message[:message_identifier]
self.content_available = !message[:content_available].nil?
self.expiration_date = message[:expiration_date]
Expand Down Expand Up @@ -60,6 +61,7 @@ def packaged_message
aps['aps']['alert'] = self.alert if self.alert
aps['aps']['badge'] = self.badge if self.badge
aps['aps']['sound'] = self.sound if self.sound
aps['aps']['category'] = self.category if self.category
aps['aps']['content-available'] = 1 if self.content_available

aps.merge!(self.other) if self.other
Expand Down
4 changes: 2 additions & 2 deletions spec/apns/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
describe '#packaged_message' do

it "should return JSON with notification information" do
n = APNS::Notification.new('device_token', {:alert => 'Hello iPhone', :badge => 3, :sound => 'awesome.caf'})
n.packaged_message.should == "{\"aps\":{\"alert\":\"Hello iPhone\",\"badge\":3,\"sound\":\"awesome.caf\"}}"
n = APNS::Notification.new('device_token', {:alert => 'Hello iPhone', :badge => 3, :sound => 'awesome.caf', :category => 'AWESOME_CATEGORY'})
n.packaged_message.should == "{\"aps\":{\"alert\":\"Hello iPhone\",\"badge\":3,\"sound\":\"awesome.caf\",\"category\":\"AWESOME_CATEGORY\"}}"
end

it "should not include keys that are empty in the JSON" do
Expand Down