pntfr 0.1.1 → 0.1.2

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: 1f3b8477063d23af20f997756ac2525bd3b32780
4
- data.tar.gz: 5f1680126704e0ebca33794342a03a96a471ab9c
3
+ metadata.gz: 86fc4111228a2ba7ad45eb4a2b1878862e46b2cb
4
+ data.tar.gz: 8381f50b307d91240a4a770353d64d0294bfefd6
5
5
  SHA512:
6
- metadata.gz: 4587cc3c9d9e1fc1707813312c914b10ae80bf849a9e56d3c2f2651fd31e8b2174fa404cfa9fa5b34cbc48b2cd28e2d003eda718f5aaf5c0914a42bd5eddee88
7
- data.tar.gz: 5958abd16c317ca5eaf9b748b4fb8df87c4665208b4a9a9bd3b3422d0b88b2e3601820ca16020315e43e356616505cf4f8546d29efecf08966069d9bae7ce7c2
6
+ metadata.gz: 7fb0d5129066a730bf76e00ecf498eac2b9e8ca4231b155f27188d23d611bc3bd1f4d9dc56c281eca1791c6ba7fdc1b9d423a6fbfd15e7d15da1158ec9c89f0c
7
+ data.tar.gz: b83fc05281fc693de889f072db1b27b1e2f6642805c07a2785f63ed788c675a715b9607b7c823dd5c06ec989de00cfd2ca2996ec882866bf2e3a8c695a66c36f
@@ -10,5 +10,20 @@ module Pntfr
10
10
  return false if string.nil? or string.empty?
11
11
  IOS == string.upcase
12
12
  end
13
+ # All supported platforms
14
+ def self.all
15
+ [ANDROID, IOS]
16
+ end
17
+ # Returns a list of platforms:
18
+ # - if the +platform+ param is present wraps it into an Array.
19
+ # - else returns all supported platforms.
20
+ #
21
+ def self.given_or_default_to_all(platform)
22
+ if platform
23
+ [platform]
24
+ else
25
+ Pntfr::Platforms.all
26
+ end
27
+ end
13
28
  end
14
29
  end
data/lib/pntfr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pntfr
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -8,9 +8,10 @@ module Pntfr
8
8
  module VirtualSession
9
9
  class GcmResponse < BaseResponse
10
10
  def initialize json
11
- @status_code= json[:status_code]
12
- @response= json[:response]
13
- @body= json[:body]
11
+ @raw= json
12
+ @status_code= @raw[:status_code]
13
+ @response= @raw[:response]
14
+ @body= @raw[:body]
14
15
  if success?
15
16
  @parsed_body= JSON.parse(@body)
16
17
  @body_result= @parsed_body['results'].first
@@ -39,6 +40,9 @@ module Pntfr
39
40
  def failure
40
41
  "#{@body}->#{@response}"
41
42
  end
43
+ def to_s
44
+ @raw.to_s
45
+ end
42
46
  end
43
47
  end
44
48
  end
data/lib/pntfr.rb CHANGED
@@ -24,4 +24,7 @@ module Pntfr
24
24
  @gcm= {}
25
25
  end
26
26
  end
27
- end
27
+ end
28
+
29
+ # produce empty configuration
30
+ Pntfr.configure {}
@@ -1,10 +1,6 @@
1
1
  require 'pntfr/device_session'
2
2
  module Pntfr
3
3
  class NotifierTest < Minitest::Test
4
- def initialize method_name
5
- super
6
- Pntfr.configure {}
7
- end
8
4
 
9
5
  def test_android_sessions_should_instantiate_android_virtual_sessions
10
6
  session= DeviceSession.new(Pntfr::Platforms::ANDROID)
@@ -2,10 +2,6 @@ require 'pntfr/device_session'
2
2
  module Pntfr
3
3
  module VirtualSession
4
4
  class AndroidTest < Minitest::Test
5
- def initialize method_name
6
- super
7
- Pntfr.configure {}
8
- end
9
5
 
10
6
  def test_received_content_shoud_be_sent_to_gcm
11
7
  push_id= 'ANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROID'
@@ -2,6 +2,7 @@ require 'pntfr/device_session'
2
2
  module Pntfr
3
3
  module VirtualSession
4
4
  class IosTest < Minitest::Test
5
+
5
6
  def test_received_content_shoud_be_ready_to_be_sent_to_apns
6
7
  push_id= 'IOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSios'
7
8
  session= DeviceSession.new(Pntfr::Platforms::IOS, push_id)
@@ -13,24 +13,26 @@ module Pntfr
13
13
  #
14
14
  # Android response
15
15
  #
16
+ GCM_200_WITH_SUCCESS= {:body=>"{\"multicast_id\":1020305051281243425,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1418221082312345%88882f99f9fd7ecd\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Wed, 10 Dec 2014 14:18:02 GMT"], "expires"=>["Wed, 10 Dec 2014 14:18:02 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
17
+ GCM_200_WITH_INVALID_REGISTRATION= {:body=>"{\"multicast_id\":6867269885611677069,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 21:28:02 GMT"], "expires"=>["Tue, 09 Dec 2014 21:28:02 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
18
+ GCM_200_WITH_MISMATCH_SENDER_ID= {:body=>"{\"multicast_id\":5372261104801760966,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"MismatchSenderId\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 20:41:01 GMT"], "expires"=>["Tue, 09 Dec 2014 20:41:01 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
19
+ GCM_400_RESPONSE= {:body=>"\"registration_ids\" field is not a JSON array\n", :headers=>{"content-type"=>["text/plain; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 21:27:30 GMT"], "expires"=>["Tue, 09 Dec 2014 21:27:30 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>400, :response=>"Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields."}
20
+
16
21
  def test_gcm_200_responses_with_success_should_have_success_and_no_error
17
- json= {:body=>"{\"multicast_id\":1020305051281243425,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1418221082312345%88882f99f9fd7ecd\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Wed, 10 Dec 2014 14:18:02 GMT"], "expires"=>["Wed, 10 Dec 2014 14:18:02 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
18
- rs= VirtualSession::GcmResponse.new(json)
22
+ rs= VirtualSession::GcmResponse.new(GCM_200_WITH_SUCCESS)
19
23
  assert rs.success?
20
24
  refute rs.error?
21
25
  assert_nil rs.error
22
26
  end
23
27
  def test_gcm_200_responses_with_invalid_registration_should_have_failed_and_report_error
24
- json= {:body=>"{\"multicast_id\":6867269885611677069,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 21:28:02 GMT"], "expires"=>["Tue, 09 Dec 2014 21:28:02 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
25
- rs= VirtualSession::GcmResponse.new(json)
28
+ rs= VirtualSession::GcmResponse.new(GCM_200_WITH_INVALID_REGISTRATION)
26
29
  refute rs.failure?
27
30
  refute rs.msg_sent?
28
31
  assert rs.success? and rs.error?
29
32
  assert_equal 'InvalidRegistration', rs.error
30
33
  end
31
34
  def test_gcm_200_responses_with_mismatch_sender_id_should_have_failed_and_report_error
32
- json= {:body=>"{\"multicast_id\":5372261104801760966,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"MismatchSenderId\"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 20:41:01 GMT"], "expires"=>["Tue, 09 Dec 2014 20:41:01 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
33
- rs= VirtualSession::GcmResponse.new(json)
35
+ rs= VirtualSession::GcmResponse.new(GCM_200_WITH_MISMATCH_SENDER_ID)
34
36
  assert rs.success?
35
37
  refute rs.msg_sent?
36
38
  assert rs.error?
@@ -38,12 +40,19 @@ module Pntfr
38
40
  assert_equal 'MismatchSenderId', rs.error
39
41
  end
40
42
  def test_gcm_400_responses_should_have_failed_and_report_error
41
- json= {:body=>"\"registration_ids\" field is not a JSON array\n", :headers=>{"content-type"=>["text/plain; charset=UTF-8"], "date"=>["Tue, 09 Dec 2014 21:27:30 GMT"], "expires"=>["Tue, 09 Dec 2014 21:27:30 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "connection"=>["close"]}, :status_code=>400, :response=>"Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields."}
42
- rs= VirtualSession::GcmResponse.new(json)
43
+ rs= VirtualSession::GcmResponse.new(GCM_400_RESPONSE)
43
44
  refute rs.success? and rs.error?
44
45
  assert rs.failure?
45
46
  expected= "\"registration_ids\" field is not a JSON array\n->Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields."
46
47
  assert_equal expected, rs.failure
47
48
  end
49
+ def test_gcm_responses_should_return_received_payload_on_to_s
50
+ [GCM_200_WITH_SUCCESS,
51
+ GCM_200_WITH_INVALID_REGISTRATION,
52
+ GCM_200_WITH_MISMATCH_SENDER_ID,
53
+ GCM_400_RESPONSE].each do |json|
54
+ assert_equal json.to_s, VirtualSession::GcmResponse.new(json).to_s
55
+ end
56
+ end
48
57
  end
49
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pntfr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliver