Class: RubyPushNotifications::FCM::FCMNotification

Inherits:
Object
  • Object
show all
Includes:
NotificationResultsManager
Defined in:
lib/ruby-push-notifications/fcm/fcm_notification.rb

Overview

Encapsulates a FCM Notification. By default only Required fields are set. (developer.android.com/google/fcm/server-ref.html#send-downstream)

Author:

  • Carlos Alonso

Instance Attribute Summary collapse

Attributes included from NotificationResultsManager

#results

Instance Method Summary collapse

Constructor Details

#initialize(registration_ids, data) ⇒ FCMNotification

Initializes the notification

Parameters:

  • . (Array)

    Array with the receiver’s FCM registration ids.

  • . (Hash)

    Payload to send.



19
20
21
22
# File 'lib/ruby-push-notifications/fcm/fcm_notification.rb', line 19

def initialize(registration_ids, data)
  @registration_ids = registration_ids
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/ruby-push-notifications/fcm/fcm_notification.rb', line 11

def data
  @data
end

#registration_idsObject (readonly)

Returns the value of attribute registration_ids.



11
12
13
# File 'lib/ruby-push-notifications/fcm/fcm_notification.rb', line 11

def registration_ids
  @registration_ids
end

Instance Method Details

#as_fcm_jsonString

Credits: github.com/calos0921 - for this url change to FCM std

Returns:



31
32
33
# File 'lib/ruby-push-notifications/fcm/fcm_notification.rb', line 31

def as_fcm_json
  JSON.dump(make_payload)
end

#make_payloadObject



24
25
26
# File 'lib/ruby-push-notifications/fcm/fcm_notification.rb', line 24

def make_payload
  { registration_ids: @registration_ids }.merge(@data)
end