class ProMotion::PushNotification

Attributes

notification[RW]

Public Class Methods

fake_notification(args = {}) click to toggle source
# File lib/ProMotion/push_notification.rb, line 44
def self.fake_notification(args = {})
  self.new({
    "aps" => {
      "alert" => args.delete(:alert) || "Test Push Notification",
      "badge" => args.delete(:badge) || 2,
      "sound" => args.delete(:sound) || "default"
    },
    "channels" => args.delete(:channels) || [
      "channel_name"
    ]
  }.merge(args))
end
new(n) click to toggle source
# File lib/ProMotion/push_notification.rb, line 6
def initialize(n)
  self.notification = n
end
simulate(args = {}) click to toggle source

For testing from the REPL > ProMotion::PushNotification.simulate alert: “My test message”, badge: 4

# File lib/ProMotion/push_notification.rb, line 40
def self.simulate(args = {})
  UIApplication.sharedApplication.delegate.on_push_notification self.fake_notification(args), args[:launched]
end

Public Instance Methods

alert() click to toggle source
# File lib/ProMotion/push_notification.rb, line 22
def alert
  aps["alert"] if aps
end
aps() click to toggle source
# File lib/ProMotion/push_notification.rb, line 18
def aps
  self.notification["aps"]
end
badge() click to toggle source
# File lib/ProMotion/push_notification.rb, line 26
def badge
  aps["badge"] if aps
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/ProMotion/push_notification.rb, line 34
def method_missing(meth, *args, &block)
  aps[meth.to_s] || aps[meth.to_sym] || self.notification[meth.to_s] || self.notification[meth.to_sym] || super
end
sound() click to toggle source
# File lib/ProMotion/push_notification.rb, line 30
def sound
  aps["sound"] if aps
end
to_json() click to toggle source
# File lib/ProMotion/push_notification.rb, line 14
def to_json
  ProMotion.logger.warn "ProMotion::PushNotification.to_json not implemented yet."
end
to_s() click to toggle source
# File lib/ProMotion/push_notification.rb, line 10
def to_s
  self.notification.inspect
end