Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Apple Push Notification delivery powered by Mongoid.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
LICENSE
README.textile
Rakefile
apn_on_mongoid.gemspec

README.textile

WARNING VERY ALPHA

This is the first build of the gem. Use in production at your own imminent devise demise. The gem will successfully send a notification to a device with no worries. However this is only with basic testing and no real production use tests.

APN on Mongoid (Apple Push Notifications on Mongoid)

APN on Mongoid is a rewritten fork of the APN on Rails gem. APN stands for Apple Push Notification [Service].
Its purpose is to allow the use of Mongoid and in turn a MongoDB for sending Push Notifications. Built for Rails 3 and Mongoid 2.X.

Acknowledgements:

This gem is a re-write of the APN for Rails gem written by PRX and Mark Bates which is also a re-write from a plugin that was written by Fabien Penso and Sam Soffes. APN on Rails is a good gem but it has its limitations and restrictions which doesn’t allow Mongoid love.

Some of the documentation listed below is a duplication of the documentation by APN on Rails.

Converting Your Certificate:

Once you have the certificate from Apple for your application, export your key
and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:

1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
2. Right click and choose `Export 2 items…`.
3. Choose the p12 format from the drop down and name it `cert.p12`.

Now covert the p12 file to a pem file:


  $ openssl pkcs12 -in cert.p12 -out apns_certificate_production.pem -nodes -clcerts

Put ‘apns_certificate_production.pem’ in config/

If you are using a development certificate, then change the name to apns_certificate_development.pem instead.

Installing:

Bundler:

Dead simple. Just use Bundler :)


  gem "apn_on_mongoid", :git => "git://github.com/alexeckermann/apn_on_mongoid.git"

Setup and Configuration:

Unlike APN on Rails this gem does not require any additional configuration or changes. The APN configuration items are available in the APN class.

If you do wish to make changes simply create a apn_on_mongoid.rb file in your config folder. The file can be used like this:


  APN.setup do |config|
    
    config.host = 'gateway.push.apple.com'
    config.port = 2195
    
    config.feedback_host = 'feedback.push.apple.com'
    config.feedback_port = 2196
    
    config.cert = "#{::Rails.root.to_s}/config/my_custom_cert.pem"
    
    config.passphrase = 'ilikemangos'
    
  end

This configuration style is the same used in Devise.

Example


  $ rails console
  >> d = APN::Device.create(:udid => "1a2b3c4d")
  >> a = APN::Application.create(:name => "MyApp", :identififer => "com.acmeinc.myapp")
  >> s = d.subscriptions.create(:application => a, :token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX")
  >> n = APN::Notification.new
  >> n.device = d
  >> n.alert = "G'day from APN on Mongoid"
  >> n.sound = "default"
  >> n.badge = 1337
  >> n.save
  >> n.deliver
  ... or ...
  >> APN::Notifications.deliver

The schema is created like so:

  • A device has many subscriptions
    • A subscription is embedded in a device
  • A subscription references an application
  • A notification references a subscription

It is done this way so you can have a registry of devices that can be assigned to multiple applications. This is handy for developers that do have more than one app that uses the APNS and want to use 1 Rails application to control notifications.

For doing once off notifications it is more work than APN on Rails but it is assumed that this gem will be used for services that require Push Notifications delivered regularly and to a large device base.

TODO

  • Making APN::Device’s and tokens separate allowing for APN::Application’s and multiple token registrations for a device for many applications
    • Handy for people with multiple apps under their belt
  • Investigate using delayed_job for notification delivery rather than rake
  • Examples for using whenever and delivering notifications via cron
Something went wrong with that request. Please try again.