Giter Club home page Giter Club logo

rpush's Introduction

Build Status Code Climate Coverage Status Gem Version

Rpush. The push notification service for Ruby.

  • Supports:
    • Apple Push Notification Service
    • Google Cloud Messaging
    • Amazon Device Messaging
    • Windows Phone Push Notification Service.
  • Seamless Rails (3, 4) integration.
  • Scalable - choose the number of persistent connections for each app.
  • Designed for uptime - signal -HUP to add, update apps.
  • Run as a daemon or inside an existing processs.
  • Use in a scheduler for low-workload deployments (Push API).
  • Hooks for fine-grained instrumentation and error handling (Reflection API).
  • Works with MRI, JRuby, Rubinius 1.9, 2.0, 2.1.

Getting Started

Add it to your Gemfile:

gem 'rpush'

Generate the migrations, rpush.yml and migrate:

rails g rpush
rake db:migrate

Create an App & Notification

Apple Push Notification Service

If this is your first time using the APNs, you will need to generate SSL certificates. See Generating Certificates for instructions.

app = Rpush::Apns::App.new
app.name = "ios_app"
app.certificate = File.read("/path/to/sandbox.pem")
app.environment = "sandbox" # APNs environment.
app.password = "certificate password"
app.connections = 1
app.save!
n = Rpush::Apns::Notification.new
n.app = Rpush::Apns::App.find_by_name("ios_app")
n.device_token = "..."
n.alert = "hi mom!"
n.attributes_for_device = {:foo => :bar}
n.save!

You should also implement the ssl_certificate_will_expire reflection to monitor when your certificate is due to expire.

Google Cloud Messaging

app = Rpush::Gcm::App.new
app.name = "android_app"
app.auth_key = "..."
app.connections = 1
app.save!
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["..."]
n.data = {:message => "hi mom!"}
n.save!

GCM also requires you to respond to Canonical IDs.

Amazon Device Messaging

app = Rpush::Adm::App.new
app.name = "kindle_app"
app.client_id = "..."
app.client_secret = "..."
app.connections = 1
app.save!
n = Rpush::Adm::Notification.new
n.app = Rpush::Adm::App.find_by_name("kindle_app")
n.registration_ids = ["..."]
n.data = {:message => "hi mom!"}
n.collapse_key = "Optional consolidationKey"
n.save!

For more documentation on ADM.

Windows Phone Notification Service

app = Rpush::Wpns::App.new
app.name = "windows_phone_app"
app.connections = 1
app.save!
n = Rpush::Wpns::Notification.new
n.app = Rpush::Wpns::App.find_by_name("windows_phone_app")
n.uri = "http://..."
n.alert = "..."
n.save!

Starting Rpush

As a daemon:

cd /path/to/rails/app
rpush <Rails environment> [options]

Inside an existing process (see Embedding API):

Rpush.embed

Please note that only ever a single instance of Rpush should be running.

In a scheduler (see Push API):

Rpush.push
Rpush.apns_feedback

See Configuration for a list of options, or run rpush --help.

Updating Rpush

After updating you should run rails g rpush to check for any new migrations.

Wiki

General

Apple Push Notification Service

Google Cloud Messaging

Contributing

Fork as usual and go crazy!

When running specs, please note that the ActiveRecord adapter can be changed by setting the ADAPTER environment variable. For example: ADAPTER=postgresql rake.

Available adapters for testing are mysql, mysql2 and postgresql.

Note that the database username is changed at runtime to be the currently logged in user's name. So if you're testing with mysql and you're using a user named 'bob', you will need to grant a mysql user 'bob' access to the 'rpush_test' mysql database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.