From 966b7b7b030e9afea7a978ef09d6e7baf8e68073 Mon Sep 17 00:00:00 2001 From: Edu Caselles Date: Wed, 22 Feb 2017 18:54:07 +0000 Subject: [PATCH] Adds `category` to notifications payload Signed-off-by: Emma Makinson --- lib/apns/notification.rb | 4 +++- spec/apns/notification_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/apns/notification.rb b/lib/apns/notification.rb index c6be868..3838e22 100644 --- a/lib/apns/notification.rb +++ b/lib/apns/notification.rb @@ -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 @@ -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] @@ -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 diff --git a/spec/apns/notification_spec.rb b/spec/apns/notification_spec.rb index b9ab67e..49b0c1b 100644 --- a/spec/apns/notification_spec.rb +++ b/spec/apns/notification_spec.rb @@ -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