apn_on_rails 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.specification +80 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +45 -0
- data/README +51 -9
- data/README.textile +198 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/apn_on_rails.gemspec +110 -0
- data/generators/templates/apn_migrations/004_create_apn_apps.rb +18 -0
- data/generators/templates/apn_migrations/005_create_groups.rb +23 -0
- data/generators/templates/apn_migrations/006_alter_apn_groups.rb +11 -0
- data/generators/templates/apn_migrations/007_create_device_groups.rb +27 -0
- data/generators/templates/apn_migrations/008_create_apn_group_notifications.rb +23 -0
- data/generators/templates/apn_migrations/009_create_pull_notifications.rb +16 -0
- data/lib/apn_on_rails/apn_on_rails.rb +22 -3
- data/lib/apn_on_rails/app/models/apn/app.rb +115 -0
- data/lib/apn_on_rails/app/models/apn/device.rb +3 -1
- data/lib/apn_on_rails/app/models/apn/device_grouping.rb +16 -0
- data/lib/apn_on_rails/app/models/apn/group.rb +12 -0
- data/lib/apn_on_rails/app/models/apn/group_notification.rb +79 -0
- data/lib/apn_on_rails/app/models/apn/notification.rb +6 -30
- data/lib/apn_on_rails/app/models/apn/pull_notification.rb +15 -0
- data/lib/apn_on_rails/libs/connection.rb +2 -1
- data/lib/apn_on_rails/libs/feedback.rb +6 -18
- data/lib/apn_on_rails/tasks/apn.rake +13 -4
- data/spec/active_record/setup_ar.rb +19 -0
- data/spec/apn_on_rails/app/models/apn/app_spec.rb +178 -0
- data/spec/apn_on_rails/app/models/apn/device_spec.rb +60 -0
- data/spec/apn_on_rails/app/models/apn/group_notification_spec.rb +66 -0
- data/spec/apn_on_rails/app/models/apn/notification_spec.rb +71 -0
- data/spec/apn_on_rails/app/models/apn/pull_notification_spec.rb +37 -0
- data/spec/apn_on_rails/libs/connection_spec.rb +40 -0
- data/spec/apn_on_rails/libs/feedback_spec.rb +45 -0
- data/spec/extensions/string.rb +10 -0
- data/spec/factories/app_factory.rb +27 -0
- data/spec/factories/device_factory.rb +29 -0
- data/spec/factories/device_grouping_factory.rb +22 -0
- data/spec/factories/group_factory.rb +27 -0
- data/spec/factories/group_notification_factory.rb +22 -0
- data/spec/factories/notification_factory.rb +22 -0
- data/spec/factories/pull_notification_factory.rb +22 -0
- data/spec/fixtures/hexa.bin +1 -0
- data/spec/fixtures/message_for_sending.bin +0 -0
- data/spec/rails_root/config/apple_push_notification_development.pem +19 -0
- data/spec/spec_helper.rb +55 -0
- metadata +214 -24
data/.gitignore
ADDED
data/.rspec
ADDED
data/.specification
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apn_on_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- markbates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-26 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: configatron
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: "apn_on_rails was developed by: markbates"
|
26
|
+
email: mark@markbates.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- lib/apn_on_rails/apn_on_rails.rb
|
36
|
+
- lib/apn_on_rails/app/models/apn/base.rb
|
37
|
+
- lib/apn_on_rails/app/models/apn/device.rb
|
38
|
+
- lib/apn_on_rails/app/models/apn/notification.rb
|
39
|
+
- lib/apn_on_rails/libs/connection.rb
|
40
|
+
- lib/apn_on_rails/libs/feedback.rb
|
41
|
+
- lib/apn_on_rails/tasks/apn.rake
|
42
|
+
- lib/apn_on_rails/tasks/db.rake
|
43
|
+
- lib/apn_on_rails.rb
|
44
|
+
- lib/apn_on_rails_tasks.rb
|
45
|
+
- README
|
46
|
+
- LICENSE
|
47
|
+
- generators/apn_migrations_generator.rb
|
48
|
+
- generators/templates/apn_migrations/001_create_apn_devices.rb
|
49
|
+
- generators/templates/apn_migrations/002_create_apn_notifications.rb
|
50
|
+
- generators/templates/apn_migrations/003_alter_apn_devices.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://www.metabates.com
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: magrathea
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: apn_on_rails
|
79
|
+
test_files: []
|
80
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source :gemcutter
|
2
|
+
gem 'configatron'
|
3
|
+
|
4
|
+
# Add dependencies required to use your gem here.
|
5
|
+
# Example:
|
6
|
+
# gem "activesupport", ">= 2.3.5"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem 'sqlite3-ruby'
|
12
|
+
gem "rspec", ">= 2.0.0.beta.19"
|
13
|
+
gem "bundler", ">= 1.0.0.rc.5"
|
14
|
+
gem "jeweler", "~> 1.5.0.pre2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
gem "actionpack", '~> 2.3.8'
|
17
|
+
gem 'activerecord', "~> 2.3.8", :require => 'active_record'
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionpack (2.3.9)
|
5
|
+
activesupport (= 2.3.9)
|
6
|
+
rack (~> 1.1.0)
|
7
|
+
activerecord (2.3.9)
|
8
|
+
activesupport (= 2.3.9)
|
9
|
+
activesupport (2.3.9)
|
10
|
+
configatron (2.6.4)
|
11
|
+
yamler (>= 0.1.0)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
git (1.2.5)
|
14
|
+
jeweler (1.5.0.pre3)
|
15
|
+
bundler (~> 1.0.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
rack (1.1.0)
|
19
|
+
rake (0.8.7)
|
20
|
+
rcov (0.9.9)
|
21
|
+
rspec (2.0.0.rc)
|
22
|
+
rspec-core (= 2.0.0.rc)
|
23
|
+
rspec-expectations (= 2.0.0.rc)
|
24
|
+
rspec-mocks (= 2.0.0.rc)
|
25
|
+
rspec-core (2.0.0.rc)
|
26
|
+
rspec-expectations (2.0.0.rc)
|
27
|
+
diff-lcs (>= 1.1.2)
|
28
|
+
rspec-mocks (2.0.0.rc)
|
29
|
+
rspec-core (= 2.0.0.rc)
|
30
|
+
rspec-expectations (= 2.0.0.rc)
|
31
|
+
sqlite3-ruby (1.3.1)
|
32
|
+
yamler (0.1.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
actionpack (~> 2.3.8)
|
39
|
+
activerecord (~> 2.3.8)
|
40
|
+
bundler (>= 1.0.0.rc.5)
|
41
|
+
configatron
|
42
|
+
jeweler (~> 1.5.0.pre2)
|
43
|
+
rcov
|
44
|
+
rspec (>= 2.0.0.beta.19)
|
45
|
+
sqlite3-ruby
|
data/README
CHANGED
@@ -1,15 +1,49 @@
|
|
1
1
|
=APN on Rails (Apple Push Notifications on Rails)
|
2
2
|
|
3
3
|
APN on Rails is a Ruby on Rails gem that allows you to easily add Apple Push Notification (iPhone)
|
4
|
-
support to your Rails application.
|
4
|
+
support to your Rails application.
|
5
|
+
|
6
|
+
It supports:
|
7
|
+
* Multiple iPhone apps managed from the same Rails application
|
8
|
+
* Individual notifications and group notifications
|
9
|
+
* Alerts, badges, sounds, and custom properties in notifications
|
10
|
+
* Pull notifications
|
11
|
+
|
12
|
+
== Feature Descriptions
|
13
|
+
|
14
|
+
Multiple iPhone Apps: In previous versions of this gem a single Rails application was set up to
|
15
|
+
manage push notifications for a single iPhone app. In many cases it is useful to have a single Rails
|
16
|
+
app manage push notifications for multiple iPhone apps. With the addition of an APN::App model, this
|
17
|
+
is now possible. The certificates are now stored on instances of APN::APP and all devices are associated
|
18
|
+
with a particular app.
|
19
|
+
|
20
|
+
Individual and Group Notifications: Previous versions of this gem treated each notification individually
|
21
|
+
and did not provide a built-in way to send a broadcast notification to a group of devices. Group notifications
|
22
|
+
are now built into the gem. A group notification is associated with a group of devices and shares its
|
23
|
+
contents across the entire group of devices.
|
24
|
+
|
25
|
+
Notification Content Areas: Notifications may contain alerts, badges, sounds, and custom properties.
|
26
|
+
|
27
|
+
Pull Notifications: This version of the gem supports an alternative notification method that relies
|
28
|
+
on pulls from client devices and does not interact with the Apple Push Notification servers. This feature
|
29
|
+
may be used entirely independently of the push notification features. Pull notifications may be
|
30
|
+
created for an app. A client app can query for the most recent pull notification available since a
|
31
|
+
given date to retrieve any notifications waiting for it.
|
5
32
|
|
6
33
|
==Acknowledgements:
|
7
34
|
|
35
|
+
From Mark Bates:
|
36
|
+
|
8
37
|
This gem is a re-write of a plugin that was written by Fabien Penso and Sam Soffes.
|
9
38
|
Their plugin was a great start, but it just didn't quite reach the level I hoped it would.
|
10
39
|
I've re-written, as a gem, added a ton of tests, and I would like to think that I made it
|
11
40
|
a little nicer and easier to use.
|
12
41
|
|
42
|
+
From Rebecca Nesson (PRX.org):
|
43
|
+
|
44
|
+
This gem extends the original version that Mark Bates adapted. His gem did the hard
|
45
|
+
work of setting up and handling all communication with the Apple push notification servers.
|
46
|
+
|
13
47
|
==Converting Your Certificate:
|
14
48
|
|
15
49
|
Once you have the certificate from Apple for your application, export your key
|
@@ -23,10 +57,10 @@ Now covert the p12 file to a pem file:
|
|
23
57
|
|
24
58
|
$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
|
25
59
|
|
26
|
-
Put 'apple_push_notification_production.pem' in config/
|
27
|
-
|
28
60
|
If you are using a development certificate, then change the name to apple_push_notification_development.pem instead.
|
29
61
|
|
62
|
+
Store the contents of the certificate files on the app model for the app you want to send notifications to.
|
63
|
+
|
30
64
|
==Installing:
|
31
65
|
|
32
66
|
===Stable (RubyForge):
|
@@ -35,7 +69,7 @@ If you are using a development certificate, then change the name to apple_push_n
|
|
35
69
|
|
36
70
|
===Edge (GitHub):
|
37
71
|
|
38
|
-
$ sudo gem install
|
72
|
+
$ sudo gem install PRX-apn_on_rails.git --source=http://gems.github.com
|
39
73
|
|
40
74
|
===Rails Gem Management:
|
41
75
|
|
@@ -45,7 +79,7 @@ If you like to use the built in Rails gem management:
|
|
45
79
|
|
46
80
|
Or, if you like to live on the edge:
|
47
81
|
|
48
|
-
config.gem '
|
82
|
+
config.gem 'PRX-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'
|
49
83
|
|
50
84
|
==Setup and Configuration:
|
51
85
|
|
@@ -70,7 +104,9 @@ Now, to create the tables you need for APN on Rails, run the following task:
|
|
70
104
|
$ ruby script/generate apn_migrations
|
71
105
|
|
72
106
|
APN on Rails uses the Configatron gem, http://github.com/markbates/configatron/tree/master,
|
73
|
-
to configure itself.
|
107
|
+
to configure itself. (With the change to multi-app support, the certifications are stored in the
|
108
|
+
database rather than in the config directory. These configurations remain for now.)
|
109
|
+
APN on Rails has the following default configurations that you change as you
|
74
110
|
see fit:
|
75
111
|
|
76
112
|
# development (delivery):
|
@@ -103,21 +139,27 @@ If you are upgrading to a new version of APN on Rails you should always run:
|
|
103
139
|
|
104
140
|
That way you ensure you have the latest version of the database tables needed.
|
105
141
|
|
106
|
-
==Example:
|
142
|
+
==Example (assuming you have created an app and stored your keys on it):
|
107
143
|
|
108
144
|
$ ./script/console
|
109
|
-
>>
|
145
|
+
>> app = APN::App.find(:first)
|
146
|
+
>> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX",:app_id => app.id)
|
110
147
|
>> notification = APN::Notification.new
|
111
148
|
>> notification.device = device
|
112
149
|
>> notification.badge = 5
|
113
150
|
>> notification.sound = true
|
114
151
|
>> notification.alert = "foobar"
|
152
|
+
>> notification.custom_properties = {:link => "http://www.prx.org"}
|
115
153
|
>> notification.save
|
116
154
|
|
117
|
-
You can use the following Rake task to deliver your notifications:
|
155
|
+
You can use the following Rake task to deliver your individual notifications:
|
118
156
|
|
119
157
|
$ rake apn:notifications:deliver
|
120
158
|
|
159
|
+
And the following task to deliver your group notifications:
|
160
|
+
|
161
|
+
$ rake apn:group_notifications:deliver
|
162
|
+
|
121
163
|
The Rake task will find any unsent notifications in the database. If there aren't any notifications
|
122
164
|
it will simply do nothing. If there are notifications waiting to be delivered it will open a single connection
|
123
165
|
to Apple and push all the notifications through that one connection. Apple does not like people opening/closing
|
data/README.textile
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
h1. APN on Rails (Apple Push Notifications on Rails)
|
2
|
+
|
3
|
+
APN on Rails is a Ruby on Rails gem that allows you to easily add Apple Push Notification (iPhone)
|
4
|
+
support to your Rails application.
|
5
|
+
|
6
|
+
It supports:
|
7
|
+
* Multiple iPhone apps managed from the same Rails application
|
8
|
+
* Individual notifications and group notifications
|
9
|
+
* Alerts, badges, sounds, and custom properties in notifications
|
10
|
+
* Pull notifications
|
11
|
+
|
12
|
+
h2. Feature Descriptions
|
13
|
+
|
14
|
+
Multiple iPhone Apps: In previous versions of this gem a single Rails application was set up to
|
15
|
+
manage push notifications for a single iPhone app. In many cases it is useful to have a single Rails
|
16
|
+
app manage push notifications for multiple iPhone apps. With the addition of an APN::App model, this
|
17
|
+
is now possible. The certificates are now stored on instances of APN::APP and all devices are associated
|
18
|
+
with a particular app.
|
19
|
+
|
20
|
+
Individual and Group Notifications: Previous versions of this gem treated each notification individually
|
21
|
+
and did not provide a built-in way to send a broadcast notification to a group of devices. Group notifications
|
22
|
+
are now built into the gem. A group notification is associated with a group of devices and shares its
|
23
|
+
contents across the entire group of devices.
|
24
|
+
|
25
|
+
Notification Content Areas: Notifications may contain alerts, badges, sounds, and custom properties.
|
26
|
+
|
27
|
+
Pull Notifications: This version of the gem supports an alternative notification method that relies
|
28
|
+
on pulls from client devices and does not interact with the Apple Push Notification servers. This feature
|
29
|
+
may be used entirely independently of the push notification features. Pull notifications may be
|
30
|
+
created for an app. A client app can query for the most recent pull notification available since a
|
31
|
+
given date to retrieve any notifications waiting for it.
|
32
|
+
|
33
|
+
h2. Acknowledgements:
|
34
|
+
|
35
|
+
From Mark Bates:
|
36
|
+
|
37
|
+
This gem is a re-write of a plugin that was written by Fabien Penso and Sam Soffes.
|
38
|
+
Their plugin was a great start, but it just didn't quite reach the level I hoped it would.
|
39
|
+
I've re-written, as a gem, added a ton of tests, and I would like to think that I made it
|
40
|
+
a little nicer and easier to use.
|
41
|
+
|
42
|
+
From Rebecca Nesson (PRX.org):
|
43
|
+
|
44
|
+
This gem extends the original version that Mark Bates adapted. His gem did the hard
|
45
|
+
work of setting up and handling all communication with the Apple push notification servers.
|
46
|
+
|
47
|
+
h2. Converting Your Certificate:
|
48
|
+
|
49
|
+
Once you have the certificate from Apple for your application, export your key
|
50
|
+
and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:
|
51
|
+
|
52
|
+
1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
|
53
|
+
2. Right click and choose `Export 2 items...`.
|
54
|
+
3. Choose the p12 format from the drop down and name it `cert.p12`.
|
55
|
+
|
56
|
+
Now covert the p12 file to a pem file:
|
57
|
+
|
58
|
+
<pre><code>
|
59
|
+
$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
|
60
|
+
</pre></code>
|
61
|
+
|
62
|
+
If you are using a development certificate, then change the name to apple_push_notification_development.pem instead.
|
63
|
+
|
64
|
+
Store the contents of the certificate files on the app model for the app you want to send notifications to.
|
65
|
+
|
66
|
+
h2. Installing:
|
67
|
+
|
68
|
+
h3. Stable (RubyForge):
|
69
|
+
|
70
|
+
<pre><code>
|
71
|
+
$ sudo gem install apn_on_rails
|
72
|
+
</pre></code>
|
73
|
+
|
74
|
+
h3. Edge (GitHub):
|
75
|
+
|
76
|
+
<pre><code>
|
77
|
+
$ sudo gem install PRX-apn_on_rails.git --source=http://gems.github.com
|
78
|
+
</pre></code>
|
79
|
+
|
80
|
+
h3. Rails Gem Management:
|
81
|
+
|
82
|
+
If you like to use the built in Rails gem management:
|
83
|
+
|
84
|
+
<pre><code>
|
85
|
+
config.gem 'apn_on_rails'
|
86
|
+
</pre></code>
|
87
|
+
|
88
|
+
Or, if you like to live on the edge:
|
89
|
+
|
90
|
+
<pre><code>
|
91
|
+
config.gem 'PRX-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'
|
92
|
+
</pre></code>
|
93
|
+
|
94
|
+
h2. Setup and Configuration:
|
95
|
+
|
96
|
+
Once you have the gem installed via your favorite gem installation, you need to require it so you can
|
97
|
+
start to use it:
|
98
|
+
|
99
|
+
Add the following require, wherever it makes sense to you:
|
100
|
+
|
101
|
+
<pre><code>
|
102
|
+
require 'apn_on_rails'
|
103
|
+
</pre></code>
|
104
|
+
|
105
|
+
You also need to add the following to your Rakefile so you can use the
|
106
|
+
Rake tasks that ship with APN on Rails:
|
107
|
+
|
108
|
+
<pre><code>
|
109
|
+
begin
|
110
|
+
require 'apn_on_rails_tasks'
|
111
|
+
rescue MissingSourceFile => e
|
112
|
+
puts e.message
|
113
|
+
end
|
114
|
+
</pre></code>
|
115
|
+
|
116
|
+
Now, to create the tables you need for APN on Rails, run the following task:
|
117
|
+
|
118
|
+
<pre><code>
|
119
|
+
$ ruby script/generate apn_migrations
|
120
|
+
</pre></code>
|
121
|
+
|
122
|
+
APN on Rails uses the Configatron gem, http://github.com/markbates/configatron/tree/master,
|
123
|
+
to configure itself. (With the change to multi-app support, the certifications are stored in the
|
124
|
+
database rather than in the config directory. These configurations remain for now.)
|
125
|
+
APN on Rails has the following default configurations that you change as you
|
126
|
+
see fit:
|
127
|
+
|
128
|
+
<pre><code>
|
129
|
+
# development (delivery):
|
130
|
+
configatron.apn.passphrase # => ''
|
131
|
+
configatron.apn.port # => 2195
|
132
|
+
configatron.apn.host # => 'gateway.sandbox.push.apple.com'
|
133
|
+
configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')
|
134
|
+
|
135
|
+
# production (delivery):
|
136
|
+
configatron.apn.host # => 'gateway.push.apple.com'
|
137
|
+
configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_production.pem')
|
138
|
+
|
139
|
+
# development (feedback):
|
140
|
+
configatron.apn.feedback.passphrase # => ''
|
141
|
+
configatron.apn.feedback.port # => 2196
|
142
|
+
configatron.apn.feedback.host # => 'feedback.sandbox.push.apple.com'
|
143
|
+
configatron.apn.feedback.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')
|
144
|
+
|
145
|
+
# production (feedback):
|
146
|
+
configatron.apn.feedback.host # => 'feedback.push.apple.com'
|
147
|
+
configatron.apn.feedback.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_production.pem')
|
148
|
+
</pre></code>
|
149
|
+
|
150
|
+
That's it, now you're ready to start creating notifications.
|
151
|
+
|
152
|
+
h3. Upgrade Notes:
|
153
|
+
|
154
|
+
If you are upgrading to a new version of APN on Rails you should always run:
|
155
|
+
|
156
|
+
<pre><code>
|
157
|
+
$ ruby script/generate apn_migrations
|
158
|
+
</pre></code>
|
159
|
+
|
160
|
+
That way you ensure you have the latest version of the database tables needed.
|
161
|
+
(There is an unaddressed problem in which migration 002 was modified in the repo to add the column custom_properties.
|
162
|
+
If you installed the gem prior to that change and try to upgrade following this path you will have to add the
|
163
|
+
custom_properties column to the apn_notifications table by hand.)
|
164
|
+
|
165
|
+
h2. Example (assuming you have created an app and stored your keys on it):
|
166
|
+
|
167
|
+
<pre><code>
|
168
|
+
$ ./script/console
|
169
|
+
>> app = APN::App.find(:first)
|
170
|
+
>> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX",:app_id => app.id)
|
171
|
+
>> notification = APN::Notification.new
|
172
|
+
>> notification.device = device
|
173
|
+
>> notification.badge = 5
|
174
|
+
>> notification.sound = true
|
175
|
+
>> notification.alert = "foobar"
|
176
|
+
>> notification.custom_properties = {:link => "http://www.prx.org"}
|
177
|
+
>> notification.save
|
178
|
+
</pre></code>
|
179
|
+
|
180
|
+
You can use the following Rake task to deliver your individual notifications:
|
181
|
+
|
182
|
+
<pre><code>
|
183
|
+
$ rake apn:notifications:deliver
|
184
|
+
</pre></code>
|
185
|
+
|
186
|
+
And the following task to deliver your group notifications:
|
187
|
+
|
188
|
+
<pre><code>
|
189
|
+
$ rake apn:group_notifications:deliver
|
190
|
+
</pre></code>
|
191
|
+
|
192
|
+
The Rake task will find any unsent notifications in the database. If there aren't any notifications
|
193
|
+
it will simply do nothing. If there are notifications waiting to be delivered it will open a single connection
|
194
|
+
to Apple and push all the notifications through that one connection. Apple does not like people opening/closing
|
195
|
+
connections constantly, so it's pretty important that you are careful about batching up your notifications so
|
196
|
+
Apple doesn't shut you down.
|
197
|
+
|
198
|
+
Released under the MIT license.
|