module Rpush::Client::ActiveModel::Gcm::Notification
Constants
- GCM_PRIORITIES
- GCM_PRIORITY_HIGH
- GCM_PRIORITY_NORMAL
Public Class Methods
included(base)
click to toggle source
# File lib/rpush/client/active_model/gcm/notification.rb, line 10 def self.included(base) base.instance_eval do validates :registration_ids, presence: true validates :priority, inclusion: { in: GCM_PRIORITIES }, allow_nil: true validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096 validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000 validates_with Rpush::Client::ActiveModel::Gcm::ExpiryCollapseKeyMutualInclusionValidator end end
Public Instance Methods
as_json(options = nil)
click to toggle source
# File lib/rpush/client/active_model/gcm/notification.rb, line 37 def as_json(options = nil) json = { 'registration_ids' => registration_ids, 'delay_while_idle' => delay_while_idle, 'data' => data } json['collapse_key'] = collapse_key if collapse_key json['content_available'] = content_available if content_available json['notification'] = notification if notification json['priority'] = priority_for_notification if priority json['time_to_live'] = expiry if expiry json end
priority=(priority)
click to toggle source
This is a hack. The schema defines `priority` to be an integer, but GCM expects a string. But for users of rpush to have an API they might expect (setting priority to `high`, not 10) we do a little conversion here. I'm not happy about it, but this will have to do until I can take a further look.
Calls superclass method
# File lib/rpush/client/active_model/gcm/notification.rb, line 26 def priority=(priority) case priority when 'high' super(GCM_PRIORITY_HIGH) when 'normal' super(GCM_PRIORITY_NORMAL) else errors.add(:priority, 'must be one of either "normal" or "high"') end end
priority_for_notification()
click to toggle source
# File lib/rpush/client/active_model/gcm/notification.rb, line 51 def priority_for_notification return 'high' if priority == GCM_PRIORITY_HIGH 'normal' if priority == GCM_PRIORITY_NORMAL end