class PushToSNS::PushNotifier
Public Class Methods
new(params = {})
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 3 def initialize(params = {}) params.each do |attr, value| public_send("#{attr}=", value) end end
Public Instance Methods
deliver()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 9 def deliver devices.each do |device| begin SendPushNotification.new(device).perform(full_notification_for_device(device)) rescue AWS::SNS::Errors::Base => e $stderr.puts "Device can't send push notifications: #{e.message}" end end end
devices()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 19 def devices raise "Please implement the method :devices to be able to load devices to notify." end
notification(device)
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 23 def notification(device) raise "Please implement the method :notification with the message to send" end
Private Instance Methods
badge()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 51 def badge @badge ||= self.class.badge end
call_or_read(proc_or_object, *arguments)
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 77 def call_or_read(proc_or_object, *arguments) if proc_or_object.respond_to?(:call) instance_exec(*arguments, &proc_or_object) else proc_or_object end end
full_notification_for_device(device)
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 29 def full_notification_for_device(device) defaults = { type: call_or_read(type, device), message: call_or_read(message, device), badge: call_or_read(badge, device), sound: call_or_read(sound, device), small_icon: call_or_read(small_icon, device), title: call_or_read(title, device), image: call_or_read(image, device), notId: call_or_read(notification_id, device) }.reject { |key, value| value.nil? } defaults.merge(notification(device)) end
image()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 63 def image @image ||= self.class.image end
message()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 47 def message @message ||= self.class.message end
notification_id()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 67 def notification_id @notification_id ||= self.class.notification_id end
small_icon()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 71 def small_icon @small_icon ||= self.class.small_icon end
sound()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 55 def sound @sound ||= self.class.sound end
title()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 59 def title @title ||= self.class.title end
type()
click to toggle source
# File lib/push_to_sns/push_notifier.rb, line 43 def type @type ||= self.class.type end