mercurius 0.1.8 → 0.1.9

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: 40aedae9f322daa624a3a3ca05cc2e0defd655fe
4
- data.tar.gz: f6838c1e98184deae1a5b4a927fe8068cf99a4c6
3
+ metadata.gz: c407384556945caff8534e28bb17bc33eeb1e804
4
+ data.tar.gz: fb500925edc12008a2cf11653699083f37995d18
5
5
  SHA512:
6
- metadata.gz: fcfbfdb534a87c655ef7590dcf1b5d9d9ae12f6bbe6066fb179a9d45884f9cff0361faa97a6c3013beeb8b9159f6d5aec991ada34005a132bf44d0d1ae45aec6
7
- data.tar.gz: d5339b66a5c9aca4e8a7d99700b844c4e13f9f90433c759df8a458f7d64e44a8cd300e420b197d00935303f789553a69c1f1880ae0ca5a245dbf82dea66281b4
6
+ metadata.gz: 060ef7919702f1ca15acbb7f501fcaee491da68f5d5a416ecc49e57c84eef62c07abeff7afebacd9d1479ed56e74d270261789622b7cc30ec9f6d36c4c045153
7
+ data.tar.gz: dd66a90ef1b5a22689bebf352700b4303bbe24993c24119df9b3782af55f3a0acfba3d23e3d5832054237159fd854f2928a9e6b636b019c2e32df4d9d4b7c91b
@@ -10,7 +10,7 @@ module GCM
10
10
  'success' => tokens.size,
11
11
  'failure' => 0,
12
12
  'canonical_ids' => 0,
13
- 'results' => valid_token_json(tokens)
13
+ 'results' => tokens.map { |token| valid_token_json(token) }
14
14
  }.to_json
15
15
 
16
16
  Mercurius::FakeResponse.new body: json, status: 200
@@ -1,15 +1,11 @@
1
1
  module GCM
2
2
  module TokenSerializer
3
- def valid_token_json(tokens)
4
- tokens.map do |token|
5
- { 'message_id' => SecureRandom.hex }
6
- end
3
+ def valid_token_json(token)
4
+ { 'message_id' => SecureRandom.hex }
7
5
  end
8
6
 
9
- def invalid_token_json(tokens, error)
10
- tokens.map do |token|
11
- { 'error' => error }
12
- end
7
+ def invalid_token_json(token, error)
8
+ { 'error' => error }
13
9
  end
14
10
 
15
11
  def canonical_token_json(tokens, canonical_ids_map)
@@ -7,19 +7,40 @@ module GCM
7
7
  end
8
8
 
9
9
  def write(json)
10
- invalid, valid = json[:registration_ids].partition do |token|
11
- @invalid_tokens.include? token
12
- end
10
+ tokens = json[:registration_ids]
13
11
 
14
12
  json = {
15
13
  'multicast_id' => '123',
16
- 'success' => valid.size,
17
- 'failure' => invalid.size,
14
+ 'success' => valid_tokens_count(tokens),
15
+ 'failure' => invalid_tokens_count(tokens),
18
16
  'canonical_ids' => 0,
19
- 'results' => valid_token_json(valid).concat(invalid_token_json(invalid, 'NotRegistered'))
17
+ 'results' => tokens.map do |token|
18
+ if valid? token
19
+ valid_token_json token
20
+ else
21
+ invalid_token_json token, 'NotRegistered'
22
+ end
23
+ end
20
24
  }.to_json
21
25
 
22
26
  Mercurius::FakeResponse.new body: json, status: 200
23
27
  end
28
+
29
+ private
30
+ def valid?(token)
31
+ !invalid? token
32
+ end
33
+
34
+ def invalid?(token)
35
+ @invalid_tokens.include?(token)
36
+ end
37
+
38
+ def valid_tokens_count(tokens)
39
+ tokens.count { |token| valid? token }
40
+ end
41
+
42
+ def invalid_tokens_count(tokens)
43
+ tokens.count { |token| invalid? token }
44
+ end
24
45
  end
25
46
  end
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -20,7 +20,7 @@ describe 'Test mode' do
20
20
  end
21
21
 
22
22
  it 'Returns invalid device errors for the tokens provided' do
23
- responses = service.deliver message, 'token123', 'token456'
23
+ responses = service.deliver message, 'token456', 'token123'
24
24
  expect(responses.results.failed.size).to eq 1
25
25
  expect(responses.results.failed[0].token).to eq 'token456'
26
26
  expect(responses.results.failed[0].error).to eq 'NotRegistered'
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.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Beck