rpush 2.2.0 → 2.3.0.rc1

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +17 -9
  4. data/lib/generators/rpush_migration_generator.rb +1 -1
  5. data/lib/rpush.rb +4 -1
  6. data/lib/rpush/apns_feedback.rb +1 -1
  7. data/lib/rpush/cli.rb +25 -22
  8. data/lib/rpush/client/active_model/apns/app.rb +1 -1
  9. data/lib/rpush/client/active_model/apns/notification.rb +2 -2
  10. data/lib/rpush/client/active_model/wpns/notification.rb +7 -1
  11. data/lib/rpush/configuration.rb +32 -22
  12. data/lib/rpush/daemon.rb +18 -9
  13. data/lib/rpush/daemon/adm/delivery.rb +4 -1
  14. data/lib/rpush/daemon/apns/delivery.rb +3 -0
  15. data/lib/rpush/daemon/apns/feedback_receiver.rb +6 -2
  16. data/lib/rpush/daemon/app_runner.rb +11 -16
  17. data/lib/rpush/daemon/batch.rb +9 -0
  18. data/lib/rpush/daemon/delivery.rb +10 -2
  19. data/lib/rpush/daemon/delivery_error.rb +3 -3
  20. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +11 -11
  21. data/lib/rpush/daemon/dispatcher/tcp.rb +2 -10
  22. data/lib/rpush/daemon/gcm/delivery.rb +13 -7
  23. data/lib/rpush/daemon/signal_handler.rb +5 -3
  24. data/lib/rpush/daemon/store/active_record.rb +14 -0
  25. data/lib/rpush/daemon/store/interface.rb +2 -1
  26. data/lib/rpush/daemon/store/redis.rb +3 -0
  27. data/lib/rpush/daemon/tcp_connection.rb +47 -17
  28. data/lib/rpush/daemon/wpns/delivery.rb +19 -10
  29. data/lib/rpush/logger.rb +30 -12
  30. data/lib/rpush/plugin.rb +44 -0
  31. data/lib/rpush/push.rb +1 -1
  32. data/lib/rpush/reflectable.rb +11 -0
  33. data/lib/rpush/{reflection.rb → reflection_collection.rb} +1 -9
  34. data/lib/rpush/reflection_public_methods.rb +9 -0
  35. data/lib/rpush/version.rb +1 -1
  36. data/lib/tasks/test.rake +6 -4
  37. data/spec/functional/adm_spec.rb +12 -0
  38. data/spec/functional/apns_spec.rb +61 -42
  39. data/spec/functional/gcm_spec.rb +9 -0
  40. data/spec/functional/retry_spec.rb +1 -1
  41. data/spec/functional/wpns_spec.rb +44 -11
  42. data/spec/spec_helper.rb +2 -0
  43. data/spec/unit/apns_feedback_spec.rb +2 -2
  44. data/spec/unit/client/active_record/apns/app_spec.rb +2 -2
  45. data/spec/unit/client/active_record/apns/notification_spec.rb +1 -2
  46. data/spec/unit/client/active_record/wpns/notification_spec.rb +9 -3
  47. data/spec/unit/configuration_spec.rb +1 -0
  48. data/spec/unit/daemon/adm/delivery_spec.rb +0 -1
  49. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +0 -1
  50. data/spec/unit/daemon/app_runner_spec.rb +14 -9
  51. data/spec/unit/daemon/delivery_spec.rb +0 -1
  52. data/spec/unit/daemon/dispatcher/tcp_spec.rb +0 -7
  53. data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
  54. data/spec/unit/daemon/signal_handler_spec.rb +5 -1
  55. data/spec/unit/daemon/store/active_record_spec.rb +1 -1
  56. data/spec/unit/daemon/tcp_connection_spec.rb +18 -18
  57. data/spec/unit/daemon/wpns/delivery_spec.rb +1 -1
  58. data/spec/unit/daemon_spec.rb +10 -2
  59. data/spec/unit/logger_spec.rb +0 -1
  60. data/spec/unit/plugin_spec.rb +36 -0
  61. data/spec/unit/push_spec.rb +2 -2
  62. data/spec/unit/{daemon/reflectable_spec.rb → reflectable_spec.rb} +6 -6
  63. data/spec/unit/{reflection_spec.rb → reflection_collection_spec.rb} +4 -8
  64. metadata +16 -18
  65. data/lib/rpush/daemon/reflectable.rb +0 -11
  66. data/spec/integration/rpush_spec.rb +0 -13
  67. data/spec/integration/support/gcm_success_response.json +0 -1
  68. data/spec/support/install.sh +0 -68
@@ -2,7 +2,7 @@ require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Daemon::Wpns::Delivery do
4
4
  let(:app) { Rpush::Wpns::App.create!(name: "MyApp") }
5
- let(:notification) { Rpush::Wpns::Notification.create!(app: app, alert: "test", uri: "http://some.example/", deliver_after: Time.now) }
5
+ let(:notification) { Rpush::Wpns::Notification.create!(app: app, data: { title: "MyApp", body: "Example notification", param: "/param1" }, uri: "http://some.example/", deliver_after: Time.now) }
6
6
  let(:logger) { double(error: nil, info: nil, warn: nil) }
7
7
  let(:response) { double(code: 200, header: {}) }
8
8
  let(:http) { double(shutdown: nil, request: response) }
@@ -6,7 +6,7 @@ describe Rpush::Daemon, "when starting" do
6
6
 
7
7
  let(:certificate) { double }
8
8
  let(:password) { double }
9
- let(:logger) { double(:logger, info: nil, error: nil, warn: nil) }
9
+ let(:logger) { double(:logger, info: nil, error: nil, warn: nil, internal_logger: nil) }
10
10
 
11
11
  before do
12
12
  Rpush.stub(logger: logger)
@@ -22,7 +22,7 @@ describe Rpush::Daemon, "when starting" do
22
22
  unless Rpush.jruby?
23
23
  it "forks into a daemon if the foreground option is false" do
24
24
  Rpush.config.foreground = false
25
- Rpush::Daemon.initialize_store
25
+ Rpush::Daemon.common_init
26
26
  Process.should_receive(:daemon)
27
27
  Rpush::Daemon.start
28
28
  end
@@ -63,6 +63,14 @@ describe Rpush::Daemon, "when starting" do
63
63
  Rpush::Daemon.store.should be_kind_of(Rpush::Daemon::Store::ActiveRecord)
64
64
  end
65
65
 
66
+ it 'initializes plugins' do
67
+ plugin = Rpush.plugin(:test)
68
+ did_init = false
69
+ plugin.init { did_init = true }
70
+ Rpush::Daemon.common_init
71
+ expect(did_init).to be_true
72
+ end
73
+
66
74
  it 'logs an error if the store cannot be loaded' do
67
75
  Rpush.config.client = :foo_bar
68
76
  Rpush.logger.should_receive(:error).with(kind_of(LoadError))
@@ -21,7 +21,6 @@ describe Rpush::Logger do
21
21
 
22
22
  it "disables logging if the log file cannot be opened" do
23
23
  File.stub(:open).and_raise(Errno::ENOENT)
24
- STDERR.should_receive(:puts).with(/No such file or directory/)
25
24
  STDERR.should_receive(:puts).with(/Logging disabled/)
26
25
  Rpush::Logger.new
27
26
  end
@@ -0,0 +1,36 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Plugin do
4
+ include Rpush::Reflectable
5
+
6
+ it 'can only be initialized once' do
7
+ plugin = double(Rpush::Plugin, unload: nil)
8
+ expect(Rpush::Plugin).to receive(:new).once.and_return(plugin)
9
+ Rpush.plugin(:test)
10
+ Rpush.plugin(:test)
11
+ end
12
+
13
+ it 'can be referenced' do
14
+ plugin = Rpush.plugin(:test)
15
+ expect(Rpush.plugins[:test]).to eq(plugin)
16
+ end
17
+
18
+ it 'can be configured' do
19
+ plugin = Rpush.plugin(:test)
20
+ plugin.configure do |config|
21
+ config.is_configured = true
22
+ end
23
+ expect(Rpush.config.plugin.test.is_configured).to be_true
24
+ end
25
+
26
+ it 'can hook up reflections' do
27
+ plugin = Rpush.plugin(:test)
28
+ reflected_error = nil
29
+ plugin.reflect do |on|
30
+ on.error { |error| reflected_error = error }
31
+ end
32
+ error = double
33
+ reflect(:error, error)
34
+ expect(reflected_error).to eq(error)
35
+ end
36
+ end
@@ -12,8 +12,8 @@ describe Rpush, 'push' do
12
12
  Rpush.config.push.should be_true
13
13
  end
14
14
 
15
- it 'initializes the store' do
16
- Rpush::Daemon.should_receive(:initialize_store)
15
+ it 'initializes the daemon' do
16
+ Rpush::Daemon.should_receive(:common_init)
17
17
  Rpush.push
18
18
  end
19
19
 
@@ -1,26 +1,26 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
- describe Rpush::Daemon::Reflectable do
3
+ describe Rpush::Reflectable do
4
4
  class TestReflectable
5
- include Rpush::Daemon::Reflectable
5
+ include Rpush::Reflectable
6
6
  end
7
7
 
8
8
  let(:logger) { double(error: nil) }
9
9
  let(:test_reflectable) { TestReflectable.new }
10
10
 
11
11
  before do
12
- Rpush.reflections.stub(:__dispatch)
12
+ Rpush.reflection_stack[0].stub(:__dispatch)
13
13
  Rpush.stub(logger: logger)
14
14
  end
15
15
 
16
16
  it 'dispatches the given reflection' do
17
- Rpush.reflections.should_receive(:__dispatch).with(:error)
17
+ Rpush.reflection_stack[0].should_receive(:__dispatch).with(:error)
18
18
  test_reflectable.reflect(:error)
19
19
  end
20
20
 
21
- it 'logs errors raise by the reflection' do
21
+ it 'logs errors raised by the reflection' do
22
22
  error = StandardError.new
23
- Rpush.reflections.stub(:__dispatch).and_raise(error)
23
+ Rpush.reflection_stack[0].stub(:__dispatch).and_raise(error)
24
24
  Rpush.logger.should_receive(:error).with(error)
25
25
  test_reflectable.reflect(:error)
26
26
  end
@@ -6,25 +6,21 @@
6
6
  Rpush.reflect { did_yield = true }
7
7
  did_yield.should be_true
8
8
  end
9
-
10
- it 'returns all reflections' do
11
- Rpush.reflections.should be_kind_of(Rpush::Reflections)
12
- end
13
9
  end
14
10
 
15
- describe Rpush::Reflections do
11
+ describe Rpush::ReflectionCollection do
16
12
  it 'dispatches the given reflection' do
17
13
  did_yield = false
18
14
  Rpush.reflect do |on|
19
15
  on.error { did_yield = true }
20
16
  end
21
- Rpush.reflections.__dispatch(:error)
17
+ Rpush.reflection_stack[0].__dispatch(:error)
22
18
  did_yield.should be_true
23
19
  end
24
20
 
25
21
  it 'raises an error when trying to dispatch and unknown reflection' do
26
22
  expect do
27
- Rpush.reflections.__dispatch(:unknown)
28
- end.to raise_error(Rpush::Reflections::NoSuchReflectionError)
23
+ Rpush.reflection_stack[0].__dispatch(:unknown)
24
+ end.to raise_error(Rpush::ReflectionCollection::NoSuchReflectionError)
29
25
  end
30
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Leitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: term-ansicolor
84
+ name: ansi
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -189,7 +189,6 @@ files:
189
189
  - lib/rpush/daemon/loggable.rb
190
190
  - lib/rpush/daemon/proc_title.rb
191
191
  - lib/rpush/daemon/queue_payload.rb
192
- - lib/rpush/daemon/reflectable.rb
193
192
  - lib/rpush/daemon/retry_header_parser.rb
194
193
  - lib/rpush/daemon/retryable_error.rb
195
194
  - lib/rpush/daemon/ring_buffer.rb
@@ -209,8 +208,11 @@ files:
209
208
  - lib/rpush/embed.rb
210
209
  - lib/rpush/logger.rb
211
210
  - lib/rpush/multi_json_helper.rb
211
+ - lib/rpush/plugin.rb
212
212
  - lib/rpush/push.rb
213
- - lib/rpush/reflection.rb
213
+ - lib/rpush/reflectable.rb
214
+ - lib/rpush/reflection_collection.rb
215
+ - lib/rpush/reflection_public_methods.rb
214
216
  - lib/rpush/version.rb
215
217
  - lib/tasks/quality.rake
216
218
  - lib/tasks/test.rake
@@ -224,14 +226,11 @@ files:
224
226
  - spec/functional/synchronization_spec.rb
225
227
  - spec/functional/wpns_spec.rb
226
228
  - spec/functional_spec_helper.rb
227
- - spec/integration/rpush_spec.rb
228
- - spec/integration/support/gcm_success_response.json
229
229
  - spec/spec_helper.rb
230
230
  - spec/support/active_record_setup.rb
231
231
  - spec/support/cert_with_password.pem
232
232
  - spec/support/cert_without_password.pem
233
233
  - spec/support/config/database.yml
234
- - spec/support/install.sh
235
234
  - spec/support/simplecov_helper.rb
236
235
  - spec/support/simplecov_quality_formatter.rb
237
236
  - spec/tmp/.gitkeep
@@ -261,7 +260,6 @@ files:
261
260
  - spec/unit/daemon/dispatcher_loop_spec.rb
262
261
  - spec/unit/daemon/feeder_spec.rb
263
262
  - spec/unit/daemon/gcm/delivery_spec.rb
264
- - spec/unit/daemon/reflectable_spec.rb
265
263
  - spec/unit/daemon/retryable_error_spec.rb
266
264
  - spec/unit/daemon/service_config_methods_spec.rb
267
265
  - spec/unit/daemon/signal_handler_spec.rb
@@ -275,8 +273,10 @@ files:
275
273
  - spec/unit/embed_spec.rb
276
274
  - spec/unit/logger_spec.rb
277
275
  - spec/unit/notification_shared.rb
276
+ - spec/unit/plugin_spec.rb
278
277
  - spec/unit/push_spec.rb
279
- - spec/unit/reflection_spec.rb
278
+ - spec/unit/reflectable_spec.rb
279
+ - spec/unit/reflection_collection_spec.rb
280
280
  - spec/unit/rpush_spec.rb
281
281
  - spec/unit_spec_helper.rb
282
282
  homepage: https://github.com/rpush/rpush
@@ -294,12 +294,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
294
294
  version: '0'
295
295
  required_rubygems_version: !ruby/object:Gem::Requirement
296
296
  requirements:
297
- - - ">="
297
+ - - ">"
298
298
  - !ruby/object:Gem::Version
299
- version: '0'
299
+ version: 1.3.1
300
300
  requirements: []
301
301
  rubyforge_project:
302
- rubygems_version: 2.4.2
302
+ rubygems_version: 2.4.5
303
303
  signing_key:
304
304
  specification_version: 4
305
305
  summary: The push notification service for Ruby.
@@ -314,14 +314,11 @@ test_files:
314
314
  - spec/functional/synchronization_spec.rb
315
315
  - spec/functional/wpns_spec.rb
316
316
  - spec/functional_spec_helper.rb
317
- - spec/integration/rpush_spec.rb
318
- - spec/integration/support/gcm_success_response.json
319
317
  - spec/spec_helper.rb
320
318
  - spec/support/active_record_setup.rb
321
319
  - spec/support/cert_with_password.pem
322
320
  - spec/support/cert_without_password.pem
323
321
  - spec/support/config/database.yml
324
- - spec/support/install.sh
325
322
  - spec/support/simplecov_helper.rb
326
323
  - spec/support/simplecov_quality_formatter.rb
327
324
  - spec/tmp/.gitkeep
@@ -351,7 +348,6 @@ test_files:
351
348
  - spec/unit/daemon/dispatcher_loop_spec.rb
352
349
  - spec/unit/daemon/feeder_spec.rb
353
350
  - spec/unit/daemon/gcm/delivery_spec.rb
354
- - spec/unit/daemon/reflectable_spec.rb
355
351
  - spec/unit/daemon/retryable_error_spec.rb
356
352
  - spec/unit/daemon/service_config_methods_spec.rb
357
353
  - spec/unit/daemon/signal_handler_spec.rb
@@ -365,7 +361,9 @@ test_files:
365
361
  - spec/unit/embed_spec.rb
366
362
  - spec/unit/logger_spec.rb
367
363
  - spec/unit/notification_shared.rb
364
+ - spec/unit/plugin_spec.rb
368
365
  - spec/unit/push_spec.rb
369
- - spec/unit/reflection_spec.rb
366
+ - spec/unit/reflectable_spec.rb
367
+ - spec/unit/reflection_collection_spec.rb
370
368
  - spec/unit/rpush_spec.rb
371
369
  - spec/unit_spec_helper.rb
@@ -1,11 +0,0 @@
1
- module Rpush
2
- module Daemon
3
- module Reflectable
4
- def reflect(name, *args)
5
- Rpush.reflections.__dispatch(name, *args)
6
- rescue StandardError => e
7
- Rpush.logger.error(e)
8
- end
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- # describe "Rpush" do
2
-
3
- # before :all do
4
- # `vagrant up`
5
- # # TODO: Upload current directory.
6
- # # TODO: Use Net::SSH
7
- # `vagrant ssh 'cd rpush; git fetch origin; git reset --hard origin/master; sh tools/run_docker.sh'`
8
- # end
9
-
10
- # it 'can be installed and successfully delivers a notification' do
11
- # # Can now SSH to the Docker instance with; ssh -i docker_key root@localhost -p 2100
12
- # end
13
- # end
@@ -1 +0,0 @@
1
- {"results":[{"message_id": "123"}]}
@@ -1,68 +0,0 @@
1
- set -ev
2
- cp -R /mnt/rpush /rpush
3
- cd /tmp
4
- export HOME=/
5
- export RAILS_NAME=rpush_`date +"%Y%m%d%H%M%S"`
6
- mysqladmin create `echo $RAILS_NAME`_development
7
- gem install --no-ri --no-rdoc rails bundler
8
- rails new $RAILS_NAME -BJTS -d mysql
9
- cd $RAILS_NAME
10
- for gem in sdoc coffee-rails uglifier sass-rails jquery-rails jbuilder turbolinks
11
- do
12
- sed -i.bak -e "s/^[ \t]*gem '$gem'/\# gem '$gem'/g" Gemfile
13
- done
14
-
15
- echo 'gem "rpush", path: "/rpush"' >> Gemfile
16
- bundle
17
- rails g rpush
18
- rake db:migrate
19
-
20
- cat > gcm_server.rb <<EOF
21
- require 'webrick'
22
- server = WEBrick::HTTPServer.new(:Port => 80)
23
- server.mount_proc '/' do |req, res|
24
- res["Content-Type"] = 'application/json'
25
- res.body = File.read('/rpush/spec/integration/support/gcm_success_response.json')
26
- end
27
- server.start
28
- EOF
29
- rails runner gcm_server.rb &
30
-
31
- cat > create_app.rb <<EOF
32
- app = Rpush::Gcm::App.new
33
- app.name = "android_app"
34
- app.auth_key = "123"
35
- app.save!
36
-
37
- n = Rpush::Gcm::Notification.new
38
- n.app = app
39
- n.registration_ids = ["abc"]
40
- n.data = {:message => "hi mom!"}
41
- n.save!
42
- puts n.id
43
- EOF
44
-
45
- export NOTIFICATION_ID=`rails runner create_app.rb`
46
- export RPUSH_GCM_HOST='http://localhost'
47
- rpush development
48
-
49
- cat > check_notification_status.rb <<EOF
50
- n = Rpush::Gcm::Notification.find(ENV["NOTIFICATION_ID"])
51
-
52
- while true do
53
- if n.failed
54
- puts "FAILED"
55
- break
56
- elsif n.delivered
57
- puts "DELIVERED"
58
- break
59
- else
60
- STDOUT.write(".")
61
- STDOUT.flush
62
- end
63
-
64
- sleep 0.2
65
- n.reload
66
- end
67
- EOF
68
- rails runner check_notification_status.rb