Skip to content

Commit

Permalink
working on tests, adding in all my changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PRXci committed Oct 6, 2010
1 parent f94d0b3 commit 43c8492
Show file tree
Hide file tree
Showing 29 changed files with 833 additions and 128 deletions.
80 changes: 80 additions & 0 deletions .specification
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- !ruby/object:Gem::Specification
name: apn_on_rails
version: !ruby/object:Gem::Version
version: 0.3.1
platform: ruby
authors:
- markbates
autorequire:
bindir: bin
cert_chain: []

date: 2010-01-26 00:00:00 -05:00
default_executable:
dependencies:
- !ruby/object:Gem::Dependency
name: configatron
type: :runtime
version_requirement:
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
description: "apn_on_rails was developed by: markbates"
email: mark@markbates.com
executables: []

extensions: []

extra_rdoc_files:
- README
- LICENSE
files:
- lib/apn_on_rails/apn_on_rails.rb
- lib/apn_on_rails/app/models/apn/base.rb
- lib/apn_on_rails/app/models/apn/device.rb
- lib/apn_on_rails/app/models/apn/notification.rb
- lib/apn_on_rails/libs/connection.rb
- lib/apn_on_rails/libs/feedback.rb
- lib/apn_on_rails/tasks/apn.rake
- lib/apn_on_rails/tasks/db.rake
- lib/apn_on_rails.rb
- lib/apn_on_rails_tasks.rb
- README
- LICENSE
- generators/apn_migrations_generator.rb
- generators/templates/apn_migrations/001_create_apn_devices.rb
- generators/templates/apn_migrations/002_create_apn_notifications.rb
- generators/templates/apn_migrations/003_alter_apn_devices.rb
has_rdoc: true
homepage: http://www.metabates.com
licenses: []

post_install_message:
rdoc_options: []

require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
requirements: []

rubyforge_project: magrathea
rubygems_version: 1.3.5
signing_key:
specification_version: 3
summary: apn_on_rails
test_files: []

60 changes: 51 additions & 9 deletions README
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
=APN on Rails (Apple Push Notifications on Rails)

APN on Rails is a Ruby on Rails gem that allows you to easily add Apple Push Notification (iPhone)
support to your Rails application.
support to your Rails application.

It supports:
* Multiple iPhone apps managed from the same Rails application
* Individual notifications and group notifications
* Alerts, badges, sounds, and custom properties in notifications
* In-App (or pull) notifications

== Feature Descriptions

Multiple iPhone Apps: In previous versions of this gem a single Rails application was set up to
manage push notifications for a single iPhone app. In many cases it is useful to have a single Rails
app manage push notifications for multiple iPhone apps. With the addition of an APN::App model, this
is now possible. The certificates are now stored on instances of APN::APP and all devices are associated
with a particular app.

Individual and Group Notifications: Previous versions of this gem treated each notification individually
and did not provide a built-in way to send a broadcast notification to a group of devices. Group notifications
are now built into the gem. A group notification is associated with a group of devices and shares its
contents across the entire group of devices.

Notification Content Areas: Notifications may contain alerts, badges, sounds, and custom properties.

In-App or Pull Notifications: This version of the gem supports an alternative notification method that relies
on pulls from client devices and does not interact with the Apple Push Notification servers. This feature
may be used entirely independently of the push notification features. In-App or Pull notifications may be
created for an app. A client app can query for the most recent in-app notification available since a
given date to retrieve any notifications waiting for it.

==Acknowledgements:

From Mark Bates:

This gem is a re-write of a plugin that was written by Fabien Penso and Sam Soffes.
Their plugin was a great start, but it just didn't quite reach the level I hoped it would.
I've re-written, as a gem, added a ton of tests, and I would like to think that I made it
a little nicer and easier to use.

From Rebecca Nesson (PRX.org):

This gem extends the original version that Mark Bates adapted. His gem did the hard
work of setting up and handling all communication with the Apple push notification servers.

==Converting Your Certificate:

Once you have the certificate from Apple for your application, export your key
Expand All @@ -23,10 +57,10 @@ Now covert the p12 file to a pem file:

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

Put 'apple_push_notification_production.pem' in config/

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

Store the contents of the certificate files on the app model for the app you want to send notifications to.

==Installing:

===Stable (RubyForge):
Expand All @@ -35,7 +69,7 @@ If you are using a development certificate, then change the name to apple_push_n

===Edge (GitHub):

$ sudo gem install markbates-apn_on_rails --source=http://gems.github.com
$ sudo gem install PRX-apn_on_rails.git --source=http://gems.github.com

===Rails Gem Management:

Expand All @@ -45,7 +79,7 @@ If you like to use the built in Rails gem management:

Or, if you like to live on the edge:

config.gem 'markbates-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'
config.gem 'PRX-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'

==Setup and Configuration:

Expand All @@ -70,7 +104,9 @@ Now, to create the tables you need for APN on Rails, run the following task:
$ ruby script/generate apn_migrations

APN on Rails uses the Configatron gem, http://github.com/markbates/configatron/tree/master,
to configure itself. APN on Rails has the following default configurations that you change as you
to configure itself. (With the change to multi-app support, the certifications are stored in the
database rather than in the config directory. These configurations remain for now.)
APN on Rails has the following default configurations that you change as you
see fit:

# development (delivery):
Expand Down Expand Up @@ -103,21 +139,27 @@ If you are upgrading to a new version of APN on Rails you should always run:

That way you ensure you have the latest version of the database tables needed.

==Example:
==Example (assuming you have created an app and stored your keys on it):

$ ./script/console
>> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX")
>> app = APN::App.find(:first)
>> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX",:app_id => app.id)
>> notification = APN::Notification.new
>> notification.device = device
>> notification.badge = 5
>> notification.sound = true
>> notification.alert = "foobar"
>> notification.custom_properties = {:link => "http://www.prx.org"}
>> notification.save

You can use the following Rake task to deliver your notifications:
You can use the following Rake task to deliver your individual notifications:

$ rake apn:notifications:deliver

And the following task to deliver your group notifications:

$ rake apn:group_notifications:deliver

The Rake task will find any unsent notifications in the database. If there aren't any notifications
it will simply do nothing. If there are notifications waiting to be delivered it will open a single connection
to Apple and push all the notifications through that one connection. Apple does not like people opening/closing
Expand Down
Loading

0 comments on commit 43c8492

Please sign in to comment.