Module: ActsAsPushable::Pushable

Extended by:
ActiveSupport::Concern
Defined in:
lib/acts_as_pushable/pushable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_device(device_params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/acts_as_pushable/pushable.rb', line 22

def add_device(device_params)
  device = build_device(device_params)
  if device.save
    return device
  else
    device.errors.each do |attribute, message|
      errors.add(:devices, "#{attribute} #{message}")
    end
    return false
  end
end

#add_device!(device_params) ⇒ Object



34
35
36
37
38
# File 'lib/acts_as_pushable/pushable.rb', line 34

def add_device!(device_params)
  device = build_device(device_params)
  device.save!
  return device
end

#android_devicesObject



18
19
20
# File 'lib/acts_as_pushable/pushable.rb', line 18

def android_devices
  devices.where(platform: 'android')
end

#ios_devicesObject



14
15
16
# File 'lib/acts_as_pushable/pushable.rb', line 14

def ios_devices
  devices.where(platform: 'ios')
end

#send_push_notification(title:, message:, **options) ⇒ Object



40
41
42
43
44
# File 'lib/acts_as_pushable/pushable.rb', line 40

def send_push_notification(title:, message:, **options)
  devices.each do |device|
    device.send_push_notification(title: title, message: message, **options)
  end
end