<commit_before>h1. 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.

h1. 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.

h2. Acknowledgements:

This gem is a re-write of the APN for Rails gem written by PRX and <NAME> which is also a re-write from a plugin that was written by <NAME> and <NAME>.
APN on Rails is a good gem but it has its limitations and restrictions which doesn't allow Mongoid love.

Most of the documentation listed below is a duplication of the documentation by APN on Rails. I respect all the work that went into that gem.

h2. 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:
<pre><code>
  $ openssl pkcs12 -in cert.p12 -out apns_certificate_production.pem -nodes -clcerts
</code></pre>

Put 'apns_certificate_production.pem' in config/

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

h2. Installing:

h3. Bundler:

Dead simple. Just use Bundler :)

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

h2. 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:

<pre><code>
  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 = '<PASSWORD>'
    
  end
</code></pre>

h2. Example

<pre><code>
  $ rails console
  >> d = APN::Device.create(:udid => "123456abcdefg", :token => "<PASSWORD>XXXXX <PASSWORD>XXX <PASSWORD>XXX")
  >> n = APN::Notification.new
  >> n.device = d
  >> n.alert = "G'day from APN on Mongoid"
  >> n.sound = "default"
  >> n.badge = 1337
  >> n.save
  >> APN::Notification.deliver_notifications
</code></pre><commit_msg>Added TODO in README, roadmapping future changes.<commit_after>h1. 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.

h1. 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.

h2. Acknowledgements:

This gem is a re-write of the APN for Rails gem written by PRX and <NAME> which is also a re-write from a plugin that was written by <NAME> and <NAME>. 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.

h2. 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:
<pre><code>
  $ openssl pkcs12 -in cert.p12 -out apns_certificate_production.pem -nodes -clcerts
</code></pre>

Put 'apns_certificate_production.pem' in config/

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

h2. Installing:

h3. Bundler:

Dead simple. Just use Bundler :)

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

h2. 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:

<pre><code>
  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 = '<PASSWORD>'
    
  end
</code></pre>

This configuration style is the same used in Devise.

h2. Example

<pre><code>
  $ rails console
  >> d = APN::Device.create(:udid => "1a2b3c4d", :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
  >> APN::Notification.deliver_notifications
</code></pre>

h2. 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
{'fraction_non_alphanumeric': 0.07775309425579181, 'fraction_numerical': 0.013805141225007934, 'mean_word_length': 3.829885057471264, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3656322', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1876, 'n_words': 862}