Class: RubyPushNotifications::FCM::FCMPusher

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

Overview

This class is responsible for sending notifications to the FCM service.

Author:

  • Carlos Alonso

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ FCMPusher

Initializes the FCMPusher

Parameters:

  • key (String)
  • options (Hash) (defaults to: {})

    optional. Options for FCMPusher. Currently supports:

    • url [String]: URL of the FCM endpoint. Defaults to the official FCM URL.

    • open_timeout [Integer]: Number of seconds to wait for the connection to open. Defaults to 30.

    • read_timeout [Integer]: Number of seconds to wait for one block to be read. Defaults to 30.



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

def initialize(key, options = {})
  @key = key
  @options = options
end

Instance Method Details

#push(notifications) ⇒ Object

Actually pushes the given notifications. Assigns every notification an array with the result of each individual notification.

Parameters:

  • notifications (Array)

    . Array of FCMNotification to send.



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

def push(notifications)
  notifications.each do |notif|
    notif.results = FCMConnection.post notif.as_fcm_json, @key, @options
  end
end