mercurius 0.1.7 → 0.1.8

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: ad8436c06b411a85bb1392ae8829e647150a8813
4
- data.tar.gz: 7b6021819a0c16f5b65c609e391c86eef4b10215
3
+ metadata.gz: 40aedae9f322daa624a3a3ca05cc2e0defd655fe
4
+ data.tar.gz: f6838c1e98184deae1a5b4a927fe8068cf99a4c6
5
5
  SHA512:
6
- metadata.gz: f82468ba84b84c9fce6f0a8dc0b977724eda79378b1c70f1c6511be8f4d16e4baff266979c3a94dd73b08c3b4c04ce979960dae2b4afe26dd790041a7d42197e
7
- data.tar.gz: 4c563b18ed858c1433ae0ff53199597028464d73f40f2b9361c0a9dd36add2fb1fc95055318c240c04809725cc5473f1315a1d1f76609695d954fe7ef178dce2
6
+ metadata.gz: fcfbfdb534a87c655ef7590dcf1b5d9d9ae12f6bbe6066fb179a9d45884f9cff0361faa97a6c3013beeb8b9159f6d5aec991ada34005a132bf44d0d1ae45aec6
7
+ data.tar.gz: d5339b66a5c9aca4e8a7d99700b844c4e13f9f90433c759df8a458f7d64e44a8cd300e420b197d00935303f789553a69c1f1880ae0ca5a245dbf82dea66281b4
@@ -1,18 +1,18 @@
1
1
  module GCM
2
2
  class Response
3
- attr_reader :response, :tokens
3
+ attr_reader :http_response, :tokens
4
4
 
5
- def initialize(response, tokens = [])
6
- @response = response
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
- response.status
11
+ http_response.status
12
12
  end
13
13
 
14
14
  def success?
15
- response.success?
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
- response.headers['Retry-After']
46
+ http_response.headers['Retry-After']
47
47
  end
48
48
 
49
49
  def to_h
50
- JSON.parse response.body
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
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -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.7
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-08 00:00:00.000000000 Z
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