pntfr 0.1.3 → 0.1.4
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/README.md +26 -1
- data/lib/pntfr/version.rb +4 -1
- data/lib/pntfr/virtual_session/android.rb +2 -1
- data/lib/pntfr/virtual_session/ios.rb +11 -3
- data/pntfr.gemspec +3 -2
- data/test/fxtr.rb +27 -0
- data/test/pntfr/device_session.rb +1 -1
- data/test/pntfr/virtual_session/android_test.rb +33 -16
- data/test/pntfr/virtual_session/ios_test.rb +23 -4
- data/test/pntfr_configuration_test.rb +1 -1
- data/test/test_helper.rb +1 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f800de7abd264da783c00f614745d0707a1c67
|
4
|
+
data.tar.gz: 6a517da6bbb0289631ed30b446b446162a9afb55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef4c923993a150b1d72c02ff360675a86cd0b786836b12c558dd72e426d178fb0904640a7ec6a49b3c180643bc4f149f7e3997080073e47cc1587b7935ccdffc
|
7
|
+
data.tar.gz: 84b38c45c01d94fb1a70821da23f54eba0bcb4b2d4efb0fe8d59c953e5678540359be4ffc3359fdc6cc4042a81f5e33fd759189793ee8b3d1108b4d98d89597e
|
data/README.md
CHANGED
@@ -65,8 +65,33 @@ Pntfr::Notifier.to(session).msg({:title => 'Some Title', :description => 'A desc
|
|
65
65
|
#send many notifications to a given device
|
66
66
|
vsession= Pntfr::Notifier.to(session)
|
67
67
|
vsession.msg({:title => 'Some Title', :description => 'A description'}).notify
|
68
|
-
vsession.msg({
|
68
|
+
vsession.msg({
|
69
|
+
:title => 'Some Other Title',
|
70
|
+
:description => 'Another description',
|
71
|
+
:sound => 'flipping-sound.aiff'})
|
72
|
+
vsession.notify
|
73
|
+
|
74
|
+
# send notifications with custom content (an extra optional parameter to #msg)
|
75
|
+
vsession= Pntfr::Notifier.to(session)
|
76
|
+
vsession.msg(
|
77
|
+
{:title => 'Some Title', :description => 'A description'},
|
78
|
+
{
|
79
|
+
:extra1 => 'extra one',
|
80
|
+
:extra_2 => 'extra 2',
|
81
|
+
:'last-extra' => {lastkey: 'last value'}
|
82
|
+
}
|
83
|
+
)
|
84
|
+
vsession.notify
|
85
|
+
|
86
|
+
# Custom content will be found into :custom key for Android.
|
87
|
+
# For iOS each custom key is transformed into an 'acme-' prefixed key.
|
69
88
|
```
|
89
|
+
# Testing
|
90
|
+
For testing one can check the messages to be sent to each given driver the same way
|
91
|
+
that Rails ActiveMailer works: messages are stacked into `Pntfr.deliveries[push_id]`,
|
92
|
+
where for each key (push_id is the identifier of the device) one will get an ordered array
|
93
|
+
with all messages sent to the device while testing. Of course, while testing,
|
94
|
+
notifications are not sent, only stored in the stack.
|
70
95
|
|
71
96
|
# Resources
|
72
97
|
- Depends on APNS gem: https://rubygems.org/gems/apns
|
data/lib/pntfr/version.rb
CHANGED
@@ -13,12 +13,13 @@ module Pntfr
|
|
13
13
|
@gcm= ::GCM.new(@notification_key) unless Pntfr.test_env?
|
14
14
|
end
|
15
15
|
|
16
|
-
def msg content
|
16
|
+
def msg content, custom=nil
|
17
17
|
@data= {
|
18
18
|
:title => content[:title],
|
19
19
|
:description => content[:description],
|
20
20
|
}
|
21
21
|
@data[:sound]= parse_sound_file(content[:sound]) unless content[:sound].nil?
|
22
|
+
@data[:custom]= custom if custom
|
22
23
|
self
|
23
24
|
end
|
24
25
|
def notify
|
@@ -5,14 +5,15 @@ require 'apns'
|
|
5
5
|
module Pntfr
|
6
6
|
module VirtualSession
|
7
7
|
class Ios < Pntfr::VirtualSession::Base
|
8
|
-
def msg content
|
8
|
+
def msg content, custom=nil
|
9
9
|
configure_apns
|
10
10
|
reset_msg
|
11
11
|
@alert= content[:title]
|
12
|
-
@alert+= "\n#{content[:description]}"
|
12
|
+
@alert+= "\n#{content[:description]}" if content.key?(:description)
|
13
13
|
@sound= content[:sound]
|
14
14
|
badge= content[:badge]
|
15
15
|
@badge= content[:badge].to_i if badge
|
16
|
+
add_custom_content(custom) if custom
|
16
17
|
self
|
17
18
|
end
|
18
19
|
|
@@ -25,6 +26,7 @@ module Pntfr
|
|
25
26
|
n[:badge]= @session.num_notifs
|
26
27
|
end
|
27
28
|
n[:sound]= @sound if @sound
|
29
|
+
n.merge!(@custom) if @custom
|
28
30
|
|
29
31
|
if Pntfr.test_env?
|
30
32
|
Pntfr.add_delivery(@push_id, n)
|
@@ -48,7 +50,13 @@ module Pntfr
|
|
48
50
|
def reset_msg
|
49
51
|
@alert= @sound= @badge= nil
|
50
52
|
end
|
51
|
-
|
53
|
+
def add_custom_content custom
|
54
|
+
@custom= {}
|
55
|
+
custom.each_pair { |k, v|
|
56
|
+
key= "acme-#{k}".to_sym
|
57
|
+
@custom[key]= v
|
58
|
+
}
|
59
|
+
end
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
data/pntfr.gemspec
CHANGED
@@ -9,8 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['oliver']
|
10
10
|
spec.email = ['oliver.hv@coditramuntana.com']
|
11
11
|
spec.summary = %q{Push notifier is a simple adapter for APNS and GCM gems, that way you can use same api to send push notifications to both devices.}
|
12
|
-
|
13
|
-
spec.homepage = "http://www.coditramuntana.com"
|
12
|
+
spec.description = %q{One single API to send push notifications to Android and iOS devices.}
|
13
|
+
# spec.homepage = "http://www.coditramuntana.com"
|
14
|
+
spec.homepage = 'https://github.com/tramuntanal/pntfr'
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
data/test/fxtr.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Fixtures
|
2
|
+
#
|
3
|
+
#
|
4
|
+
|
5
|
+
module Fxtr
|
6
|
+
module Android
|
7
|
+
def self.simple_msg
|
8
|
+
{
|
9
|
+
:title => 'Some Title', :description => 'A description',
|
10
|
+
:sound => 'bell.caff'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
module Common
|
15
|
+
# without description, only title
|
16
|
+
def self.simple_msg
|
17
|
+
{:title => 'Test Title'}
|
18
|
+
end
|
19
|
+
def self.custom_msg_content
|
20
|
+
{
|
21
|
+
:extra1 => 'extra one',
|
22
|
+
:extra_2 => 'extra 2',
|
23
|
+
:'last-extra' => {lastkey: 'last value'}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -3,4 +3,4 @@
|
|
3
3
|
# minimal expected session
|
4
4
|
Pntfr::DeviceSession= Struct.new(:platform, :push_id)
|
5
5
|
# session with num_notifs which will be autoincremented on each sent msg
|
6
|
-
Pntfr::IosDeviceSession= Struct.new(:platform, :push_id, :num_notifs)
|
6
|
+
Pntfr::IosDeviceSession= Struct.new(:platform, :push_id, :num_notifs)
|
@@ -1,44 +1,61 @@
|
|
1
1
|
require 'pntfr/device_session'
|
2
|
+
require 'fxtr'
|
3
|
+
|
2
4
|
module Pntfr
|
3
5
|
module VirtualSession
|
4
6
|
class AndroidTest < Minitest::Test
|
5
7
|
|
8
|
+
def setup
|
9
|
+
@push_id= 'ANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROID'
|
10
|
+
end
|
6
11
|
def test_received_content_shoud_be_sent_to_gcm
|
7
|
-
|
8
|
-
session= DeviceSession.new(Pntfr::Platforms::ANDROID, push_id)
|
12
|
+
session= DeviceSession.new(Pntfr::Platforms::ANDROID, @push_id)
|
9
13
|
|
10
|
-
vsession= Pntfr::Notifier.to(session).msg(
|
11
|
-
:title => 'Some Title', :description => 'A description',
|
12
|
-
:sound => 'bell.caff'
|
13
|
-
})
|
14
|
+
vsession= Pntfr::Notifier.to(session).msg(Fxtr::Android.simple_msg)
|
14
15
|
rs= vsession.notify
|
15
16
|
assert rs.success? and rs.msg_sent?
|
16
17
|
|
17
|
-
notifs= Pntfr.deliveries[push_id]
|
18
|
-
refute_nil notifs, "A notification should have been delivered for #{push_id}"
|
18
|
+
notifs= Pntfr.deliveries[@push_id]
|
19
|
+
refute_nil notifs, "A notification should have been delivered for #{@push_id}"
|
19
20
|
notif= notifs.last
|
20
21
|
assert_equal 'Some Title', notif[:data][:title]
|
21
22
|
assert_equal 'A description', notif[:data][:description]
|
22
23
|
assert_equal 'bell', notif[:data][:sound]
|
23
24
|
end
|
24
25
|
def test_sound_attribute_shoud_be_sent_to_gcm
|
25
|
-
|
26
|
-
session= DeviceSession.new(Pntfr::Platforms::ANDROID, push_id)
|
26
|
+
session= DeviceSession.new(Pntfr::Platforms::ANDROID, @push_id)
|
27
27
|
|
28
|
-
vsession= Pntfr::Notifier.to(session).msg(
|
29
|
-
:title => 'Some Title', :description => 'A description',
|
30
|
-
:sound => 'bell.caff'
|
31
|
-
})
|
28
|
+
vsession= Pntfr::Notifier.to(session).msg(Fxtr::Android.simple_msg)
|
32
29
|
rs= vsession.notify
|
33
30
|
assert rs.success? and rs.msg_sent?
|
34
31
|
|
35
|
-
notifs= Pntfr.deliveries[push_id]
|
36
|
-
refute_nil notifs, "A notification should have been delivered for #{push_id}"
|
32
|
+
notifs= Pntfr.deliveries[@push_id]
|
33
|
+
refute_nil notifs, "A notification should have been delivered for #{@push_id}"
|
37
34
|
notif= notifs.last
|
38
35
|
assert_equal 'Some Title', notif[:data][:title]
|
39
36
|
assert_equal 'A description', notif[:data][:description]
|
40
37
|
assert_equal 'bell', notif[:data][:sound]
|
41
38
|
end
|
39
|
+
|
40
|
+
def test_sending_custom_content_for_android_should_be_added_as_more_keys
|
41
|
+
session= DeviceSession.new(Pntfr::Platforms::ANDROID, @push_id)
|
42
|
+
|
43
|
+
vsession= Pntfr::Notifier.to(session)
|
44
|
+
vsession.msg(Fxtr::Common.simple_msg, Fxtr::Common.custom_msg_content)
|
45
|
+
rs= vsession.notify
|
46
|
+
assert rs.success? and rs.msg_sent?
|
47
|
+
|
48
|
+
notifs= Pntfr.deliveries[@push_id]
|
49
|
+
refute_nil notifs, "A notification should have been delivered for #{@push_id}"
|
50
|
+
notif= notifs.last
|
51
|
+
data= notif[:data]
|
52
|
+
assert_equal 'Test Title', data[:title]
|
53
|
+
assert_equal 'extra one', data[:custom][:extra1]
|
54
|
+
assert_equal 'extra 2', data[:custom][:extra_2]
|
55
|
+
assert_equal({lastkey: 'last value'}, data[:custom][:'last-extra'])
|
56
|
+
|
57
|
+
end
|
58
|
+
|
42
59
|
end
|
43
60
|
end
|
44
61
|
end
|
@@ -2,16 +2,18 @@ require 'pntfr/device_session'
|
|
2
2
|
module Pntfr
|
3
3
|
module VirtualSession
|
4
4
|
class IosTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@push_id= 'IOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSios'
|
7
|
+
end
|
5
8
|
|
6
9
|
def test_received_content_shoud_be_ready_to_be_sent_to_apns
|
7
|
-
|
8
|
-
session= DeviceSession.new(Pntfr::Platforms::IOS, push_id)
|
10
|
+
session= DeviceSession.new(Pntfr::Platforms::IOS, @push_id)
|
9
11
|
|
10
12
|
rs= Pntfr::Notifier.to(session).msg({:title => 'thatitle', :description => 'thadescription', :sound => 'click.aiff', :badge => 33}).notify
|
11
13
|
assert rs.success? and rs.msg_sent?
|
12
14
|
|
13
|
-
ios_notifs= Pntfr.deliveries[push_id]
|
14
|
-
refute_nil ios_notifs, "A notification should have been delivered for #{push_id}"
|
15
|
+
ios_notifs= Pntfr.deliveries[@push_id]
|
16
|
+
refute_nil ios_notifs, "A notification should have been delivered for #{@push_id}"
|
15
17
|
ios_notif= ios_notifs.last
|
16
18
|
assert_equal "thatitle\nthadescription", ios_notif[:alert]
|
17
19
|
assert_equal 'click.aiff', ios_notif[:sound]
|
@@ -39,6 +41,23 @@ module Pntfr
|
|
39
41
|
assert_equal 'default', notif[:sound]
|
40
42
|
assert_equal 5, notif[:badge]
|
41
43
|
end
|
44
|
+
|
45
|
+
def test_sending_custom_content_for_ios_should_be_added_as_acme_keys
|
46
|
+
session= DeviceSession.new(Pntfr::Platforms::IOS, @push_id)
|
47
|
+
|
48
|
+
vsession= Pntfr::Notifier.to(session)
|
49
|
+
vsession.msg(Fxtr::Common.simple_msg, Fxtr::Common.custom_msg_content)
|
50
|
+
rs= vsession.notify
|
51
|
+
assert rs.success? and rs.msg_sent?
|
52
|
+
|
53
|
+
ios_notifs= Pntfr.deliveries[@push_id]
|
54
|
+
refute_nil ios_notifs, "A notification should have been delivered for #{@push_id}"
|
55
|
+
ios_notif= ios_notifs.last
|
56
|
+
assert_equal 'Test Title', ios_notif[:alert]
|
57
|
+
assert_equal 'extra one', ios_notif[:'acme-extra1']
|
58
|
+
assert_equal 'extra 2', ios_notif[:'acme-extra_2']
|
59
|
+
assert_equal({lastkey: 'last value'}, ios_notif[:'acme-last-extra'])
|
60
|
+
end
|
42
61
|
end
|
43
62
|
end
|
44
63
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,7 +7,7 @@ require 'pntfr'
|
|
7
7
|
# require all test files
|
8
8
|
def add_to_path(d)
|
9
9
|
Dir.entries(d).each do |f|
|
10
|
-
next if f == '.'
|
10
|
+
next if f == '.' || f == '..'
|
11
11
|
file= File.join(d, f)
|
12
12
|
if File.directory?(file)
|
13
13
|
add_to_path(file)
|
@@ -17,4 +17,3 @@ def add_to_path(d)
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
add_to_path(File.dirname(__FILE__))
|
20
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pntfr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apns
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
|
-
description:
|
101
|
+
description: One single API to send push notifications to Android and iOS devices.
|
102
102
|
email:
|
103
103
|
- oliver.hv@coditramuntana.com
|
104
104
|
executables: []
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/pntfr/virtual_session/ios.rb
|
124
124
|
- lib/pntfr/virtual_session/success_response.rb
|
125
125
|
- pntfr.gemspec
|
126
|
+
- test/fxtr.rb
|
126
127
|
- test/pntfr/device_session.rb
|
127
128
|
- test/pntfr/platforms_test.rb
|
128
129
|
- test/pntfr/push_notifier_test.rb
|
@@ -132,7 +133,7 @@ files:
|
|
132
133
|
- test/pntfr/virtual_session/response_test.rb
|
133
134
|
- test/pntfr_configuration_test.rb
|
134
135
|
- test/test_helper.rb
|
135
|
-
homepage:
|
136
|
+
homepage: https://github.com/tramuntanal/pntfr
|
136
137
|
licenses:
|
137
138
|
- MIT
|
138
139
|
metadata: {}
|
@@ -158,6 +159,7 @@ specification_version: 4
|
|
158
159
|
summary: Push notifier is a simple adapter for APNS and GCM gems, that way you can
|
159
160
|
use same api to send push notifications to both devices.
|
160
161
|
test_files:
|
162
|
+
- test/fxtr.rb
|
161
163
|
- test/pntfr/device_session.rb
|
162
164
|
- test/pntfr/platforms_test.rb
|
163
165
|
- test/pntfr/push_notifier_test.rb
|