rapns 2.0.0rc1 → 2.0.0rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/generators/templates/create_rapns_apps.rb +1 -0
- data/lib/rapns/app.rb +1 -0
- data/lib/rapns/daemon/app_runner.rb +2 -15
- data/lib/rapns/version.rb +1 -1
- data/spec/rapns/daemon/app_runner_spec.rb +4 -18
- metadata +2 -2
data/README.md
CHANGED
@@ -47,17 +47,17 @@ Generate the migration, rapns.yml and migrate:
|
|
47
47
|
app = Rapns::App.new
|
48
48
|
app.key = "my_app"
|
49
49
|
app.certificate = File.read("/path/to/development.pem")
|
50
|
+
app.environment = "development"
|
50
51
|
app.password = "certificate password"
|
51
52
|
app.connections = 1
|
52
53
|
app.save!
|
53
54
|
|
54
55
|
* `key` is a symbolic name to tie this app to notifications.
|
55
56
|
* `certificate` is the contents of your PEM certificate, NOT its path on disk.
|
57
|
+
* `environment` the certificate type, either `development` or `production`.
|
56
58
|
* `password` should be left blank if you did not password protect your certificate.
|
57
59
|
* `connections` (default: 1) the number of connections to keep open to the APNs. Consider increasing this if you are sending a large number of notifications to this app.
|
58
60
|
|
59
|
-
The APNs environment is automatically detected from the app certificate, you do not need to configure push and feedback hosts.
|
60
|
-
|
61
61
|
## Starting the rapns Daemon
|
62
62
|
|
63
63
|
cd /path/to/rails/app
|
@@ -2,6 +2,7 @@ class CreateRapnsApps < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :rapns_apps do |t|
|
4
4
|
t.string :key, :null => false
|
5
|
+
t.string :environment, :null => false
|
5
6
|
t.text :certificate, :null => false
|
6
7
|
t.string :password, :null => true
|
7
8
|
t.integer :connections, :null => false, :default => 1
|
data/lib/rapns/app.rb
CHANGED
@@ -3,6 +3,7 @@ module Rapns
|
|
3
3
|
self.table_name = 'rapns_apps'
|
4
4
|
|
5
5
|
validates :key, :presence => true, :uniqueness => true
|
6
|
+
validates :environment, :presence => true, :inclusion => { :in => %w(development production) }
|
6
7
|
validates :certificate, :presence => true
|
7
8
|
validates_numericality_of :connections, :greater_than => 0, :only_integer => true
|
8
9
|
end
|
@@ -38,10 +38,8 @@ module Rapns
|
|
38
38
|
if @all[app.key]
|
39
39
|
@all[app.key].sync(app)
|
40
40
|
else
|
41
|
-
|
42
|
-
|
43
|
-
push_host, push_port = HOSTS[environment][:push]
|
44
|
-
feedback_host, feedback_port = HOSTS[environment][:feedback]
|
41
|
+
push_host, push_port = HOSTS[app.environment.to_sym][:push]
|
42
|
+
feedback_host, feedback_port = HOSTS[app.environment.to_sym][:feedback]
|
45
43
|
feedback_poll = Rapns::Daemon.config.feedback_poll
|
46
44
|
runner = AppRunner.new(app, push_host, push_port, feedback_host, feedback_port, feedback_poll)
|
47
45
|
runner.start
|
@@ -61,17 +59,6 @@ module Rapns
|
|
61
59
|
@all.values.map(&:debug)
|
62
60
|
end
|
63
61
|
|
64
|
-
def self.detect_environment(app)
|
65
|
-
if app.certificate =~ /Apple Development IOS Push Services/i
|
66
|
-
:development
|
67
|
-
elsif app.certificate =~ /Apple Production IOS Push Services/i
|
68
|
-
:production
|
69
|
-
else
|
70
|
-
Rapns::Daemon.logger.error("Could not detect environment for app '#{app.key}'.")
|
71
|
-
nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
62
|
def initialize(app, push_host, push_port, feedback_host, feedback_port, feedback_poll)
|
76
63
|
@app = app
|
77
64
|
@push_host = push_host
|
data/lib/rapns/version.rb
CHANGED
@@ -140,8 +140,8 @@ describe Rapns::Daemon::AppRunner, 'ready' do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
describe Rapns::Daemon::AppRunner, 'sync' do
|
143
|
-
let(:app) { stub(:key => 'app') }
|
144
|
-
let(:new_app) { stub(:key => 'new_app') }
|
143
|
+
let(:app) { stub(:key => 'app', :environment => 'development') }
|
144
|
+
let(:new_app) { stub(:key => 'new_app', :environment => 'development') }
|
145
145
|
let(:runner) { stub(:sync => nil, :stop => nil) }
|
146
146
|
let(:new_runner) { stub }
|
147
147
|
let(:logger) { stub(:error => nil) }
|
@@ -166,7 +166,7 @@ describe Rapns::Daemon::AppRunner, 'sync' do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'starts a runner for a new app with a production certificate' do
|
169
|
-
new_app.stub(:
|
169
|
+
new_app.stub(:environment => 'production')
|
170
170
|
Rapns::App.stub(:all => [new_app])
|
171
171
|
new_runner = stub
|
172
172
|
Rapns::Daemon::AppRunner.should_receive(:new).with(new_app, 'gateway.push.apple.com', 2195,
|
@@ -176,7 +176,7 @@ it 'starts a runner for a new app with a production certificate' do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'starts a runner for a new app with a development certificate' do
|
179
|
-
new_app.stub(:
|
179
|
+
new_app.stub(:environment => 'development')
|
180
180
|
Rapns::App.stub(:all => [new_app])
|
181
181
|
new_runner = stub
|
182
182
|
Rapns::Daemon::AppRunner.should_receive(:new).with(new_app, 'gateway.sandbox.push.apple.com', 2195,
|
@@ -185,20 +185,6 @@ it 'starts a runner for a new app with a production certificate' do
|
|
185
185
|
Rapns::Daemon::AppRunner.sync
|
186
186
|
end
|
187
187
|
|
188
|
-
it 'logs an error if the environment cannot be determined from the certificate' do
|
189
|
-
new_app.stub(:certificate => 'wat')
|
190
|
-
Rapns::App.stub(:all => [new_app])
|
191
|
-
Rapns::Daemon.logger.should_receive(:error).with("Could not detect environment for app 'new_app'.")
|
192
|
-
Rapns::Daemon::AppRunner.sync
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'does not attempt to start an AppRunner if the environment could not be detected' do
|
196
|
-
new_app.stub(:certificate => 'wat')
|
197
|
-
Rapns::App.stub(:all => [new_app])
|
198
|
-
Rapns::Daemon::AppRunner.should_not_receive(:new)
|
199
|
-
Rapns::Daemon::AppRunner.sync
|
200
|
-
end
|
201
|
-
|
202
188
|
it 'deletes old apps' do
|
203
189
|
Rapns::App.stub(:all => [])
|
204
190
|
runner.should_receive(:stop)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.0rc2
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easy to use library for Apple's Push Notification Service with Rails
|
15
15
|
3
|