### FCMPush Performance Benchmark Results Source: https://github.com/miyataka/fcmpush/blob/main/README.md Benchmark results comparing FCMPush with other Ruby FCM gems. Shows requests per second and performance differences. ```text 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 ``` -------------------------------- ### Configure Fcmpush in Rails Source: https://github.com/miyataka/fcmpush/blob/main/README.md Configure the Fcmpush client in a Rails application by providing the path to your service account credentials JSON file or its content. Alternatively, set environment variables for authentication. Legacy server key configuration is also shown but deprecated. ```ruby 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'] = 'xxxx@xxxx.iam.gserviceaccount.com' # 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 # @deprecated: This attribute will be removed next version. config.server_key = 'your firebase server key' # Or set environment variables # @deprecated: This attribute will be removed next version. # ENV['FCM_SERVER_KEY'] = 'your firebase server key' # Proxy ENV variables are considered by default if set by net/http, but you can explicitly define your proxy host here # user and password are optional # config.proxy = { uri: "http://proxy.host:3128", user: nil, password: nil } # explicitly disable using proxy, even ignore environment variables if set # config.proxy = false # HTTP connection open and read timeouts (in seconds) are set for all client requests. # If unset, the default values for Net::HTTP::Persistent are used (currently 60 seconds). # config.open_timeout = 30 # config.read_timeout = 15 end ``` -------------------------------- ### Subscribe/Unsubscribe Devices to FCM Topic Source: https://github.com/miyataka/fcmpush/blob/main/README.md Manage device subscriptions to FCM topics. This uses the legacy authentication method requiring a server key. The response indicates success or failure for each device token provided. ```ruby 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 ``` -------------------------------- ### Push FCM Messages in Batch (Deprecated) Source: https://github.com/miyataka/fcmpush/blob/main/README.md Send multiple push notifications in a single batch request. This method is deprecated and will be removed in a future version. The response is an array of results, one for each message. ```ruby 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" ``` -------------------------------- ### Push a Single FCM Message Source: https://github.com/miyataka/fcmpush/blob/main/README.md Send a single push notification to a device using its token. The payload structure follows the FCM HTTP v1 API specification. The response contains a 'name' field identifying the sent message. ```ruby 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" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.