class Pushr::MessageGcm
Constants
- POSTFIX
Attributes
collapse_key[RW]
data[RW]
delay_while_idle[RW]
dry_run[RW]
notification_key[RW]
registration_ids[RW]
restricted_package_name[RW]
time_to_live[RW]
Public Instance Methods
to_hash()
click to toggle source
# File lib/pushr/message_gcm.rb, line 23 def to_hash hsh = { type: self.class.to_s, app: app, registration_ids: registration_ids, notification_key: notification_key, collapse_key: collapse_key, delay_while_idle: delay_while_idle, time_to_live: time_to_live, data: data } hsh[Pushr::Core.external_id_tag] = external_id if external_id hsh end
to_message()
click to toggle source
# File lib/pushr/message_gcm.rb, line 14 def to_message hsh = {} hsh['registration_ids'] = registration_ids %w(notification_key collapse_key delay_while_idle time_to_live data restricted_package_name dry_run).each do |variable| hsh[variable] = send(variable) if send(variable) end MultiJson.dump(hsh) end
Private Instance Methods
data_size()
click to toggle source
# File lib/pushr/message_gcm.rb, line 44 def data_size errors.add(:data, 'is more thank 4kb') if data && MultiJson.dump(data).bytes.count > 4096 end
registration_ids_array()
click to toggle source
# File lib/pushr/message_gcm.rb, line 32 def registration_ids_array if registration_ids.class == Array if registration_ids.size > 1000 errors.add(:registration_ids, 'is too big (max 1000)') elsif registration_ids.size == 0 errors.add(:registration_ids, 'is too small (min 1)') end else errors.add(:registration_ids, 'is not an array') unless registration_ids.class == Array end end