0.01
No commit activity in last 3 years
No release in over 3 years
Client for accessing Firebase Cloud Messaging APIs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Google API Client for FCM

Extension for original google-api-client with implementation of Firebase Cloud Messaging Server API via HTTP V1 protocol.

Note

FCM support was added to original google-api-client according docs.

Installation

Add this line to your application's Gemfile:

gem 'google-api-fcm'

And then execute:

$ bundle

Usage

require 'google/apis/messages'

# More Google Auth examples you can find in original gem
scope = Google::Apis::Messages::AUTH_MESSAGES
authorization = Google::Auth.get_application_default(scope)


service = Google::Apis::Messages::MessagesService.new(project_id: 'PROJECT-ID')
service.authorization = authorization
# Build notification message (with topic)
message = Google::Apis::Messages::Message.new(
  topic: 'news',
  notification: {
    title: 'Breaking news',
    body: 'Hell has frozen over'
  }
)

or

# Build notification message (with token)
message = Google::Apis::Messages::Message.new(
  token: 'bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1',
  notification: {
    title: 'Breaking news',
    body: 'Hell has frozen over'
  }
)
# Finally send the message to FCM
service.notify(message)

Set analytics label

The analytics label can be set when sending the message, in order to mark the message for analytics purposes

message = Google::Apis::Messages::Message.new(
  token: 'bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1',
  notification: {
    title: 'Breaking news',
    body: 'Hell has frozen over'
  },
  fcm_options: {
    analytics_label: 'test-label'
  }
)