mercurius 0.1.2 → 0.1.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: 6ccb885f46ade09933f1d11b586e9dde8a787a98
4
- data.tar.gz: ee229449b16cef9938a8fbe519ed4d6dbb5a0f16
3
+ metadata.gz: 770cfa0ddc12836b9e92eaec376949918e6b3f45
4
+ data.tar.gz: 4f21ff49852f315976929e4909eb0a38e73f66e1
5
5
  SHA512:
6
- metadata.gz: 69b2ec2ff3797d0c122d0a4daff22d07044ebf61fbc63f13d4fd182cf1842a4e03d76b4b85bc6ac6b2e6c3cdd96bb6a6660f74672e9e205935050bcc6497512a
7
- data.tar.gz: d6e7d78b30512d57605fbd1dd9711c020555adcee0ddb070b09898d5affb4b912d9ca6c3501bd603a5754f07e9407cd78a199860da330504c24f3d2a3de2c88b
6
+ metadata.gz: 9445e87cc176641987a28ca5beae772b235a0ea24ce352cac2bdb18a371fab1f95858784f627c1a21658365c4b0fce04d221d503d48c03523cf33b2d87b3a8f1
7
+ data.tar.gz: b7ad5f7db52bf7bda6bc405a5c2334d60bc4d94ff7ef954e1bbf23bc03e857d8f9fc80dd86c6170a56551d6e3b867c014ae07b81814d3fd9d533ad6ab6d3133c
@@ -2,14 +2,18 @@ module GCM
2
2
  class Notification
3
3
  include ActiveModel::Model
4
4
 
5
- attr_accessor :data, :collapse_key, :time_to_live, :delay_while_idle
5
+ def self.special_attrs
6
+ [:collapse_key, :time_to_live, :delay_while_idle, :dry_run]
7
+ end
6
8
 
9
+ attr_accessor :data
10
+ attr_accessor *special_attrs
7
11
  # validate delay_while_idle is true/false
8
12
  # validate ttl is integer in seconds
9
13
 
10
14
  def initialize(attributes = {})
11
15
  @attributes = attributes
12
- super data: @attributes.except(:collapse_key, :time_to_live, :delay_while_idle)
16
+ super @attributes.slice(*self.class.special_attrs).merge(data: @attributes.except(*self.class.special_attrs))
13
17
  end
14
18
 
15
19
  def to_h
@@ -17,7 +21,8 @@ module GCM
17
21
  data: data,
18
22
  collapse_key: collapse_key,
19
23
  time_to_live: time_to_live,
20
- delay_while_idle: delay_while_idle
24
+ delay_while_idle: delay_while_idle,
25
+ dry_run: dry_run
21
26
  }
22
27
 
23
28
  hash.reject { |k, v| v.nil? }
@@ -31,5 +31,19 @@ module GCM
31
31
  def failed?
32
32
  !success?
33
33
  end
34
+
35
+ def has_canonical_ids?
36
+ (response_body.canonical_ids || 0) > 0
37
+ end
38
+
39
+ def canonical_ids
40
+ response_body.results.map do |result|
41
+ result["registration_id"]
42
+ end
43
+ end
44
+
45
+ def response_body
46
+ @response_body ||= OpenStruct.new JSON.parse(response.body)
47
+ end
34
48
  end
35
49
  end
@@ -23,5 +23,8 @@ module GCM
23
23
  @_failed_device_tokens ||= failed_responses.flat_map { |response| response.device_tokens }
24
24
  end
25
25
 
26
+ def has_canonical_ids?
27
+ responses.map{ |response| response.has_canonical_ids? }.reduce{ |carry, val| carry || val }
28
+ end
26
29
  end
27
30
  end
@@ -23,6 +23,10 @@ module Mercurius
23
23
  []
24
24
  end
25
25
 
26
+ def has_canonical_ids?
27
+ false
28
+ end
29
+
26
30
  end
27
31
  end
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -0,0 +1,17 @@
1
+ describe GCM::Notification do
2
+ describe 'with attributes' do
3
+ it 'should extract special attributes from the hash and assign them' do
4
+ notification = GCM::Notification.new({ collapse_key: 'some_key', time_to_live: 123, delay_while_idle: true, dry_run: true })
5
+ expect(notification.collapse_key).to eq 'some_key'
6
+ expect(notification.time_to_live).to eq 123
7
+ expect(notification.delay_while_idle).to eq true
8
+ expect(notification.dry_run).to eq true
9
+ end
10
+
11
+ it 'should move other attributes to data' do
12
+ notification = GCM::Notification.new({ message: 'hello', dry_run: true})
13
+ expect(notification.dry_run).to eq true
14
+ expect(notification.data).to eq({ message: 'hello' })
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ describe GCM::Response do
2
+ subject { GCM::Response.new nil, nil }
3
+
4
+ it 'has_canonical_ids? should return true if the response body has canonical ids' do
5
+ allow(subject).to receive(:response_body) { OpenStruct.new canonical_ids: 1 }
6
+ expect(subject.has_canonical_ids?).to be_truthy
7
+ end
8
+
9
+ it 'has_canonical_ids? should return false if the body has no canonical ids' do
10
+ allow(subject).to receive(:response_body) { OpenStruct.new success: 1 }
11
+ expect(subject.has_canonical_ids?).to be_falsy
12
+ end
13
+
14
+ it 'canonical_ids should return an array of registration ids' do
15
+ allow(subject).to receive(:response_body) { OpenStruct.new results: [{'registration_id' => '1234'}, {'registration_id' => '5678'}, {}] }
16
+ expect(subject.canonical_ids).to eq ['1234', '5678', nil]
17
+ end
18
+
19
+ it 'response_body should return an openstruct of the response.body' do
20
+ allow(subject).to receive(:response) { OpenStruct.new body: { one: 'two' }.to_json }
21
+ result = subject.response_body
22
+ expect(result).to be_a OpenStruct
23
+ expect(result.to_h).to eq({one: 'two'})
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ describe GCM::Result do
2
+ subject { GCM::Result.new nil }
3
+
4
+ it 'has_canonical_ids? should return true if any responses have them' do
5
+ allow(subject).to receive(:responses) { [instance_double(GCM::Response, has_canonical_ids?: true), instance_double(GCM::Response, has_canonical_ids?: false)] }
6
+ expect(subject.has_canonical_ids?).to be_truthy
7
+ end
8
+
9
+ it 'otherwise, has_canonical_ids should return false' do
10
+ allow(subject).to receive(:responses) { [instance_double(GCM::Response, has_canonical_ids?: false), instance_double(GCM::Response, has_canonical_ids?: false)] }
11
+ expect(subject.has_canonical_ids?).to be_falsy
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercurius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Beck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -165,6 +165,9 @@ files:
165
165
  - spec/lib/apns_notification_spec.rb
166
166
  - spec/lib/apns_service_spec.rb
167
167
  - spec/lib/apns_spec.rb
168
+ - spec/lib/gcm_notification_spec.rb
169
+ - spec/lib/gcm_response_spec.rb
170
+ - spec/lib/gcm_result_spec.rb
168
171
  - spec/lib/gcm_service_spec.rb
169
172
  - spec/lib/testing_spec.rb
170
173
  - spec/spec_helper.rb
@@ -197,6 +200,9 @@ test_files:
197
200
  - spec/lib/apns_notification_spec.rb
198
201
  - spec/lib/apns_service_spec.rb
199
202
  - spec/lib/apns_spec.rb
203
+ - spec/lib/gcm_notification_spec.rb
204
+ - spec/lib/gcm_response_spec.rb
205
+ - spec/lib/gcm_result_spec.rb
200
206
  - spec/lib/gcm_service_spec.rb
201
207
  - spec/lib/testing_spec.rb
202
208
  - spec/spec_helper.rb