Giter Site home page Giter Site logo

apn_on_mongoid's Introduction

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

apn_on_mongoid's People

Contributors

feklistov avatar gvalmon avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.