Sha256: e0075a38ce3f9eed31e9240eab33c44e4cdc865167647a80945561514d4abbba

Contents?: true

Size: 996 Bytes

Versions: 8

Compression:

Stored size: 996 Bytes

Contents

module ProMotion
  class PushNotification

    attr_accessor :notification

    def initialize(n)
      self.notification = n
    end

    def to_s
      self.notification.inspect
    end

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

    def aps
      self.notification["aps"]
    end

    def alert
      aps["alert"] if aps
    end

    def badge
      aps["badge"] if aps
    end

    def sound
      aps["sound"] if aps
    end

    # For testing from the REPL
    # > PM::PushNotification.simulate alert: "My test message", badge: 4
    def self.simulate(args = {})
      UIApplication.sharedApplication.delegate.on_push_notification self.fake_notification(args)
    end

    def self.fake_notification(args = {})
      self.new({
        "aps" => {
          "alert" => args[:alert] || "Test Push Notification",
          "badge" => args[:badge] || 2,
          "sound" => args[:sound] || "default"
        }
      })
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ProMotion-0.7.8 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.6 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.5 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.4 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.3 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.2 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.1 lib/ProMotion/push_notifications/push_notification.rb
ProMotion-0.7.0 lib/ProMotion/push_notifications/push_notification.rb