Class: ActsAsHocPushable::PushNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_hoc_pushable/push_notification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(devices:, title:, message:, **data) ⇒ PushNotification

Returns a new instance of PushNotification.



8
9
10
11
12
13
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 8

def initialize(devices:, title:, message:, **data)
  @devices = devices
  @title = title
  @message = message
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6

def data
  @data
end

#devicesObject

Returns the value of attribute devices.



6
7
8
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6

def devices
  @devices
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6

def message
  @message
end

#title=(value) ⇒ Object

Sets the attribute title

Parameters:

  • value

    the value to set the attribute title to.



6
7
8
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6

def title=(value)
  @title = value
end

Class Method Details

.send_push_notification(devices:, title: nil, message: nil, **data) ⇒ Object



24
25
26
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 24

def self.send_push_notification(devices:, title: nil, message: nil, **data)
  new(devices: devices, title: title, message: message, **data).perform
end

.send_push_notification_to_topic(topic:, title: nil, message: nil, **data) ⇒ Object



15
16
17
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 15

def self.send_push_notification_to_topic(topic:, title: nil, message: nil, **data)
  new(devices: nil, title: title, message: message, **data).perform_topic(topic: topic)
end

.send_silent_push_notification(devices:, **data) ⇒ Object



28
29
30
31
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 28

def self.send_silent_push_notification(devices:, **data)
  silent_data = data.merge({ content_avaiable: true })
  new(devices: devices, title: nil, message: nil, **silent_data).perform
end

.send_silent_push_notification_to_topic(topic:, **data) ⇒ Object



19
20
21
22
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 19

def self.send_silent_push_notification_to_topic(topic:, **data)
  silent_data = data.merge({ content_avaiable: true })
  new(devices: nil, title: nil, message: nil, **silent_data).perform_topic(topic: topic)
end

Instance Method Details

#performObject



38
39
40
41
42
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 38

def perform
  tokens = @devices.map {|d| d.token }
  response = client.send(tokens, push_options)
  handle_response(response)
end

#perform_topic(topic:) ⇒ Object



33
34
35
36
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 33

def perform_topic(topic:)
  response = client.send_to_topic(topic, push_options)
  handle_response(response)
end