module Rpush::Client::ActiveModel::Webpush::Notification
Public Class Methods
included(base)
click to toggle source
# 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
Public Instance Methods
as_json(_options = nil)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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
message()
click to toggle source
# File lib/rpush/client/active_model/webpush/notification.rb, line 45 def message data['message'].presence if data end
subscription()
click to toggle source
# File lib/rpush/client/active_model/webpush/notification.rb, line 41 def subscription @subscription ||= registration_ids.first.deep_symbolize_keys end
urgency()
click to toggle source
webpush-wg.github.io/webpush-protocol/#urgency
# File lib/rpush/client/active_model/webpush/notification.rb, line 50 def urgency data['urgency'].presence if data end