All Projects → miyataka → fcmpush

miyataka / fcmpush

Licence: MIT license
Firebase Cloud Messaging API wrapper for Ruby, suppot HTTP v1 API including access_token auto refresh feature.

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to fcmpush

andpush
Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)
Stars: ✭ 83 (+88.64%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging, push
fcm
Golang client library for Firebase Cloud Messaging.
Stars: ✭ 22 (-50%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
Push Receiver
A library to subscribe to GCM/FCM and receive notifications within a node process.
Stars: ✭ 125 (+184.09%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
FCM-OnDeviceNotificationScheduler
Demo implementation to Schedule FCM Notifications on Android Device using AlarmManager + WorkManager.
Stars: ✭ 111 (+152.27%)
Mutual labels:  fcm, firebase-cloud-messaging, fcm-notifications
Pushraven
A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
Stars: ✭ 67 (+52.27%)
Mutual labels:  fcm, firebase-cloud-messaging, push
Fcm Django
FCM Django: Send push notifications via django to websites, iOS & android mobile devices through FCM (Firebase Cloud Messaging)
Stars: ✭ 495 (+1025%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
laravel-firebase
Laravel FCM (Firebase Cloud Messaging) Notification Channel
Stars: ✭ 25 (-43.18%)
Mutual labels:  fcm, firebase-cloud-messaging, fcm-notifications
Easynotifylibproject
Send firebase notifications to your users very easily: A new Android Lib
Stars: ✭ 31 (-29.55%)
Mutual labels:  push-notifications, fcm, push
Electron Push Receiver
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
Stars: ✭ 158 (+259.09%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
Materialize Sass
Materializecss rubygem for Rails Asset Pipeline / Sprockets
Stars: ✭ 785 (+1684.09%)
Mutual labels:  rubygems, gem
Tabler Rubygem
Rubygem for https://tabler.github.io
Stars: ✭ 77 (+75%)
Mutual labels:  rubygems, gem
Instagram Crawler
Crawl instagram photos, posts and videos for download.
Stars: ✭ 178 (+304.55%)
Mutual labels:  rubygems, gem
jquery-datatables
Jquery datatables ruby gems for assets pipeline
Stars: ✭ 73 (+65.91%)
Mutual labels:  rubygems, gem
sinator
Sinatra application generator
Stars: ✭ 19 (-56.82%)
Mutual labels:  rubygems, gem
harvesting
Ruby wrapper for the Harvest API v2
Stars: ✭ 24 (-45.45%)
Mutual labels:  rubygems, gem
Onesignal Cordova Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Stars: ✭ 214 (+386.36%)
Mutual labels:  push-notifications, fcm
mobile-push
A push notification library
Stars: ✭ 21 (-52.27%)
Mutual labels:  push-notifications, firebase-cloud-messaging
hms-push-serverdemo-java
Java sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.
Stars: ✭ 39 (-11.36%)
Mutual labels:  push-notifications, push
FcmNotificationHandler
Android library that helps to construct and launch system tray notifications from FCM Notification messages received when the app is in foreground mimicking the default format and behavior applied when the app is background.
Stars: ✭ 18 (-59.09%)
Mutual labels:  push-notifications, fcm
ejabberd mod gcm
Google Cloud Messaging API for Ejabberd (PUSH Messages)
Stars: ✭ 27 (-38.64%)
Mutual labels:  push-notifications, push

Fcmpush Build Status Gem Version

Fcmpush is an Firebase Cloud Messaging(FCM) Client. It implements FCM HTTP v1 API, including Auto Refresh access_token feature, and batch request!! This gem supports HTTP v1 API only, NOT supported legacy HTTP protocol.

fcmpush is highly inspired by andpush gem.

Installation

Add this line to your application's Gemfile:

gem 'fcmpush'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fcmpush

Usage

on Rails, config/initializers/fcmpush.rb

Fcmpush.configure do |config|
  ## for message push
  # firebase web console => project settings => service account => firebase admin sdk => generate new private key

  # pass string of path to credential file to config.json_key_io
  config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
  # Or content of json key file wrapped with StringIO
  # config.json_key_io = StringIO.new('{ ... }')

  # Or set environment variables
  # ENV['GOOGLE_ACCOUNT_TYPE'] = 'service_account'
  # ENV['GOOGLE_CLIENT_ID'] = '000000000000000000000'
  # ENV['GOOGLE_CLIENT_EMAIL'] = '[email protected]'
  # ENV['GOOGLE_PRIVATE_KEY'] = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n\'

  ## for topic subscribe/unsubscribe because they use regacy auth
  # firebase web console => project settings => cloud messaging => Project credentials => Server key
  config.server_key = 'your firebase server key'
  # Or set environment variables
  # ENV['FCM_SERVER_KEY'] = 'your firebase server key'
end

for more detail. see here.

push message

require 'fcmpush'

project_id   = "..." # Your project_id
device_token = "..." # The device token of the device you'd like to push a message to

client  = Fcmpush.new(project_id)
payload = { # ref. https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
  message: {
    token: device_token,
    notification: {
      title: "this is title",
      body: "this is message body"
    }
  }
}

response = client.push(payload)

json = response.json
json[:name] # => "projects/[your_project_id]/messages/0:1571037134532751%31bd1c9631bd1c96"

push messages in batch

require 'fcmpush'

project_id   = "..." # Your project_id
device_tokens = ["...A", "...B", "...C"] # The device token of the device you'd like to push a message to

client  = Fcmpush.new(project_id)

payloads = device_tokens.map do |token|
  { # ref. https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
    message: {
      token: token,
      notification: {
        title: "this is title",
        body: "this is message body"
      }
    }
  }
end

response = client.batch_push(payloads)

response_array = response.json
response_array.first[:name] # => "projects/[your_project_id]/messages/0:1571037134532751%31bd1c9631bd1c96"

topic subscribe/unsubscribe

require 'fcmpush'

project_id   = "..." # Your project_id
topic = "your_topic_name"
device_tokens = ["device_tokenA", "device_tokenB", ...] # The device tokens of the device you'd like to subscribe

client  = Fcmpush.new(project_id)

response = client.subscribe(topic, device_tokens)
# response = client.unsubscribe(topic, device_tokens)

json = response.json
json[:results] # => [{}, {"error":"NOT_FOUND"}, ...]  ref. https://developers.google.com/instance-id/reference/server#example_result_3

Performance

  • fcmpush's performance is good. (about the same as fastest one!)
  • And fcmpush supports batch request feature! batch request not use in benchmarking. Because, it not supported by other gems.
  • andpush is the fastest, but it uses legacy HTTP API.
  • fcmpush is fastest in gems using V1 HTTP API(fcmpush, google-api-fcm, firebase_cloud_messenger).
  • I excluded google-api-fcm gem because it can't run in ruby 3.
  • benchmark detail is here.
Warming up --------------------------------------
             andpush     1.000  i/100ms
                 fcm     1.000  i/100ms
             fcmpush     1.000  i/100ms
firebase_cloud_messenger
                         1.000  i/100ms
Calculating -------------------------------------
             andpush     19.236  (±10.4%) i/s -     95.000  in   5.048723s
                 fcm      6.536  (±15.3%) i/s -     33.000  in   5.083179s
             fcmpush     18.871  (±10.6%) i/s -     93.000  in   5.031072s
firebase_cloud_messenger
                          3.238  (± 0.0%) i/s -     17.000  in   5.265755s

Comparison:
             andpush:       19.2 i/s
             fcmpush:       18.9 i/s - same-ish: difference falls within error
                 fcm:        6.5 i/s - 2.94x  (± 0.00) slower
firebase_cloud_messenger:        3.2 i/s - 5.94x  (± 0.00) slower

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/miyataka/fcmpush.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].