Class: Rapns::Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MultiJsonHelper
Defined in:
lib/rapns/notification.rb

Direct Known Subclasses

Apns::Notification, Gcm::Notification

Instance Method Summary collapse

Methods included from MultiJsonHelper

#multi_json_dump, #multi_json_load

Constructor Details

#initialize(*args) ⇒ Notification

Returns a new instance of Notification.



28
29
30
31
32
33
34
35
# File 'lib/rapns/notification.rb', line 28

def initialize(*args)
  attributes = args.first
  if attributes.is_a?(Hash) && attributes.keys.include?(:attributes_for_device)
    msg = ":attributes_for_device via mass-assignment is deprecated. Use :data or the attributes_for_device= instance method."
    Rapns::Deprecation.warn(msg)
  end
  super
end

Instance Method Details

#dataObject



43
44
45
# File 'lib/rapns/notification.rb', line 43

def data
  multi_json_load(read_attribute(:data)) if read_attribute(:data)
end

#data=(attrs) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'lib/rapns/notification.rb', line 37

def data=(attrs)
  return unless attrs
  raise ArgumentError, "must be a Hash" if !attrs.is_a?(Hash)
  write_attribute(:data, multi_json_dump(attrs))
end

#payloadObject



47
48
49
# File 'lib/rapns/notification.rb', line 47

def payload
  multi_json_dump(as_json)
end

#payload_sizeObject



51
52
53
# File 'lib/rapns/notification.rb', line 51

def payload_size
  payload.bytesize
end