Class: HeyYou::Channels::FcmPush

Inherits:
Base
  • Object
show all
Defined in:
lib/hey_you/channels/fcm_push.rb

Class Method Summary collapse

Class Method Details

.send!(builder, **options) ⇒ Array{Hash}

Parameters:

  • builder (HeyYou::Builder)
    • builder with notifications texts and settings

  • [String] (Hash)

    a customizable set of options

  • [Hash] (Hash)

    a customizable set of options

Returns:

  • (Array{Hash})
    • FCM responses



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hey_you/channels/fcm_push.rb', line 26

def send!(builder, **options)
  options[:token] ||= options[:to]

  if options[:token].is_a?(Array)
    messages = options[:token].map { |token| build_message(builder, **options.merge(token: token)) }
  end

  messages ||= [build_message(builder, **options)]

  messages.map do |message|
    {
      receiver: message.receiver_hash,
      response: HeyYouFcmPush::Connection.instance.send_notification(message.to_h, validate_only: options[:validate_only])
    }
  end
end