mercurius 0.0.2 → 0.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 +4 -4
- data/.rspec +2 -1
- data/lib/mercurius/apns/connection.rb +9 -6
- data/lib/mercurius/apns/service.rb +1 -1
- data/lib/mercurius/errors/too_many_retries_error.rb +3 -3
- data/lib/mercurius/testing/service.rb +29 -0
- data/lib/mercurius/testing.rb +4 -0
- data/lib/mercurius/version.rb +1 -1
- data/mercurius.gemspec +1 -0
- data/spec/lib/apns_service_spec.rb +7 -7
- data/spec/lib/testing_spec.rb +37 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd30d51ece41def120dc1676a015a2b8a66e0bf0
|
4
|
+
data.tar.gz: ee291d676c6797d48753ce2638f35be20f3560b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f549a2dd708bb10c62dd415d38c66956d06f58b2ce8962ece93876e9c28deb2cbaf16991b48a420686cee92cb0199f84a0fc88e9635bf932f43e393329bbdfd1
|
7
|
+
data.tar.gz: a51150db3b488ea1da40619e54830b84504334684fcd42a40b646ef2e40c0e0f747fdf7dd55cacb86134e69139071deec3741d811be9eff81a85b25f319bea5f
|
data/.rspec
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
--
|
1
|
+
--color
|
2
|
+
--require spec_helper
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module APNS
|
2
2
|
class Connection
|
3
|
-
attr_reader :host, :port, :
|
3
|
+
attr_reader :host, :port, :pem
|
4
4
|
|
5
5
|
def initialize(host, port, pem)
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@host = host
|
7
|
+
@port = port
|
8
|
+
@pem = pem
|
8
9
|
end
|
9
10
|
|
10
11
|
def open
|
12
|
+
@socket ||= TCPSocket.new host, port
|
13
|
+
@ssl ||= OpenSSL::SSL::SSLSocket.new @socket, ssl_context_for_pem(pem)
|
11
14
|
@ssl.connect
|
12
15
|
end
|
13
16
|
|
14
17
|
def close
|
15
|
-
@ssl.close
|
16
|
-
@socket.close
|
18
|
+
@ssl.close if @ssl
|
19
|
+
@socket.close if @socket
|
17
20
|
end
|
18
21
|
|
19
22
|
def closed?
|
20
|
-
@ssl.closed?
|
23
|
+
(@ssl.nil? || @ssl.closed?) || (@socket.nil? || @socket.closed?)
|
21
24
|
end
|
22
25
|
|
23
26
|
def write(data)
|
@@ -45,7 +45,7 @@ module APNS
|
|
45
45
|
connection.open if connection.closed?
|
46
46
|
yield connection
|
47
47
|
rescue StandardError, Errno::EPIPE => e
|
48
|
-
raise TooManyRetriesError.new if too_many_retries?
|
48
|
+
raise TooManyRetriesError.new(e) if too_many_retries?
|
49
49
|
connection.close
|
50
50
|
@attempts += 1
|
51
51
|
retry
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Mercurius
|
2
|
+
module Testing
|
3
|
+
module Service
|
4
|
+
|
5
|
+
class Delivery < Struct.new(:notification, :device_tokens)
|
6
|
+
end
|
7
|
+
|
8
|
+
def deliver(notification, *device_tokens)
|
9
|
+
@deliveries ||= []
|
10
|
+
@deliveries << Delivery.new(notification, Array(device_tokens).flatten)
|
11
|
+
end
|
12
|
+
|
13
|
+
def deliveries
|
14
|
+
@deliveries
|
15
|
+
end
|
16
|
+
|
17
|
+
def notifications_to(device_token)
|
18
|
+
deliveries_to(device_token).map(&:notification)
|
19
|
+
end
|
20
|
+
|
21
|
+
def deliveries_to(device_token)
|
22
|
+
deliveries.select do |delivery|
|
23
|
+
delivery.device_tokens.include? device_token
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/mercurius/version.rb
CHANGED
data/mercurius.gemspec
CHANGED
@@ -57,14 +57,14 @@ describe APNS::Service do
|
|
57
57
|
service.deliver APNS::Notification.new(alert: 'Hey2'), 'token123'
|
58
58
|
end
|
59
59
|
end
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
62
|
+
describe 'retries' do
|
63
|
+
it 'tries 3 times before giving up' do
|
64
|
+
allow(service.connection).to receive(:open) { raise StandardError }
|
65
|
+
expect { service.deliver APNS::Notification.new(alert: 'Hey1'), 'token123' }.to raise_exception(TooManyRetriesError)
|
66
|
+
expect(service.attempts).to eq 3
|
67
67
|
end
|
68
|
-
|
69
68
|
end
|
69
|
+
|
70
70
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../../../lib/mercurius/testing/service', __FILE__)
|
2
|
+
|
3
|
+
describe 'Test mode' do
|
4
|
+
|
5
|
+
class GCM::MockService < GCM::Service
|
6
|
+
include Mercurius::Testing::Service
|
7
|
+
end
|
8
|
+
|
9
|
+
class APNS::MockService < APNS::Service
|
10
|
+
include Mercurius::Testing::Service
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'GCM' do
|
14
|
+
let(:service) { GCM::MockService.new }
|
15
|
+
let(:message) { GCM::Notification.new(alert: 'Hey') }
|
16
|
+
|
17
|
+
it 'returns the deliveries sent to GCM' do
|
18
|
+
service.deliver message, 'token123'
|
19
|
+
delivery = service.deliveries[0]
|
20
|
+
expect(delivery.device_tokens).to include 'token123'
|
21
|
+
expect(delivery.notification.data).to eq Hash[alert: 'Hey']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'APNS' do
|
26
|
+
let(:service) { APNS::MockService.new }
|
27
|
+
let(:message) { APNS::Notification.new(alert: 'Hey') }
|
28
|
+
|
29
|
+
it 'returns the deliveries sent to APNS' do
|
30
|
+
service.deliver message, 'token123'
|
31
|
+
delivery = service.deliveries[0]
|
32
|
+
expect(delivery.device_tokens).to include 'token123'
|
33
|
+
expect(delivery.notification.alert).to eq 'Hey'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercurius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Beck
|
@@ -154,11 +154,14 @@ files:
|
|
154
154
|
- lib/mercurius/gcm/response.rb
|
155
155
|
- lib/mercurius/gcm/result.rb
|
156
156
|
- lib/mercurius/gcm/service.rb
|
157
|
+
- lib/mercurius/testing.rb
|
158
|
+
- lib/mercurius/testing/service.rb
|
157
159
|
- lib/mercurius/version.rb
|
158
160
|
- mercurius.gemspec
|
159
161
|
- spec/lib/apns_service_spec.rb
|
160
162
|
- spec/lib/gcm_service_spec.rb
|
161
163
|
- spec/lib/notification_spec.rb
|
164
|
+
- spec/lib/testing_spec.rb
|
162
165
|
- spec/spec_helper.rb
|
163
166
|
- spec/support/apns.pem
|
164
167
|
- spec/support/fake_socket.rb
|
@@ -171,9 +174,9 @@ require_paths:
|
|
171
174
|
- lib
|
172
175
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
176
|
requirements:
|
174
|
-
- - "
|
177
|
+
- - "~>"
|
175
178
|
- !ruby/object:Gem::Version
|
176
|
-
version: '0'
|
179
|
+
version: '2.0'
|
177
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
181
|
requirements:
|
179
182
|
- - ">="
|
@@ -189,6 +192,7 @@ test_files:
|
|
189
192
|
- spec/lib/apns_service_spec.rb
|
190
193
|
- spec/lib/gcm_service_spec.rb
|
191
194
|
- spec/lib/notification_spec.rb
|
195
|
+
- spec/lib/testing_spec.rb
|
192
196
|
- spec/spec_helper.rb
|
193
197
|
- spec/support/apns.pem
|
194
198
|
- spec/support/fake_socket.rb
|