Class: ProMotion::PushNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/ProMotion/push_notification/push_notification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ PushNotification

Returns a new instance of PushNotification.



6
7
8
# File 'lib/ProMotion/push_notification/push_notification.rb', line 6

def initialize(n)
  self.notification = n
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



34
35
36
# File 'lib/ProMotion/push_notification/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

Instance Attribute Details

#notificationObject

Returns the value of attribute notification.



4
5
6
# File 'lib/ProMotion/push_notification/push_notification.rb', line 4

def notification
  @notification
end

Class Method Details

.fake_notification(args = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ProMotion/push_notification/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

.simulate(args = {}) ⇒ Object

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



40
41
42
# File 'lib/ProMotion/push_notification/push_notification.rb', line 40

def self.simulate(args = {})
  UIApplication.sharedApplication.delegate.on_push_notification self.fake_notification(args), args[:launched]
end

Instance Method Details

#alertObject



22
23
24
# File 'lib/ProMotion/push_notification/push_notification.rb', line 22

def alert
  aps["alert"] if aps
end

#apsObject



18
19
20
# File 'lib/ProMotion/push_notification/push_notification.rb', line 18

def aps
  self.notification["aps"]
end

#badgeObject



26
27
28
# File 'lib/ProMotion/push_notification/push_notification.rb', line 26

def badge
  aps["badge"] if aps
end

#soundObject



30
31
32
# File 'lib/ProMotion/push_notification/push_notification.rb', line 30

def sound
  aps["sound"] if aps
end

#to_jsonObject



14
15
16
# File 'lib/ProMotion/push_notification/push_notification.rb', line 14

def to_json
  PM.logger.warn "PM::PushNotification.to_json not implemented yet."
end

#to_sObject



10
11
12
# File 'lib/ProMotion/push_notification/push_notification.rb', line 10

def to_s
  self.notification.inspect
end