Skip to content

Instantly share code, notes, and snippets.

@gregblake
Created August 27, 2019 14:26
Show Gist options
  • Select an option

  • Save gregblake/e70ca19155953440e6b23f65b10eebeb to your computer and use it in GitHub Desktop.

Select an option

Save gregblake/e70ca19155953440e6b23f65b10eebeb to your computer and use it in GitHub Desktop.
Testing Rpush Certs
Rpush.embed # to deliver push notifications in the Rails console on notification save
# Selecting the mobile device that'll receive the notification:
greg = User.find_by(login: "greg.blake");
devices = greg.mobile_devices;
mobile_device = greg.mobile_devices.last;
# Sending a notification to the device
n = Rpush::Apns2::Notification.new;
n.app = mobile_device.app;
n.device_token = mobile_device.device_token;
n.alert = Faker::Matz.quote;
apns_topic = mobile_device.app&.name;
n.data = { 'headers' => { 'apns-topic' => apns_topic } };
n.save # This delivers the push notification
# ===============================
# Android:
Rpush.embed # to deliver push notifications in the Rails console on notification save
# Selecting the mobile device that'll receive the notification:
stefan = User.find_by(login: "stefan.schmidt");
stefan_android_devices = stefan.mobile_devices.where(platform: "android");
mobile_device = stefan_android_devices.last;
# Sending a notification to the device
n = Rpush::Gcm::Notification.new;
n.app = mobile_device.app;
n.registration_ids = [mobile_device.device_token];
n.data = {
room_id: 9513,
badge: 1,
category: "connect-no-reply",
custom_notification: {
room_id: 1976
}
}
n.priority = 'high';
n.content_available = true
n.notification = {
body: "Hey it's me, #{Faker::TheFreshPrinceOfBelAir.character} from Fresh Prince",
title: Faker::TheFreshPrinceOfBelAir.quote
}
n.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment