pntfr 0.0.1 → 0.1.0

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: 21f8593d4f134a1ff8e05513e7188f8b6a274a84
4
- data.tar.gz: 8f024163dca35fa1c71196c3d3adb1bdf6ce7757
3
+ metadata.gz: 881840f1cd5381a2e47d78f26b8abaa26cd2b02b
4
+ data.tar.gz: 9f8bb4c8aca929683314e84e203b8e6a9255b337
5
5
  SHA512:
6
- metadata.gz: 45e976044bf8346564e1933f5a2dee4844f992fa9b30d9128033019784ffeed8842e84c388c6f8bdf9a43a27ac861555541c2f147114a5164a5888bddc5a5dde
7
- data.tar.gz: 5ec6fcb740a97e25afa66ee3704c4839bf9a7a209a75e8f6dceac254b01523f467ac7647ae0409aa8fea876ce2d8913d5511b4c9f01d934e3c5ae7c957b4c1e8
6
+ metadata.gz: 42006755a948b74d3f00b47c0db693d538278981d43ce1a383967cb95ab2d13efe61f016eb7b0dd6c38bc72c6bfefb602f0051e9d6aecefd619575f4399d827b
7
+ data.tar.gz: cd3fdf9794ec96cb0d38cec160eee42e26bab0cac6e71ff9925067982203de44524f8d65ef44d6113d6684883e0e3a52e5fabd30a29a96a681b91717928a4b55
data/README.md CHANGED
@@ -47,17 +47,25 @@ The neutral model for the content of the messages is composed by a title and a d
47
47
  this maps directly to Android notification's `data` content wile is concatenated with a newline
48
48
  for Apns notificaitons.
49
49
 
50
- Sending a notification is quite simple. First you create a virtual session to manage
51
- each recipient's connection. This virtual session will take care of the message format for
52
- each platform and of connecting with the correct driver. Secondly set the message to be sent,
53
- and notify.
50
+ Sending a notification is quite simple.
51
+ - First, create a virtual session to manage each recipient's connection. This virtual
52
+ session is platform specific and will take care of the message structure for the
53
+ given platform and of connecting through the correct driver.
54
+ - Second, set the message to be sent
55
+ - Third, notify.
56
+ Your're done.
54
57
 
55
- Given you have a DeviceSession model in your application. Then to send a message to a device do:
58
+ Given you have a DeviceSession model in your application. Then to send notifications to a device do:
56
59
  ```ruby
57
60
  # get device session
58
61
  session= DeviceSession.new(platform: Pntfr::Platforms::IOS, push_id: '...')
59
- # send notification to the given user
62
+ # send notification to the given device
60
63
  Pntfr::Notifier.to(session).msg({:title => 'Some Title', :description => 'A description'}).notify
64
+
65
+ #send many notifications to a given device
66
+ vsession= Pntfr::Notifier.to(session)
67
+ vsession.msg({:title => 'Some Title', :description => 'A description'}).notify
68
+ vsession.msg({:title => 'Some Other Title', :description => 'Another description', :sound => 'flipping-sound.aiff'}).notify
61
69
  ```
62
70
 
63
71
  # Resources
data/lib/pntfr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pntfr
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -8,6 +8,7 @@ module Pntfr
8
8
  def initialize session
9
9
  super
10
10
  @notification_key= Pntfr.config.gcm[:notification_key]
11
+ @gcm= GCM.new(@notification_key) unless Pntfr.test_env?
11
12
  end
12
13
 
13
14
  def msg content
@@ -22,8 +23,7 @@ module Pntfr
22
23
  if Pntfr.test_env?
23
24
  Pntfr.add_delivery(@push_id, options)
24
25
  else
25
- gcm= GCM.new(@notification_key)
26
- gcm.send_notification(@push_id, options)
26
+ @gcm.send_notification(@push_id, options)
27
27
  end
28
28
  end
29
29
 
@@ -5,6 +5,7 @@ module Pntfr
5
5
  module VirtualSession
6
6
  class Ios < Pntfr::VirtualSession::Base
7
7
  def msg content
8
+ reset_msg
8
9
  @alert= content[:title]
9
10
  @alert+= "\n#{content[:description]}"
10
11
  @sound= content[:sound]
@@ -28,8 +29,16 @@ module Pntfr
28
29
  else
29
30
  APNS.send_notification(@push_id, n)
30
31
  end
32
+ end
33
+
34
+ #-------------------------------------------------
35
+ private
36
+ #-------------------------------------------------
31
37
 
38
+ def reset_msg
39
+ @alert= @sound= @badge= nil
32
40
  end
41
+
33
42
  end
34
43
  end
35
44
  end
@@ -0,0 +1,6 @@
1
+ # Pntfr's expected models to be used for testing purposes
2
+
3
+ # minimal expected session
4
+ Pntfr::DeviceSession= Struct.new(:platform, :push_id)
5
+ # session with num_notifs which will be autoincremented on each sent msg
6
+ Pntfr::IosDeviceSession= Struct.new(:platform, :push_id, :num_notifs)
@@ -1,10 +1,10 @@
1
+ require 'pntfr/device_session'
1
2
 
2
3
  module Pntfr
3
4
  module VirtualSession
4
5
  class IosBadgeTest < Minitest::Test
5
6
  def test_sending_a_notification_increments_session_notifications_num
6
- clazz= Struct.new(:platform, :push_id, :num_notifs)
7
- session= clazz.new(Pntfr::Platforms::IOS, '1id2id3id4id5id', 0)
7
+ session= Pntfr::IosDeviceSession.new(Pntfr::Platforms::IOS, '1id2id3id4id5id', 0)
8
8
 
9
9
  Pntfr::Notifier.to(session).msg({:title => 't', :description => 'd'}).notify
10
10
 
@@ -0,0 +1,25 @@
1
+ module Pntfr
2
+ module VirtualSession
3
+ class IosTest < Minitest::Test
4
+ def test_ios_information_from_previous_msg_should_be_reset_when_sending_a_new_msg
5
+ session= IosDeviceSession.new(Pntfr::Platforms::IOS, name, 3)
6
+ vsession= Pntfr::Notifier.to(session)
7
+
8
+ vsession.msg(title: 't1', description: 'd1', sound: 's1').notify
9
+ vsession.msg(title: 't2', description: 'd2').notify
10
+
11
+ notifs= Pntfr.deliveries[session.push_id]
12
+ assert_equal 5, session.num_notifs
13
+ assert_equal 2, notifs.size
14
+ notif= notifs.first
15
+ assert_equal "t1\nd1", notif[:alert]
16
+ assert_equal 's1', notif[:sound]
17
+ assert_equal 4, notif[:badge]
18
+ notif= notifs.last
19
+ assert_equal "t2\nd2", notif[:alert]
20
+ assert_equal 'default', notif[:sound]
21
+ assert_equal 5, notif[:badge]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,23 +1,21 @@
1
+ require 'pntfr/device_session'
1
2
  module Pntfr
2
3
  class NotifierTest < Minitest::Test
3
4
  def initialize method_name
4
5
  super
5
6
  Pntfr.configure {}
6
7
  end
7
- def setup
8
- @PushSessionClass= Struct.new(:platform, :push_id)
9
- end
10
8
 
11
9
  #
12
10
  # COMMON
13
11
  #
14
12
  def test_android_sessions_should_instantiate_android_virtual_sessions
15
- session= @PushSessionClass.new(Pntfr::Platforms::ANDROID)
13
+ session= DeviceSession.new(Pntfr::Platforms::ANDROID)
16
14
  vsess= Pntfr::Notifier.to(session)
17
15
  assert vsess.is_a?(Pntfr::VirtualSession::Android)
18
16
  end
19
17
  def test_ios_sessions_should_instantiate_ios_virtual_sessions
20
- session= @PushSessionClass.new(Pntfr::Platforms::IOS)
18
+ session= DeviceSession.new(Pntfr::Platforms::IOS)
21
19
  vsess= Pntfr::Notifier.to(session)
22
20
  assert vsess.is_a?(Pntfr::VirtualSession::Ios)
23
21
  end
@@ -27,7 +25,7 @@ module Pntfr
27
25
  #
28
26
  def test_received_content_shoud_be_sent_to_gcm
29
27
  push_id= 'ANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROID'
30
- session= @PushSessionClass.new(Pntfr::Platforms::ANDROID, push_id)
28
+ session= DeviceSession.new(Pntfr::Platforms::ANDROID, push_id)
31
29
 
32
30
  Pntfr::Notifier.to(session).msg({:title => 'Some Title', :description => 'A description'}).notify
33
31
 
@@ -43,7 +41,7 @@ module Pntfr
43
41
  #
44
42
  def test_received_content_shoud_be_ready_to_be_sent_to_apns
45
43
  push_id= 'IOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSios'
46
- session= @PushSessionClass.new(Pntfr::Platforms::IOS, push_id)
44
+ session= DeviceSession.new(Pntfr::Platforms::IOS, push_id)
47
45
 
48
46
  Pntfr::Notifier.to(session).msg({:title => 'thatitle', :description => 'thadescription', :sound => 'click.aiff', :badge => 33}).notify
49
47
 
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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliver
@@ -103,7 +103,9 @@ files:
103
103
  - nbproject/project.properties
104
104
  - nbproject/project.xml
105
105
  - pntfr.gemspec
106
+ - test/pntfr/device_session.rb
106
107
  - test/pntfr/ios_badge_test.rb
108
+ - test/pntfr/ios_test.rb
107
109
  - test/pntfr/platforms_test.rb
108
110
  - test/pntfr/push_notifier_test.rb
109
111
  - test/pntfr_configuration_test.rb
@@ -134,7 +136,9 @@ specification_version: 4
134
136
  summary: Push notifier is a simple adapter for APNS and GCM gems, that way you can
135
137
  use same api to send push notifications to both devices.
136
138
  test_files:
139
+ - test/pntfr/device_session.rb
137
140
  - test/pntfr/ios_badge_test.rb
141
+ - test/pntfr/ios_test.rb
138
142
  - test/pntfr/platforms_test.rb
139
143
  - test/pntfr/push_notifier_test.rb
140
144
  - test/pntfr_configuration_test.rb