mercurius 0.1.2 → 0.1.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/lib/mercurius/gcm/notification.rb +8 -3
- data/lib/mercurius/gcm/response.rb +14 -0
- data/lib/mercurius/gcm/result.rb +3 -0
- data/lib/mercurius/testing/result.rb +4 -0
- data/lib/mercurius/version.rb +1 -1
- data/spec/lib/gcm_notification_spec.rb +17 -0
- data/spec/lib/gcm_response_spec.rb +25 -0
- data/spec/lib/gcm_result_spec.rb +13 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 770cfa0ddc12836b9e92eaec376949918e6b3f45
|
4
|
+
data.tar.gz: 4f21ff49852f315976929e4909eb0a38e73f66e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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(
|
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
|
data/lib/mercurius/gcm/result.rb
CHANGED
data/lib/mercurius/version.rb
CHANGED
@@ -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.
|
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-
|
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
|