mercurius 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bba600c5ea9ccfe58f1be1c8a0190f76ed156876
4
- data.tar.gz: 878a4fbc8539723e11c8b489a6335fa1e0839e88
3
+ metadata.gz: fd30d51ece41def120dc1676a015a2b8a66e0bf0
4
+ data.tar.gz: ee291d676c6797d48753ce2638f35be20f3560b7
5
5
  SHA512:
6
- metadata.gz: a80bcb308c866c6d4b98beb7ea1ec19e7407c306f6ec6fa322dd40388973473324363dbf6d26432ff8aeea0f57fb492086c4b6e87d2ed50be1e8ba0982b09502
7
- data.tar.gz: f63ae742964e49c26bb46ada8088dc77cdb94539663ecef72ffa63fcb0232a1945caed3ce11eedb63b516db770ff85de4d63ff865fb8a8995fa14d1f4dc2161d
6
+ metadata.gz: f549a2dd708bb10c62dd415d38c66956d06f58b2ce8962ece93876e9c28deb2cbaf16991b48a420686cee92cb0199f84a0fc88e9635bf932f43e393329bbdfd1
7
+ data.tar.gz: a51150db3b488ea1da40619e54830b84504334684fcd42a40b646ef2e40c0e0f747fdf7dd55cacb86134e69139071deec3741d811be9eff81a85b25f319bea5f
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- --require spec_helper
1
+ --color
2
+ --require spec_helper
@@ -1,23 +1,26 @@
1
1
  module APNS
2
2
  class Connection
3
- attr_reader :host, :port, :ssl
3
+ attr_reader :host, :port, :pem
4
4
 
5
5
  def initialize(host, port, pem)
6
- @socket = TCPSocket.new host, port
7
- @ssl = OpenSSL::SSL::SSLSocket.new @socket, ssl_context_for_pem(pem)
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? && @socket.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
@@ -1,7 +1,7 @@
1
1
  class TooManyRetriesError < StandardError
2
2
 
3
- def initialize
4
- super "APNS Service has reached it's maximum number of retries"
3
+ def initialize(e)
4
+ super "APNS Service has reached it's maximum number of retries. Error: #{e.message}"
5
5
  end
6
6
 
7
- end
7
+ end
@@ -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
@@ -0,0 +1,4 @@
1
+ require File.expand_path('testing/service', __FILE__)
2
+
3
+ APNS::Service.send :prepend, TestService
4
+ GCM::Service.send :prepend, TestService
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/mercurius.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
 
23
23
  s.require_paths = ["lib"]
24
+ s.required_ruby_version = '~> 2.0'
24
25
 
25
26
  s.add_dependency 'json'
26
27
  s.add_dependency 'faraday'
@@ -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
- describe 'retries' do
62
- it 'tries 3 times before giving up' do
63
- allow(service.connection).to receive(:open) { raise StandardError }
64
- expect { service.deliver APNS::Notification.new(alert: 'Hey1'), 'token123' }.to raise_exception(TooManyRetriesError)
65
- expect(service.attempts).to eq 3
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.2
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