Class: NotifyUser::PubNub

Inherits:
Object
  • Object
show all
Defined in:
app/models/notify_user/pub_nub.rb

Class Method Summary collapse

Class Method Details

.push_notification(notification) ⇒ Object

sends push notification



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/notify_user/pub_nub.rb', line 5

def self.push_notification(notification)
  pubnub = Pubnub.new(
    :origin => ENV['PN_ORIGIN'],
    :publish_key   => ENV['PN_PUBLISH_KEY'],
    :subscribe_key => ENV['PN_SUBSCRIBE_KEY'],
    :secret_key => ENV['PN_SECRET_KEY'],
    :logger => Logger.new(STDOUT)
  )

  pubnub.grant( auth_key: ENV['PN_SECRET_KEY'],
                :read => true,
                :write => true,
                :ttl => 525600,
                :http_sync => true
              )

  pubnub.publish(
    channel: notification.target.uuid,
    http_sync: true,
    :message => {
      aps: {
        alert: notification.params["message"]
      }
    }
  )
end