Class: ActsAsPushable::GCM::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_pushable/gcm/notification.rb

Class Method Summary collapse

Class Method Details

.send(device:, title:, message:, **options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/acts_as_pushable/gcm/notification.rb', line 6

def self.send(device:, title:, message:, **options)
  payload = {
    popup: options.fetch("popup", true),
    popup_title: options.fetch("popup_title", nil),
    popup_body: options.fetch("popup_body", nil),
    popup_type: options.fetch("popup_type", 'alert'),
    popup_ok_button_text: options.fetch("popup_ok_button_text", 'Ok'),
    popup_cancel_button_text: options.fetch("popup_cancel_button_text", 'Cancel'),
    navigate_to_view: options.fetch("navigate_to_view", nil),
    navigate_to_view_as_modal: options.fetch("navigate_to_view_as_modal", true),
    navigate_to_view_parameters: options.fetch("navigate_to_view_parameters", {}),
  }

  gcm = ::GCM.new(ActsAsPushable.configuration.gcm_key)

  gcm_options = {
    data: {
      title: title,
      message: message,
    }.merge(payload)
  }

  response = gcm.send([device.token], gcm_options)
  if response[:not_registered_ids].include? device.token
    device.update_attribute 'invalidated_at', Time.now
  end
end