pushr-apns 1.0.0.pre.2 → 1.0.0.pre.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5181efd03d6487fde7a093fa325893e2ea32a540
4
- data.tar.gz: 6de48a3c06fa85bc2528929b68cf8da9edb53a13
3
+ metadata.gz: efc2bbab50485a9c869eedbe32b47a5493780034
4
+ data.tar.gz: 5f287d84ca34d2ccaf2c06e234e6955d9d8845d2
5
5
  SHA512:
6
- metadata.gz: 936533c37781f04415a8e4f63e49e79f9aea36f16db3b848df645b29681342e154190145bd79677bd2bee359df817069919da853c889d53a01f79c4eb9caffd8
7
- data.tar.gz: 55296d2a67c8cacd82a38f9841231a73bb5bb06e243b667235b2e81ea935bf55312c7f6029943403295073e840bfb645871dc8af461ea060035f5931bf226ffb
6
+ metadata.gz: f2a3c1e7ae567fe58e1d6941ba81f069ac0d56d2f9c41af18266536b478a35b40fc02ad15a77534aef7fea6aad079807ff272c4b6523d1e09c7c7e30648f05a8
7
+ data.tar.gz: 71d2da4ef4ce5663649523fd0efe35bf22dff0247beef7e30b4ea4f2d189b8a55d16ef0009f4d572d526d3eaacc8172a629090a7daf60ee82f9520c3458608af
@@ -1,3 +1,3 @@
1
1
  module PushrApns
2
- VERSION = '1.0.0.pre.2'
2
+ VERSION = '1.0.0.pre.3'
3
3
  end
@@ -3,11 +3,13 @@ require 'pathname'
3
3
  require 'pushr-apns/version'
4
4
  require 'pushr/configuration'
5
5
  require 'pushr/configuration_apns'
6
+ require 'pushr/configuration_apns_feedback'
6
7
  require 'pushr/message'
7
8
  require 'pushr/message_apns'
8
9
  require 'pushr/feedback'
9
10
  require 'pushr/feedback_apns'
10
11
  require 'pushr/daemon/apns'
12
+ require 'pushr/daemon/apns_feedback'
11
13
  require 'pushr/daemon/apns_support/interruptible_sleep'
12
14
  require 'pushr/daemon/apns_support/disconnection_error'
13
15
  require 'pushr/daemon/apns_support/connection_apns'
@@ -1,10 +1,9 @@
1
1
  module Pushr
2
2
  class ConfigurationApns < Pushr::Configuration
3
3
  attr_accessor :id, :type, :app, :enabled, :connections, :certificate, :certificate_password,
4
- :sandbox, :feedback_poll, :skip_check_for_error
4
+ :sandbox, :skip_check_for_error
5
5
  validates :certificate, presence: true
6
6
  validates :sandbox, inclusion: { in: [true, false] }
7
- validates :feedback_poll, numericality: true, presence: true
8
7
  validates :skip_check_for_error, inclusion: { in: [true, false] }, allow_blank: true
9
8
 
10
9
  def name
@@ -13,8 +12,7 @@ module Pushr
13
12
 
14
13
  def to_json
15
14
  hsh = { type: self.class.to_s, app: app, enabled: enabled, connections: connections, certificate: certificate,
16
- certificate_password: certificate_password, sandbox: sandbox, feedback_poll: feedback_poll,
17
- skip_check_for_error: skip_check_for_error }
15
+ certificate_password: certificate_password, sandbox: sandbox, skip_check_for_error: skip_check_for_error }
18
16
  MultiJson.dump(hsh)
19
17
  end
20
18
  end
@@ -0,0 +1,15 @@
1
+ module Pushr
2
+ class ConfigurationApnsFeedback < Pushr::Configuration
3
+ attr_accessor :id, :type, :app, :enabled, :connections, :feedback_poll
4
+ validates :feedback_poll, numericality: true, presence: true
5
+
6
+ def name
7
+ :apns_feedback
8
+ end
9
+
10
+ def to_json
11
+ hsh = { type: self.class.to_s, app: app, enabled: enabled, connections: connections, feedback_poll: feedback_poll }
12
+ MultiJson.dump(hsh)
13
+ end
14
+ end
15
+ end
@@ -1,29 +1,26 @@
1
1
  module Pushr
2
2
  module Daemon
3
3
  class Apns
4
- attr_accessor :configuration
4
+ attr_accessor :configuration, :handlers
5
5
 
6
6
  def initialize(options)
7
- self.configuration = options
8
-
9
- @feedback_receiver = ApnsSupport::FeedbackReceiver.new(configuration)
10
- start_feedback
11
- end
12
-
13
- def connectiontype
14
- ApnsSupport::ConnectionApns
7
+ @configuration = options
8
+ @handlers = []
15
9
  end
16
10
 
17
- def start_feedback
18
- @feedback_receiver.start
19
- end
11
+ def start
12
+ configuration.connections.times do |i|
13
+ connection = ApnsSupport::ConnectionApns.new(configuration, i + 1)
14
+ connection.connect
20
15
 
21
- def stop_feedback
22
- @feedback_receiver.stop
16
+ handler = MessageHandler.new("pushr:#{configuration.app}:#{configuration.name}", connection, configuration.app, i + 1)
17
+ handler.start
18
+ @handlers << handler
19
+ end
23
20
  end
24
21
 
25
22
  def stop
26
- stop_feedback
23
+ @handlers.map(&:stop)
27
24
  end
28
25
  end
29
26
  end
@@ -0,0 +1,24 @@
1
+ module Pushr
2
+ module Daemon
3
+ class ApnsFeedback
4
+ attr_accessor :configuration, :handlers
5
+
6
+ def initialize(options)
7
+ @configuration = options
8
+ @handlers = []
9
+ end
10
+
11
+ def start
12
+ configuration.connections.times do |i|
13
+ connection = ApnsSupport::FeedbackReceiver.new(configuration, i + 1)
14
+ connection.start
15
+ @handlers << connection
16
+ end
17
+ end
18
+
19
+ def stop
20
+ @handlers.map(&:stop)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -39,6 +39,8 @@ module Pushr
39
39
  def connect
40
40
  @ssl_context = setup_ssl_context
41
41
  @tcp_socket, @ssl_socket = connect_socket
42
+ rescue
43
+ Pushr::Daemon.logger.error("#{@name}] Error connection to server, invalid certificate?")
42
44
  end
43
45
 
44
46
  def close
@@ -93,8 +95,10 @@ module Pushr
93
95
  error = nil
94
96
 
95
97
  if tuple = read(ERROR_TUPLE_BYTES)
96
- cmd, code, notification_id = tuple.unpack('ccN')
98
+ _, code, notification_id = tuple.unpack('ccN')
97
99
 
100
+ # TODO: if error 8, create feedback object to remove
101
+ # Pushr::FeedbackApns.new(app: notification.app, failed_at: Time.now, device: notification.device, follow_up: 'delete').save
98
102
  description = APN_ERRORS[code.to_i] || 'Unknown error. Possible push bug?'
99
103
  error = Pushr::Daemon::DeliveryError.new(code, notification_id, description, 'APNS')
100
104
  else
@@ -5,7 +5,7 @@ module Pushr
5
5
 
6
6
  FEEDBACK_TUPLE_BYTES = 38
7
7
 
8
- def initialize(configuration)
8
+ def initialize(configuration, _)
9
9
  @configuration = configuration
10
10
  @interruptible_sleep = InterruptibleSleep.new
11
11
  end
@@ -14,7 +14,7 @@ module Pushr
14
14
  @thread = Thread.new do
15
15
  loop do
16
16
  break if @stop
17
- check_for_feedback
17
+ check_every_configuration
18
18
  @interruptible_sleep.sleep @configuration.feedback_poll
19
19
  end
20
20
  end
@@ -26,15 +26,24 @@ module Pushr
26
26
  @thread.join if @thread
27
27
  end
28
28
 
29
- def check_for_feedback
29
+ def check_every_configuration
30
+ Pushr::Configuration.all.each do |config|
31
+ if config.enabled == true && config.class == Pushr::ConfigurationApns
32
+ Pushr::Daemon.logger.info("[#{config.app}: Checking for feedback")
33
+ check_for_feedback(config)
34
+ end
35
+ end
36
+ end
37
+
38
+ def check_for_feedback(config)
30
39
  connection = nil
31
40
  begin
32
- connection = ConnectionApns.new(@configuration)
41
+ connection = ConnectionApns.new(config)
33
42
  connection.connect
34
43
 
35
44
  while tuple = connection.read(FEEDBACK_TUPLE_BYTES)
36
45
  timestamp, device = parse_tuple(tuple)
37
- create_feedback(connection, timestamp, device)
46
+ create_feedback(config, connection, timestamp, device)
38
47
  end
39
48
  rescue StandardError => e
40
49
  Pushr::Daemon.logger.error(e)
@@ -50,10 +59,10 @@ module Pushr
50
59
  [Time.at(failed_at).utc, device]
51
60
  end
52
61
 
53
- def create_feedback(connection, failed_at, device)
62
+ def create_feedback(config, connection, failed_at, device)
54
63
  formatted_failed_at = failed_at.strftime('%Y-%m-%d %H:%M:%S UTC')
55
64
  Pushr::Daemon.logger.info("[#{connection.name}: Delivery failed at #{formatted_failed_at} for #{device}")
56
- Pushr::FeedbackApns.new(app: @configuration.app, failed_at: failed_at, device: device, follow_up: 'delete').save
65
+ Pushr::FeedbackApns.new(app: config.app, failed_at: failed_at, device: device, follow_up: 'delete').save
57
66
  end
58
67
  end
59
68
  end
@@ -2,7 +2,7 @@ module Pushr
2
2
  class MessageApns < Pushr::Message
3
3
  POSTFIX = 'apns'
4
4
 
5
- attr_accessor :type, :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device, :content_available, :priority
5
+ attr_accessor :type, :app, :device, :badge, :sound, :expiry, :attributes_for_device, :content_available, :priority
6
6
 
7
7
  validates :badge, numericality: true, allow_nil: true
8
8
  validates :expiry, numericality: true, presence: true
@@ -18,7 +18,7 @@ describe Pushr::ConfigurationApns do
18
18
  describe 'create' do
19
19
  it 'should create a configuration' do
20
20
  config = Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true, certificate: 'test', certificate_password: nil,
21
- sandbox: true, feedback_poll: 100, skip_check_for_error: true)
21
+ sandbox: true, skip_check_for_error: true)
22
22
  expect(config.key).to eql('app_name:apns')
23
23
  end
24
24
  end
@@ -26,7 +26,7 @@ describe Pushr::ConfigurationApns do
26
26
  describe 'save' do
27
27
  let(:config) do
28
28
  Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true, certificate: 'test', certificate_password: nil,
29
- sandbox: true, feedback_poll: 100, skip_check_for_error: true)
29
+ sandbox: true, skip_check_for_error: true)
30
30
  end
31
31
  it 'should save a configuration' do
32
32
  config.save
@@ -25,7 +25,7 @@ describe Pushr::Daemon::ApnsSupport::ConnectionApns do
25
25
 
26
26
  let(:tcpsocket) { double('TCPSocket').as_null_object }
27
27
  let(:sslsocket) { double('SSLSocket').as_null_object }
28
- let(:certificate) { File.read(File.join(File.dirname(__FILE__), '..', '..', '..', 'support', 'cert_without_password.pem')) }
28
+ let(:certificate) { File.read(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'support', 'cert_without_password.pem')) }
29
29
  let(:config) do
30
30
  Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true, certificate: certificate)
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushr-apns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.2
4
+ version: 1.0.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Pesman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-19 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -174,7 +174,9 @@ files:
174
174
  - lib/pushr-apns/version.rb
175
175
  - lib/pushr/apns.rb
176
176
  - lib/pushr/configuration_apns.rb
177
+ - lib/pushr/configuration_apns_feedback.rb
177
178
  - lib/pushr/daemon/apns.rb
179
+ - lib/pushr/daemon/apns_feedback.rb
178
180
  - lib/pushr/daemon/apns_support/connection_apns.rb
179
181
  - lib/pushr/daemon/apns_support/disconnection_error.rb
180
182
  - lib/pushr/daemon/apns_support/feedback_receiver.rb
@@ -183,12 +185,12 @@ files:
183
185
  - lib/pushr/message_apns.rb
184
186
  - README.md
185
187
  - MIT-LICENSE
186
- - spec/lib/pushr/apns_spec.rb
187
- - spec/lib/pushr/apns_support/connection_apns_spec.rb
188
- - spec/lib/pushr/apns_support/disconnection_error_spec.rb
189
- - spec/lib/pushr/apns_support/feedback_receiver_spec.rb
190
- - spec/lib/pushr/apns_support/interruptible_sleep_spec.rb
191
188
  - spec/lib/pushr/configuration_apns_spec.rb
189
+ - spec/lib/pushr/daemon/apns_spec.rb
190
+ - spec/lib/pushr/daemon/apns_support/connection_apns_spec.rb
191
+ - spec/lib/pushr/daemon/apns_support/disconnection_error_spec.rb
192
+ - spec/lib/pushr/daemon/apns_support/feedback_receiver_spec.rb
193
+ - spec/lib/pushr/daemon/apns_support/interruptible_sleep_spec.rb
192
194
  - spec/lib/pushr/feedback_apns_spec.rb
193
195
  - spec/lib/pushr/message_apns_spec.rb
194
196
  - spec/spec_helper.rb
@@ -219,12 +221,12 @@ signing_key:
219
221
  specification_version: 4
220
222
  summary: APNS (iOS/Apple) part of the modular push daemon.
221
223
  test_files:
222
- - spec/lib/pushr/apns_spec.rb
223
- - spec/lib/pushr/apns_support/connection_apns_spec.rb
224
- - spec/lib/pushr/apns_support/disconnection_error_spec.rb
225
- - spec/lib/pushr/apns_support/feedback_receiver_spec.rb
226
- - spec/lib/pushr/apns_support/interruptible_sleep_spec.rb
227
224
  - spec/lib/pushr/configuration_apns_spec.rb
225
+ - spec/lib/pushr/daemon/apns_spec.rb
226
+ - spec/lib/pushr/daemon/apns_support/connection_apns_spec.rb
227
+ - spec/lib/pushr/daemon/apns_support/disconnection_error_spec.rb
228
+ - spec/lib/pushr/daemon/apns_support/feedback_receiver_spec.rb
229
+ - spec/lib/pushr/daemon/apns_support/interruptible_sleep_spec.rb
228
230
  - spec/lib/pushr/feedback_apns_spec.rb
229
231
  - spec/lib/pushr/message_apns_spec.rb
230
232
  - spec/spec_helper.rb