Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of the Andpush gem and benchmark
require 'benchmark/ips'
require 'andpush'
require 'fcm'
server_key = ENV.fetch('FCM_TEST_SERVER_KEY')
DEVICE_TOKEN = ENV.fetch('FCM_TEST_REGISTRATION_TOKEN')
FCM_CLIENT = FCM.new(server_key)
PAYLOAD_FOR_FCM = { dry_run: true, notification: { title: "u", body: "y" } }
ANDPUSH_CLIENT = Andpush.build(server_key)
PAYLOAD_FOR_ANDPUSH = PAYLOAD_FOR_FCM.merge(to: DEVICE_TOKEN)
Benchmark.ips do |x|
x.report("andpush") { ANDPUSH_CLIENT.push(PAYLOAD_FOR_ANDPUSH) }
x.report("fcm") { FCM_CLIENT.send(DEVICE_TOKEN, PAYLOAD_FOR_FCM) }
x.compare!
end
require 'andpush'
server_key = "..." # Your server key
device_token = "..." # The device token of the device you'd like to push a message to
client = Andpush.new(server_key)
payload = {
to: device_token,
notification: {
title: "Update",
body: "Your weekly summary is ready"
},
data: {
extra: "data"
}
}
response = client.push(payload)
json = response.json
json[:canonical_ids] # => 0
json[:failure] # => 0
json[:multicast_id] # => 8478364278516813477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment