rapns 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -10
- data/lib/generators/rapns_generator.rb +9 -1
- data/lib/generators/templates/create_rapns_feedback.rb +15 -0
- data/lib/generators/templates/rapns.yml +22 -9
- data/lib/rapns/daemon/configuration.rb +32 -14
- data/lib/rapns/daemon/connection.rb +35 -50
- data/lib/rapns/daemon/delivery_handler.rb +65 -15
- data/lib/rapns/daemon/delivery_handler_pool.rb +1 -5
- data/lib/rapns/daemon/delivery_queue.rb +10 -27
- data/lib/rapns/daemon/feedback_receiver.rb +57 -0
- data/lib/rapns/daemon/feeder.rb +9 -7
- data/lib/rapns/daemon/interruptible_sleep.rb +14 -0
- data/lib/rapns/daemon/pool.rb +0 -5
- data/lib/rapns/daemon.rb +9 -9
- data/lib/rapns/device_token_format_validator.rb +10 -0
- data/lib/rapns/feedback.rb +10 -0
- data/lib/rapns/notification.rb +15 -1
- data/lib/rapns/version.rb +1 -1
- data/lib/rapns.rb +3 -1
- data/spec/rapns/daemon/certificate_spec.rb +6 -0
- data/spec/rapns/daemon/configuration_spec.rb +124 -40
- data/spec/rapns/daemon/connection_spec.rb +81 -129
- data/spec/rapns/daemon/delivery_handler_pool_spec.rb +1 -6
- data/spec/rapns/daemon/delivery_handler_spec.rb +117 -30
- data/spec/rapns/daemon/delivery_queue_spec.rb +29 -0
- data/spec/rapns/daemon/feedback_receiver_spec.rb +86 -0
- data/spec/rapns/daemon/feeder_spec.rb +25 -9
- data/spec/rapns/daemon/interruptible_sleep_spec.rb +32 -0
- data/spec/rapns/daemon/logger_spec.rb +34 -14
- data/spec/rapns/daemon_spec.rb +34 -31
- data/spec/rapns/feedback_spec.rb +12 -0
- data/spec/rapns/notification_spec.rb +5 -0
- data/spec/spec_helper.rb +5 -2
- metadata +16 -5
- data/lib/rapns/daemon/connection_pool.rb +0 -31
- data/spec/rapns/daemon/connection_pool_spec.rb +0 -40
@@ -0,0 +1,86 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rapns::Daemon::FeedbackReceiver, 'check_for_feedback' do
|
4
|
+
let(:connection) { stub(:connect => nil, :read => nil, :close => nil) }
|
5
|
+
let(:logger) { stub(:error => nil, :info => nil) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Rapns::Daemon::FeedbackReceiver.stub(:interruptible_sleep)
|
9
|
+
Rapns::Daemon.logger = logger
|
10
|
+
Rapns::Daemon::Connection.stub(:new => connection)
|
11
|
+
Rapns::Feedback.stub(:create!)
|
12
|
+
Rapns::Daemon.configuration = stub(:feedback => stub(:host => 'feedback.push.apple.com', :port => 2196, :poll => 60))
|
13
|
+
Rapns::Daemon::FeedbackReceiver.instance_variable_set("@stop", false)
|
14
|
+
end
|
15
|
+
|
16
|
+
def stub_connection_read_with_tuple
|
17
|
+
connection.unstub(:read)
|
18
|
+
|
19
|
+
def connection.read(bytes)
|
20
|
+
if !@called
|
21
|
+
@called = true
|
22
|
+
"N\xE3\x84\r\x00 \x83OxfU\xEB\x9F\x84aJ\x05\xAD}\x00\xAF1\xE5\xCF\xE9:\xC3\xEA\a\x8F\x1D\xA4M*N\xB0\xCE\x17"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'instantiates a new connection' do
|
28
|
+
Rapns::Daemon::Connection.should_receive(:new).with("FeedbackReceiver", 'feedback.push.apple.com', 2196)
|
29
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'connects to the feeback service' do
|
33
|
+
connection.should_receive(:connect)
|
34
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'closes the connection' do
|
38
|
+
connection.should_receive(:close)
|
39
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'reads from the connection' do
|
43
|
+
connection.should_receive(:read).with(38)
|
44
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'logs the feedback' do
|
48
|
+
stub_connection_read_with_tuple
|
49
|
+
Rapns::Daemon.logger.should_receive(:info).with("[FeedbackReceiver] Delivery failed at 2011-12-10 16:08:45 UTC for 834f786655eb9f84614a05ad7d00af31e5cfe93ac3ea078f1da44d2a4eb0ce17")
|
50
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'creates the feedback' do
|
54
|
+
stub_connection_read_with_tuple
|
55
|
+
Rapns::Feedback.should_receive(:create!).with(:failed_at => Time.at(1323533325), :device_token => '834f786655eb9f84614a05ad7d00af31e5cfe93ac3ea078f1da44d2a4eb0ce17')
|
56
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'logs errors' do
|
60
|
+
error = StandardError.new('bork!')
|
61
|
+
connection.stub(:read).and_raise(error)
|
62
|
+
Rapns::Daemon.logger.should_receive(:error).with(error)
|
63
|
+
Rapns::Daemon::FeedbackReceiver.check_for_feedback
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'sleeps for the feedback poll period' do
|
67
|
+
Rapns::Daemon::FeedbackReceiver.stub(:check_for_feedback)
|
68
|
+
Rapns::Daemon::FeedbackReceiver.should_receive(:interruptible_sleep).with(60).at_least(:once)
|
69
|
+
Thread.stub(:new).and_yield
|
70
|
+
Rapns::Daemon::FeedbackReceiver.stub(:loop).and_yield
|
71
|
+
Rapns::Daemon::FeedbackReceiver.start
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'checks for feedback when started' do
|
75
|
+
Rapns::Daemon::FeedbackReceiver.should_receive(:check_for_feedback).at_least(:once)
|
76
|
+
Thread.stub(:new).and_yield
|
77
|
+
Rapns::Daemon::FeedbackReceiver.stub(:loop).and_yield
|
78
|
+
Rapns::Daemon::FeedbackReceiver.start
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'interrupts sleep when stopped' do
|
82
|
+
Rapns::Daemon::FeedbackReceiver.stub(:check_for_feedback)
|
83
|
+
Rapns::Daemon::FeedbackReceiver.should_receive(:interrupt_sleep)
|
84
|
+
Rapns::Daemon::FeedbackReceiver.stop
|
85
|
+
end
|
86
|
+
end
|
@@ -3,12 +3,14 @@ require "spec_helper"
|
|
3
3
|
describe Rapns::Daemon::Feeder do
|
4
4
|
before do
|
5
5
|
Rapns::Daemon::Feeder.stub(:sleep)
|
6
|
+
Rapns::Daemon::Feeder.stub(:interruptible_sleep)
|
6
7
|
@notification = Rapns::Notification.create!(:device_token => "a" * 64)
|
7
8
|
@logger = mock("Logger", :info => nil, :error => nil, :warn => nil)
|
8
9
|
Rapns::Daemon.stub(:logger).and_return(@logger)
|
9
|
-
@queue = mock(:push => nil, :
|
10
|
+
@queue = mock(:push => nil, :notifications_processed? => true)
|
10
11
|
Rapns::Daemon.stub(:delivery_queue).and_return(@queue)
|
11
|
-
Rapns::Daemon.stub(:configuration => mock("Configuration", :poll => 2))
|
12
|
+
Rapns::Daemon.stub(:configuration => mock("Configuration", :push => stub(:poll => 2)))
|
13
|
+
Rapns::Daemon::Feeder.instance_variable_set("@stop", false)
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should reconnect to the database when daemonized" do
|
@@ -59,13 +61,10 @@ describe Rapns::Daemon::Feeder do
|
|
59
61
|
Rapns::Daemon::Feeder.enqueue_notifications
|
60
62
|
end
|
61
63
|
|
62
|
-
it "should
|
63
|
-
Rapns::Daemon
|
64
|
-
Rapns::
|
65
|
-
|
66
|
-
|
67
|
-
it "should wait for a delivery handler to become available" do
|
68
|
-
Rapns::Daemon.delivery_queue.should_receive(:wait_for_available_handler)
|
64
|
+
it "should not enqueue more notifications if other are still being processed" do
|
65
|
+
Rapns::Daemon.delivery_queue.stub(:notifications_processed? => false)
|
66
|
+
Rapns::Notification.should_not_receive(:ready_for_delivery)
|
67
|
+
Rapns::Daemon.delivery_queue.should_not_receive(:push)
|
69
68
|
Rapns::Daemon::Feeder.enqueue_notifications
|
70
69
|
end
|
71
70
|
|
@@ -76,6 +75,23 @@ describe Rapns::Daemon::Feeder do
|
|
76
75
|
Rapns::Daemon::Feeder.enqueue_notifications
|
77
76
|
end
|
78
77
|
|
78
|
+
it "interrupts sleep when stopped" do
|
79
|
+
Rapns::Daemon::Feeder.should_receive(:interrupt_sleep)
|
80
|
+
Rapns::Daemon::Feeder.stop
|
81
|
+
end
|
82
|
+
|
83
|
+
it "enqueues notifications when started" do
|
84
|
+
Rapns::Daemon::Feeder.should_receive(:enqueue_notifications).at_least(:once)
|
85
|
+
Rapns::Daemon::Feeder.stub(:loop).and_yield
|
86
|
+
Rapns::Daemon::Feeder.start(true)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should sleep for the given period" do
|
90
|
+
Rapns::Daemon::Feeder.should_receive(:interruptible_sleep).with(2)
|
91
|
+
Rapns::Daemon::Feeder.stub(:loop).and_yield
|
92
|
+
Rapns::Daemon::Feeder.start(true)
|
93
|
+
end
|
94
|
+
|
79
95
|
context "when the database connection is lost" do
|
80
96
|
let(:error) { adapter_error.new("db down!") }
|
81
97
|
before do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rapns::Daemon::InterruptibleSleep do
|
4
|
+
class SleepTest
|
5
|
+
extend Rapns::Daemon::InterruptibleSleep
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
IO.stub(:pipe)
|
10
|
+
IO.stub(:select)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'creates a new pipe' do
|
14
|
+
IO.should_receive(:pipe)
|
15
|
+
SleepTest.interruptible_sleep 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'selects on the reader' do
|
19
|
+
rd = stub
|
20
|
+
IO.stub(:pipe => [rd, stub])
|
21
|
+
IO.should_receive(:select).with([rd], nil, nil, 1)
|
22
|
+
SleepTest.interruptible_sleep 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'closes the writer' do
|
26
|
+
wr = stub
|
27
|
+
IO.stub(:pipe => [stub, wr])
|
28
|
+
SleepTest.interruptible_sleep 1
|
29
|
+
wr.should_receive(:close)
|
30
|
+
SleepTest.interrupt_sleep
|
31
|
+
end
|
32
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
module Rails
|
4
|
+
def self.logger
|
5
|
+
@logger
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
def self.logger=(logger)
|
9
|
+
@logger = logger
|
12
10
|
end
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
module HoptoadNotifier
|
14
|
+
def self.notify(e)
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
module Airbrake
|
19
|
+
def self.notify(e)
|
22
20
|
end
|
21
|
+
end
|
23
22
|
|
23
|
+
describe Rapns::Daemon::Logger do
|
24
24
|
before do
|
25
25
|
Rails.stub(:root).and_return("/rails_root")
|
26
26
|
@buffered_logger = mock("BufferedLogger", :info => nil, :error => nil, :level => 0, :auto_flushing => 1, :auto_flushing= => nil)
|
@@ -81,6 +81,26 @@ describe Rapns::Daemon::Logger do
|
|
81
81
|
logger.error(e)
|
82
82
|
end
|
83
83
|
|
84
|
+
context "without Airbrake defined" do
|
85
|
+
before do
|
86
|
+
Object.send(:remove_const, :Airbrake)
|
87
|
+
end
|
88
|
+
|
89
|
+
after do
|
90
|
+
module Airbrake
|
91
|
+
def self.notify(e)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should notify using HoptoadNotifier" do
|
97
|
+
e = RuntimeError.new("hi mom")
|
98
|
+
logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => true)
|
99
|
+
HoptoadNotifier.should_receive(:notify).with(e)
|
100
|
+
logger.error(e)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
84
104
|
it "should not notify Airbrake of the exception if the airbrake_notify option is false" do
|
85
105
|
e = RuntimeError.new("hi mom")
|
86
106
|
logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => false)
|
data/spec/rapns/daemon_spec.rb
CHANGED
@@ -4,27 +4,43 @@ describe Rapns::Daemon, "when starting" do
|
|
4
4
|
module Rails
|
5
5
|
end
|
6
6
|
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
"airbrake_notify" => true,
|
10
|
+
"certificate" => "development.pem",
|
11
|
+
"certificate_password" => "abc123",
|
12
|
+
"pid_file" => "rapns.pid",
|
13
|
+
"push" => {
|
14
|
+
"port" => 123,
|
15
|
+
"host" => "localhost",
|
16
|
+
"poll" => 4,
|
17
|
+
"connections" => 3
|
18
|
+
},
|
19
|
+
"feedback" => {
|
20
|
+
"port" => 123,
|
21
|
+
"host" => "localhost",
|
22
|
+
"poll" => 30,
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
7
27
|
before do
|
8
28
|
Rails.stub(:root).and_return("/rails_root")
|
9
29
|
|
10
30
|
@configuration = Rapns::Daemon::Configuration.new("development", "/rails_root/config/rapns/rapns.yml")
|
11
|
-
@configuration.stub(:read_config).and_return({"development" =>
|
31
|
+
@configuration.stub(:read_config).and_return({"development" => config})
|
12
32
|
Rapns::Daemon::Configuration.stub(:new).and_return(@configuration)
|
13
33
|
|
14
34
|
@certificate = Rapns::Daemon::Certificate.new("/rails_root/config/rapns/development.pem")
|
15
35
|
@certificate.stub(:read_certificate).and_return("certificate contents")
|
16
36
|
Rapns::Daemon::Certificate.stub(:new).and_return(@certificate)
|
17
37
|
|
18
|
-
@connection_pool = Rapns::Daemon::ConnectionPool.new(3)
|
19
|
-
@connection_pool.stub(:populate)
|
20
|
-
Rapns::Daemon::ConnectionPool.stub(:new).and_return(@connection_pool)
|
21
|
-
|
22
38
|
@handler_pool = Rapns::Daemon::DeliveryHandlerPool.new(3)
|
23
39
|
@handler_pool.stub(:populate)
|
24
40
|
Rapns::Daemon::DeliveryHandlerPool.stub(:new).and_return(@handler_pool)
|
25
41
|
|
42
|
+
Rapns::Daemon::FeedbackReceiver.stub(:start)
|
26
43
|
Rapns::Daemon::Feeder.stub(:start)
|
27
|
-
Rapns::Daemon::Feeder.stub(:wait)
|
28
44
|
Rapns::Daemon.stub(:daemonize)
|
29
45
|
Rapns::Daemon.stub(:write_pid_file)
|
30
46
|
@logger = mock("Logger", :info => nil)
|
@@ -54,22 +70,11 @@ describe Rapns::Daemon, "when starting" do
|
|
54
70
|
Rapns::Daemon.certificate.should == @certificate
|
55
71
|
end
|
56
72
|
|
57
|
-
it "should
|
58
|
-
Rapns::Daemon::
|
59
|
-
@connection_pool.should_receive(:populate)
|
60
|
-
Rapns::Daemon.start("development", {})
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should initialize the delivery queue with the number of connection as its signal point" do
|
64
|
-
Rapns::Daemon::DeliveryQueue.should_receive(:new).with(3)
|
73
|
+
it "should initialize the delivery queue" do
|
74
|
+
Rapns::Daemon::DeliveryQueue.should_receive(:new)
|
65
75
|
Rapns::Daemon.start("development", {})
|
66
76
|
end
|
67
77
|
|
68
|
-
it "should make the connection pool accessible" do
|
69
|
-
Rapns::Daemon.start("development", {})
|
70
|
-
Rapns::Daemon.connection_pool.should == @connection_pool
|
71
|
-
end
|
72
|
-
|
73
78
|
it "should populate the delivery handler pool" do
|
74
79
|
Rapns::Daemon::DeliveryHandlerPool.should_receive(:new).with(3).and_return(@handler_pool)
|
75
80
|
@handler_pool.should_receive(:populate)
|
@@ -97,6 +102,11 @@ describe Rapns::Daemon, "when starting" do
|
|
97
102
|
Rapns::Daemon.start("development", {})
|
98
103
|
end
|
99
104
|
|
105
|
+
it "should start the feedback receiver" do
|
106
|
+
Rapns::Daemon::FeedbackReceiver.should_receive(:start)
|
107
|
+
Rapns::Daemon.start("development", true)
|
108
|
+
end
|
109
|
+
|
100
110
|
it "should start the feeder" do
|
101
111
|
Rapns::Daemon::Feeder.should_receive(:start)
|
102
112
|
Rapns::Daemon.start("development", true)
|
@@ -118,8 +128,7 @@ describe Rapns::Daemon, "when being shutdown" do
|
|
118
128
|
before do
|
119
129
|
Rails.stub(:root).and_return("/rails_root")
|
120
130
|
Rapns::Daemon::Feeder.stub(:stop)
|
121
|
-
|
122
|
-
Rapns::Daemon.stub(:connection_pool).and_return(@connection_pool)
|
131
|
+
Rapns::Daemon::FeedbackReceiver.stub(:stop)
|
123
132
|
@handler_pool = mock("DeliveryHandlerPool", :drain => nil)
|
124
133
|
Rapns::Daemon.stub(:delivery_handler_pool).and_return(@handler_pool)
|
125
134
|
@configuration = mock("Configuration", :pid_file => File.join(Rails.root, "rapns.pid"))
|
@@ -127,19 +136,13 @@ describe Rapns::Daemon, "when being shutdown" do
|
|
127
136
|
Rapns::Daemon.stub(:puts)
|
128
137
|
end
|
129
138
|
|
130
|
-
it "should stop the
|
131
|
-
Rapns::Daemon::
|
139
|
+
it "should stop the feedback receiver" do
|
140
|
+
Rapns::Daemon::FeedbackReceiver.should_receive(:stop)
|
132
141
|
Rapns::Daemon.send(:shutdown)
|
133
142
|
end
|
134
143
|
|
135
|
-
it "should
|
136
|
-
|
137
|
-
Rapns::Daemon.send(:shutdown)
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not attempt to drain the connection pool if it has not been initialized" do
|
141
|
-
Rapns::Daemon.stub(:connection_pool).and_return(nil)
|
142
|
-
@connection_pool.should_not_receive(:drain)
|
144
|
+
it "should stop the feeder" do
|
145
|
+
Rapns::Daemon::Feeder.should_receive(:stop)
|
143
146
|
Rapns::Daemon.send(:shutdown)
|
144
147
|
end
|
145
148
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rapns::Feedback do
|
4
|
+
it { should validate_presence_of(:device_token) }
|
5
|
+
it { should validate_presence_of(:failed_at) }
|
6
|
+
|
7
|
+
it "should validate the format of the device_token" do
|
8
|
+
notification = Rapns::Feedback.new(:device_token => "{$%^&*()}")
|
9
|
+
notification.valid?.should be_false
|
10
|
+
notification.errors[:device_token].include?("is invalid").should be_true
|
11
|
+
end
|
12
|
+
end
|
@@ -68,6 +68,11 @@ describe Rapns::Notification, "as_json" do
|
|
68
68
|
notification.as_json["aps"].key?("alert").should be_false
|
69
69
|
end
|
70
70
|
|
71
|
+
it "should encode the alert as JSON if it is a Hash" do
|
72
|
+
notification = Rapns::Notification.new(:alert => { 'body' => "hi mom", 'alert-loc-key' => "View" })
|
73
|
+
notification.as_json["aps"]["alert"].should == { 'body' => "hi mom", 'alert-loc-key' => "View" }
|
74
|
+
end
|
75
|
+
|
71
76
|
it "should include the badge if present" do
|
72
77
|
notification = Rapns::Notification.new(:badge => 6)
|
73
78
|
notification.as_json["aps"]["badge"].should == 6
|
data/spec/spec_helper.rb
CHANGED
@@ -17,9 +17,12 @@ end
|
|
17
17
|
puts "Using #{$adapter} adapter."
|
18
18
|
ActiveRecord::Base.establish_connection('adapter' => $adapter, 'database' => 'rapns_test')
|
19
19
|
require 'generators/templates/create_rapns_notifications'
|
20
|
+
require 'generators/templates/create_rapns_feedback'
|
20
21
|
|
21
|
-
CreateRapnsNotifications.
|
22
|
-
|
22
|
+
[CreateRapnsNotifications, CreateRapnsFeedback].each do |migration|
|
23
|
+
migration.down rescue ActiveRecord::StatementInvalid
|
24
|
+
migration.up
|
25
|
+
end
|
23
26
|
|
24
27
|
require 'bundler'
|
25
28
|
Bundler.require(:default)
|
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
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: 2011-11
|
12
|
+
date: 2011-12-11 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
|
@@ -21,6 +21,7 @@ extensions: []
|
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- lib/generators/rapns_generator.rb
|
24
|
+
- lib/generators/templates/create_rapns_feedback.rb
|
24
25
|
- lib/generators/templates/create_rapns_notifications.rb
|
25
26
|
- lib/generators/templates/rapns.yml
|
26
27
|
- lib/rapns.rb
|
@@ -29,14 +30,17 @@ files:
|
|
29
30
|
- lib/rapns/daemon/certificate.rb
|
30
31
|
- lib/rapns/daemon/configuration.rb
|
31
32
|
- lib/rapns/daemon/connection.rb
|
32
|
-
- lib/rapns/daemon/connection_pool.rb
|
33
33
|
- lib/rapns/daemon/delivery_error.rb
|
34
34
|
- lib/rapns/daemon/delivery_handler.rb
|
35
35
|
- lib/rapns/daemon/delivery_handler_pool.rb
|
36
36
|
- lib/rapns/daemon/delivery_queue.rb
|
37
|
+
- lib/rapns/daemon/feedback_receiver.rb
|
37
38
|
- lib/rapns/daemon/feeder.rb
|
39
|
+
- lib/rapns/daemon/interruptible_sleep.rb
|
38
40
|
- lib/rapns/daemon/logger.rb
|
39
41
|
- lib/rapns/daemon/pool.rb
|
42
|
+
- lib/rapns/device_token_format_validator.rb
|
43
|
+
- lib/rapns/feedback.rb
|
40
44
|
- lib/rapns/notification.rb
|
41
45
|
- lib/rapns/patches.rb
|
42
46
|
- lib/rapns/patches/rails/3.1.0/postgresql_adapter.rb
|
@@ -45,14 +49,17 @@ files:
|
|
45
49
|
- README.md
|
46
50
|
- spec/rapns/daemon/certificate_spec.rb
|
47
51
|
- spec/rapns/daemon/configuration_spec.rb
|
48
|
-
- spec/rapns/daemon/connection_pool_spec.rb
|
49
52
|
- spec/rapns/daemon/connection_spec.rb
|
50
53
|
- spec/rapns/daemon/delivery_error_spec.rb
|
51
54
|
- spec/rapns/daemon/delivery_handler_pool_spec.rb
|
52
55
|
- spec/rapns/daemon/delivery_handler_spec.rb
|
56
|
+
- spec/rapns/daemon/delivery_queue_spec.rb
|
57
|
+
- spec/rapns/daemon/feedback_receiver_spec.rb
|
53
58
|
- spec/rapns/daemon/feeder_spec.rb
|
59
|
+
- spec/rapns/daemon/interruptible_sleep_spec.rb
|
54
60
|
- spec/rapns/daemon/logger_spec.rb
|
55
61
|
- spec/rapns/daemon_spec.rb
|
62
|
+
- spec/rapns/feedback_spec.rb
|
56
63
|
- spec/rapns/notification_spec.rb
|
57
64
|
- spec/spec_helper.rb
|
58
65
|
- bin/rapns
|
@@ -83,13 +90,17 @@ summary: Easy to use library for Apple's Push Notification Service with Rails 3
|
|
83
90
|
test_files:
|
84
91
|
- spec/rapns/daemon/certificate_spec.rb
|
85
92
|
- spec/rapns/daemon/configuration_spec.rb
|
86
|
-
- spec/rapns/daemon/connection_pool_spec.rb
|
87
93
|
- spec/rapns/daemon/connection_spec.rb
|
88
94
|
- spec/rapns/daemon/delivery_error_spec.rb
|
89
95
|
- spec/rapns/daemon/delivery_handler_pool_spec.rb
|
90
96
|
- spec/rapns/daemon/delivery_handler_spec.rb
|
97
|
+
- spec/rapns/daemon/delivery_queue_spec.rb
|
98
|
+
- spec/rapns/daemon/feedback_receiver_spec.rb
|
91
99
|
- spec/rapns/daemon/feeder_spec.rb
|
100
|
+
- spec/rapns/daemon/interruptible_sleep_spec.rb
|
92
101
|
- spec/rapns/daemon/logger_spec.rb
|
93
102
|
- spec/rapns/daemon_spec.rb
|
103
|
+
- spec/rapns/feedback_spec.rb
|
94
104
|
- spec/rapns/notification_spec.rb
|
95
105
|
- spec/spec_helper.rb
|
106
|
+
has_rdoc:
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Rapns
|
2
|
-
module Daemon
|
3
|
-
class ConnectionPool < Pool
|
4
|
-
|
5
|
-
def claim_connection
|
6
|
-
connection = nil
|
7
|
-
begin
|
8
|
-
connection = @queue.pop
|
9
|
-
yield connection
|
10
|
-
ensure
|
11
|
-
@queue.push(connection) if connection
|
12
|
-
end
|
13
|
-
connection
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def new_object_for_pool(i)
|
19
|
-
Connection.new("Connection #{i}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def object_added_to_pool(object)
|
23
|
-
object.connect
|
24
|
-
end
|
25
|
-
|
26
|
-
def object_removed_from_pool(object)
|
27
|
-
object.close
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Rapns::Daemon::ConnectionPool do
|
4
|
-
before do
|
5
|
-
@connection = mock("Connection", :connect => nil)
|
6
|
-
Rapns::Daemon::Connection.stub(:new).and_return(@connection)
|
7
|
-
@pool = Rapns::Daemon::ConnectionPool.new(3)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should populate the pool" do
|
11
|
-
Rapns::Daemon::Connection.should_receive(:new).exactly(3).times
|
12
|
-
@pool.populate
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should tell each connection to close when drained" do
|
16
|
-
@pool.populate
|
17
|
-
@connection.should_receive(:close).exactly(3).times
|
18
|
-
@pool.drain
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe Rapns::Daemon::ConnectionPool, "when claiming a connection" do
|
23
|
-
before do
|
24
|
-
@connection = mock("Connection", :connect => nil)
|
25
|
-
Rapns::Daemon::Connection.stub(:new).and_return(@connection)
|
26
|
-
@pool = Rapns::Daemon::ConnectionPool.new(3)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should pop the connection from the pool" do
|
30
|
-
@pool.instance_variable_get("@queue").should_receive(:pop)
|
31
|
-
@pool.claim_connection {}
|
32
|
-
end
|
33
|
-
|
34
|
-
it "shuld push the connection into the pool after use" do
|
35
|
-
@pool.instance_variable_get("@queue").stub(:pop).and_return(@connection)
|
36
|
-
@pool.instance_variable_get("@queue").should_receive(:push).with(@connection)
|
37
|
-
@pool.claim_connection {}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|