apns_dispatch 1.0.2 → 1.0.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: 8b358e96c901dfd0757116b623f643fa2a574a9e
4
- data.tar.gz: 8f82788c67d2506878938736872e1932d216c9ef
3
+ metadata.gz: 721ee8dbbf30859aa73eea70d7540addf381e30c
4
+ data.tar.gz: 2d94582ec84875a3dc32b8f06dc8c715cfe490e8
5
5
  SHA512:
6
- metadata.gz: 116df1b07cb7a127f40ca8753691e4cf62dd9b27fccf4ef95baa3e93bb06c37d7d99b85c709ee52bf7d20c88da42e6f44b94ec37ad3a99e083aa55bae58dd1c9
7
- data.tar.gz: 8623b2e40f3ec19a4339447d3c4be20ede2dec83f46f703952f33878079c4cb147d192c4c9e4b4bf899a965586057a4832464f7fff64d76412ba203503315a76
6
+ metadata.gz: f534f8e61319c70dfe4a2b1c5ea37b39e99e9ecefc45e458d0f4971ba2e5149ea2b2963f38492ea092701259ed3d62b158e29c6e5160b0181691218c3aef9a5b
7
+ data.tar.gz: 46acc5e9615e592452fa5fef37084b68c74a6db31b1d03100ea12a6dafd994e765838281d4b76f54a8e189fb00da911f50f07fcab9d6b1516c666ec6182c7aa1
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apns_dispatch (1.0.2)
4
+ apns_dispatch (1.0.3)
5
5
  json (~> 1.8.1)
6
- retryable (~> 1.3.5)
6
+ retryable (~> 2.0.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  diff-lcs (1.2.5)
12
- json (1.8.1)
13
- rake (10.1.1)
14
- retryable (1.3.5)
12
+ json (1.8.3)
13
+ rake (10.4.2)
14
+ retryable (2.0.2)
15
15
  rspec (2.13.0)
16
16
  rspec-core (~> 2.13.0)
17
17
  rspec-expectations (~> 2.13.0)
@@ -28,3 +28,6 @@ DEPENDENCIES
28
28
  apns_dispatch!
29
29
  rake
30
30
  rspec (~> 2.13.0)
31
+
32
+ BUNDLED WITH
33
+ 1.10.6
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
 
18
18
  gem.add_dependency 'json', '~> 1.8.1'
19
- gem.add_dependency 'retryable', '~> 1.3.5'
19
+ gem.add_dependency 'retryable', '~> 2.0.2'
20
20
 
21
21
  gem.add_development_dependency 'rake'
22
22
  gem.add_development_dependency 'rspec', '~> 2.13.0'
@@ -2,6 +2,9 @@ module ApnsDispatch
2
2
  # Creates a packaged notification for the APNs. Based on code from https://github.com/jpoz/APNS.
3
3
 
4
4
  class ApnNotification
5
+ # Constants
6
+ COMMAND = 0
7
+
5
8
  def initialize(connection, token, message, options = {})
6
9
  @connection = connection
7
10
  @token = token
@@ -16,15 +19,11 @@ module ApnsDispatch
16
19
  private
17
20
 
18
21
  def binary_token
19
- [@token].pack 'H*'
20
- end
21
-
22
- def command
23
- 0
22
+ [@token].pack 'H*'.freeze
24
23
  end
25
24
 
26
25
  def default_aps_message
27
- { alert: @message, sound: 'default' }
26
+ { alert: @message, sound: 'default'.freeze }
28
27
  end
29
28
 
30
29
  def message_information
@@ -34,7 +33,8 @@ module ApnsDispatch
34
33
  end
35
34
 
36
35
  def notification_packet
37
- [command, binary_token.bytesize, binary_token, payload.bytesize, payload].pack 'cna*na*'
36
+ [COMMAND, binary_token.bytesize, binary_token, payload.bytesize, payload].
37
+ pack 'cna*na*'.freeze
38
38
  end
39
39
 
40
40
  def payload
@@ -12,6 +12,7 @@ module ApnsDispatch
12
12
  GATEWAY_PORT = 2195
13
13
  PRODUCTION_FEEDBACK_HOST = 'feedback.push.apple.com'
14
14
  PRODUCTION_GATEWAY_HOST = 'gateway.push.apple.com'
15
+ RETRYABLE_ERRORS = [Errno::EPIPE, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError]
15
16
  SANDBOX_FEEDBACK_HOST = 'feedback.sandbox.push.apple.com'
16
17
  SANDBOX_GATEWAY_HOST = 'gateway.sandbox.push.apple.com'
17
18
 
@@ -39,6 +40,7 @@ module ApnsDispatch
39
40
 
40
41
  @certificate = certificate
41
42
  @options = options
43
+ @mutex = Mutex.new
42
44
  end
43
45
 
44
46
  def read(length)
@@ -78,17 +80,18 @@ module ApnsDispatch
78
80
  connect!
79
81
  end
80
82
 
81
- def retryable_errors
82
- [Errno::EPIPE, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError]
83
+ def retryable(&block)
84
+ options = { exception_cb: lambda { |e| reconnect! }, on: RETRYABLE_ERRORS, sleep: 0, tries: 2 }
85
+ Retryable.retryable(options) { yield }
83
86
  end
84
87
 
85
88
  def with_connection(&block)
86
- unless connected?
87
- connect!
88
- end
89
+ @mutex.synchronize do
90
+ unless connected?
91
+ connect!
92
+ end
89
93
 
90
- retryable exception_cb: lambda { |e| reconnect! }, on: retryable_errors, sleep: 0, tries: 2 do
91
- yield
94
+ retryable { yield }
92
95
  end
93
96
  end
94
97
  end
@@ -1,3 +1,3 @@
1
1
  module ApnsDispatch
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -8,7 +8,7 @@ describe ApnsDispatch::ApnNotification do
8
8
  @connection = stub
9
9
  @apn_notificiation = ApnsDispatch::ApnNotification.new(@connection, token, message, options)
10
10
 
11
- expected_message = { aps: { alert: message, sound: 'default', badge: 1}, order_id: 1}
11
+ expected_message = { aps: { alert: message, sound: 'default', badge: 1 }, order_id: 1 }
12
12
  payload = expected_message.to_json
13
13
  @packet = [0, 32, [token].pack('H*'), payload.bytesize, payload].pack('cna*na*')
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apns_dispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Costa Walcott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.5
33
+ version: 2.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.5
40
+ version: 2.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.2.1
115
+ rubygems_version: 2.4.8
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: A simple Ruby framework for communicating with the APNs