Module: Rpush::Client::ActiveModel::Webpush::Notification

Included in:
Rpush::Client::ActiveRecord::Webpush::Notification, Redis::Webpush::Notification
Defined in:
lib/rpush/client/active_model/webpush/notification.rb

Defined Under Namespace

Classes: RegistrationValidator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 22

def self.included(base)
  base.instance_eval do
    alias_attribute :time_to_live, :expiry

    validates :registration_ids, presence: true
    validates :data, presence: true
    validates :time_to_live, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true

    validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096
    validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1
    validates_with RegistrationValidator
  end
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 54

def as_json(_options = nil)
  {
    'data'             => data,
    'time_to_live'     => time_to_live,
    'registration_ids' => registration_ids
  }
end

#data=(value) ⇒ Object



36
37
38
39
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 36

def data=(value)
  value = value.stringify_keys if value.respond_to?(:stringify_keys)
  super value
end

#messageObject



45
46
47
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 45

def message
  data['message'].presence if data
end

#subscriptionObject



41
42
43
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 41

def subscription
  @subscription ||= registration_ids.first.deep_symbolize_keys
end

#urgencyObject



50
51
52
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 50

def urgency
  data['urgency'].presence if data
end