Skip to content

moduloTech/modulofcm

Repository files navigation

Modulofcm

Firebase Cloud Messaging client library

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add modulofcm

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install modulofcm

Usage

Modulofcm.configure do |config|
  config.client(:legacy_client) do |client|
    client.api_key = 'My Legacy HTTP API key - will cease to function after June 2024.'
  end

  config.client(:new_client) do |client|
    client.api_token = 'my_token'
    client.google_application_credentials_path = ''
  end
end

# Any data you want to add to your notification
data = {
  id: 232_342,
  key: 'asd9adfiu6bn',
  mission_id: 234_323
}

# All keyword arguments are optional and references a field in Firebase documentation:
# Legacy API: https://firebase.google.com/docs/cloud-messaging/http-server-ref
# APIv1 : https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
#  title: The notification's title.
#    Legacy: `notification.title`
#    APIv1: `message.notification.title`
#  body: The notification's body text.
#    Legacy: `notification.body`
#    APIv1: `message.notification.body`,
#  sound: The sound to play when the device receives the notification.
#    Legacy: `notification.sound`
#    APIv1:
#      android: `message.android.sound`
#      ios: `message.apns.aps.sound` 
#  content_available: Allow to awaken the iOS app.
#    Legacy: `content_available` - ignored on non-iOS devices.
#    APIv1:
#      ios: `message.apns.aps.content-available`
#  data: Arbitrary key/value payload, which must be UTF-8 encoded. The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm").
#    Legacy: `data`
#    APIv1: `message.data`
Modulofcm.client(:legacy_client).push('Legacy device registration token', data: data, title: 'My title', body: 'The body', sound: 'notif.caf', content_available: true)
Modulofcm.client(:new_client).push('FCM new token', data: data, title: 'My title', body: 'The body', sound: 'notif.caf', content_available: true)

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/modulotech/modulofcm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Modulofcm project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Ruby Firebase Cloud Messaging client library

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published