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 +4 -4
- data/lib/pntfr/platforms.rb +15 -0
- data/lib/pntfr/version.rb +1 -1
- data/lib/pntfr/virtual_session/gcm_response.rb +7 -3
- data/lib/pntfr.rb +4 -1
- data/test/pntfr/push_notifier_test.rb +0 -4
- data/test/pntfr/virtual_session/android_test.rb +0 -4
- data/test/pntfr/virtual_session/ios_test.rb +1 -0
- data/test/pntfr/virtual_session/response_test.rb +17 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86fc4111228a2ba7ad45eb4a2b1878862e46b2cb
|
4
|
+
data.tar.gz: 8381f50b307d91240a4a770353d64d0294bfefd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fb0d5129066a730bf76e00ecf498eac2b9e8ca4231b155f27188d23d611bc3bd1f4d9dc56c281eca1791c6ba7fdc1b9d423a6fbfd15e7d15da1158ec9c89f0c
|
7
|
+
data.tar.gz: b83fc05281fc693de889f072db1b27b1e2f6642805c07a2785f63ed788c675a715b9607b7c823dd5c06ec989de00cfd2ca2996ec882866bf2e3a8c695a66c36f
|
data/lib/pntfr/platforms.rb
CHANGED
@@ -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
@@ -8,9 +8,10 @@ module Pntfr
|
|
8
8
|
module VirtualSession
|
9
9
|
class GcmResponse < BaseResponse
|
10
10
|
def initialize json
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
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
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|