Sha256: 0d9b30faa3a81ab93f243f1d9d00a8c416349955bf4623a1ecba2b0e6582dd35

Contents?: true

Size: 1.49 KB

Versions: 9

Compression:

Stored size: 1.49 KB

Contents

module NotifyUser
  class PubNub

    #sends push notification
    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
                  )

      pn_apns = {
        aps: {
          alert: notification.mobile_message,
          badge: notification.count_for_target,
          type: notification.type
        }
      }

      pn_apns[:aps][:action_id] = notification.params[:action_id] if notification.params[:action_id]
      pn_apns[:aps]['content-available'] = notification.params['content-available'] if notification.params['content-available']

      pn_gcm = {
        data: {
          notification_id: notification.id,
          message: notification.mobile_message,
          type: notification.type,
          unread_count: notification.count_for_target
        }
      }

      pn_gcm[:data][:action_id] = notification.params[:action_id] if notification.params[:action_id]

      pubnub.publish(
        channel: notification.target.uuid,
        http_sync: true,
        message: {
          pn_apns: pn_apns,
          pn_gcm: pn_gcm
        }
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
notify_user-0.3.2 app/models/notify_user/pub_nub.rb
notify_user-0.3.1 app/models/notify_user/pub_nub.rb
notify_user-0.1.4 app/models/notify_user/pub_nub.rb
notify_user-0.1.3 app/models/notify_user/pub_nub.rb
notify_user-0.1.2 app/models/notify_user/pub_nub.rb
notify_user-0.1.1 app/models/notify_user/pub_nub.rb
notify_user-0.0.30 app/models/notify_user/pub_nub.rb
notify_user-0.0.29 app/models/notify_user/pub_nub.rb
notify_user-0.0.28 app/models/notify_user/pub_nub.rb