mercurius 0.1.7 → 0.1.8
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/response.rb +7 -7
- data/lib/mercurius/gcm/response_collection.rb +14 -8
- data/lib/mercurius/gcm/result_collection.rb +8 -8
- data/lib/mercurius/version.rb +1 -1
- data/spec/lib/gcm_result_collection_spec.rb +17 -0
- data/spec/lib/response_collection_spec.rb +26 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40aedae9f322daa624a3a3ca05cc2e0defd655fe
|
4
|
+
data.tar.gz: f6838c1e98184deae1a5b4a927fe8068cf99a4c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcfbfdb534a87c655ef7590dcf1b5d9d9ae12f6bbe6066fb179a9d45884f9cff0361faa97a6c3013beeb8b9159f6d5aec991ada34005a132bf44d0d1ae45aec6
|
7
|
+
data.tar.gz: d5339b66a5c9aca4e8a7d99700b844c4e13f9f90433c759df8a458f7d64e44a8cd300e420b197d00935303f789553a69c1f1880ae0ca5a245dbf82dea66281b4
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module GCM
|
2
2
|
class Response
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :http_response, :tokens
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(http_response, tokens = [])
|
6
|
+
@http_response = http_response
|
7
7
|
@tokens = tokens
|
8
8
|
end
|
9
9
|
|
10
10
|
def status
|
11
|
-
|
11
|
+
http_response.status
|
12
12
|
end
|
13
13
|
|
14
14
|
def success?
|
15
|
-
|
15
|
+
http_response.success?
|
16
16
|
end
|
17
17
|
|
18
18
|
def fail?
|
@@ -43,11 +43,11 @@ module GCM
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def retry_after
|
46
|
-
|
46
|
+
http_response.headers['Retry-After']
|
47
47
|
end
|
48
48
|
|
49
49
|
def to_h
|
50
|
-
JSON.parse
|
50
|
+
JSON.parse http_response.body
|
51
51
|
rescue JSON::ParserError
|
52
52
|
{}
|
53
53
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module GCM
|
2
2
|
class ResponseCollection
|
3
|
+
include Enumerable
|
4
|
+
|
3
5
|
attr_reader :recommendations
|
4
6
|
|
5
7
|
def initialize(notification, responses = [])
|
@@ -7,14 +9,6 @@ module GCM
|
|
7
9
|
@notification = notification
|
8
10
|
end
|
9
11
|
|
10
|
-
def [](index)
|
11
|
-
@responses[index]
|
12
|
-
end
|
13
|
-
|
14
|
-
def <<(response)
|
15
|
-
@responses.concat Array(response).flatten
|
16
|
-
end
|
17
|
-
|
18
12
|
def results
|
19
13
|
out = GCM::ResultCollection.new
|
20
14
|
@responses.map do |response|
|
@@ -24,5 +18,17 @@ module GCM
|
|
24
18
|
end
|
25
19
|
out
|
26
20
|
end
|
21
|
+
|
22
|
+
def [](index)
|
23
|
+
@responses[index]
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(response)
|
27
|
+
@responses.concat Array(response).flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def each(&block)
|
31
|
+
@responses.each &block
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
@@ -6,14 +6,6 @@ module GCM
|
|
6
6
|
@results = results
|
7
7
|
end
|
8
8
|
|
9
|
-
def [](index)
|
10
|
-
@results[index]
|
11
|
-
end
|
12
|
-
|
13
|
-
def each(&block)
|
14
|
-
@results.each &block
|
15
|
-
end
|
16
|
-
|
17
9
|
def succeeded
|
18
10
|
@results.select &:success?
|
19
11
|
end
|
@@ -26,8 +18,16 @@ module GCM
|
|
26
18
|
@results.select &:has_canonical_id?
|
27
19
|
end
|
28
20
|
|
21
|
+
def [](index)
|
22
|
+
@results[index]
|
23
|
+
end
|
24
|
+
|
29
25
|
def <<(result)
|
30
26
|
@results << result
|
31
27
|
end
|
28
|
+
|
29
|
+
def each(&block)
|
30
|
+
@results.each &block
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/mercurius/version.rb
CHANGED
@@ -7,6 +7,23 @@ describe GCM::ResultCollection do
|
|
7
7
|
]
|
8
8
|
end
|
9
9
|
|
10
|
+
describe 'Enumerable' do
|
11
|
+
it '#[] returns the result at the given index' do
|
12
|
+
expect(subject[0].token).to eq 'token123'
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#each iterates through the results' do
|
16
|
+
subject.each.with_index do |result, i|
|
17
|
+
expect(result).to eq subject[i]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it '#<< adds a new result to the collection' do
|
22
|
+
subject << GCM::Result.new({ message_id: '3' }, 'token789')
|
23
|
+
expect(subject.to_a.last.token).to eq 'token789'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
10
27
|
describe '#succeeded' do
|
11
28
|
it 'returns only the successful results' do
|
12
29
|
expect(subject.succeeded.count).to eq 2
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe GCM::ResponseCollection do
|
2
|
+
subject do
|
3
|
+
GCM::ResponseCollection.new nil, [
|
4
|
+
GCM::Response.new(Mercurius::FakeResponse.new(body: '{}', status: 200)),
|
5
|
+
GCM::Response.new(Mercurius::FakeResponse.new(body: '{}', status: 201)),
|
6
|
+
GCM::Response.new(Mercurius::FakeResponse.new(body: '{}', status: 204))
|
7
|
+
]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'Enumerable' do
|
11
|
+
it '#[] returns the response at the given index' do
|
12
|
+
expect(subject[0].status).to eq 200
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#each iterates through the responses' do
|
16
|
+
subject.each.with_index do |response, i|
|
17
|
+
expect(response).to eq subject[i]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it '#<< adds a new response to the collection' do
|
22
|
+
subject << GCM::Response.new(Mercurius::FakeResponse.new(body: '{}', status: 400))
|
23
|
+
expect(subject.to_a.last.status).to eq 400
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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.8
|
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-09-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- spec/lib/gcm_result_collection_spec.rb
|
176
176
|
- spec/lib/gcm_result_spec.rb
|
177
177
|
- spec/lib/gcm_service_spec.rb
|
178
|
+
- spec/lib/response_collection_spec.rb
|
178
179
|
- spec/lib/testing_spec.rb
|
179
180
|
- spec/spec_helper.rb
|
180
181
|
- spec/support/apns.pem
|
@@ -211,6 +212,7 @@ test_files:
|
|
211
212
|
- spec/lib/gcm_result_collection_spec.rb
|
212
213
|
- spec/lib/gcm_result_spec.rb
|
213
214
|
- spec/lib/gcm_service_spec.rb
|
215
|
+
- spec/lib/response_collection_spec.rb
|
214
216
|
- spec/lib/testing_spec.rb
|
215
217
|
- spec/spec_helper.rb
|
216
218
|
- spec/support/apns.pem
|