pntfr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +9 -0
- data/lib/pntfr/notifier.rb +15 -0
- data/lib/pntfr/platforms.rb +14 -0
- data/lib/pntfr/version.rb +3 -0
- data/lib/pntfr/virtual_session/android.rb +32 -0
- data/lib/pntfr/virtual_session/base.rb +15 -0
- data/lib/pntfr/virtual_session/ios.rb +35 -0
- data/lib/pntfr.rb +27 -0
- data/nbproject/private/private.properties +2 -0
- data/nbproject/private/rake-d.txt +5 -0
- data/nbproject/project.properties +7 -0
- data/nbproject/project.xml +15 -0
- data/pntfr.gemspec +25 -0
- data/test/pntfr/ios_badge_test.rb +18 -0
- data/test/pntfr/platforms_test.rb +44 -0
- data/test/pntfr/push_notifier_test.rb +59 -0
- data/test/pntfr_configuration_test.rb +28 -0
- data/test/test_helper.rb +35 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21f8593d4f134a1ff8e05513e7188f8b6a274a84
|
4
|
+
data.tar.gz: 8f024163dca35fa1c71196c3d3adb1bdf6ce7757
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45e976044bf8346564e1933f5a2dee4844f992fa9b30d9128033019784ffeed8842e84c388c6f8bdf9a43a27ac861555541c2f147114a5164a5888bddc5a5dde
|
7
|
+
data.tar.gz: 5ec6fcb740a97e25afa66ee3704c4839bf9a7a209a75e8f6dceac254b01523f467ac7647ae0409aa8fea876ce2d8913d5511b4c9f01d934e3c5ae7c957b4c1e8
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
/nbproject/
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Oliver HV
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 oliver
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Pntfr
|
2
|
+
Push Notifier is a simple adapter for APNS (Apple Push Notification Service) and GCM (Google Cloud Messaging) gems, that way you can use same API to send push notifications to both devices.
|
3
|
+
|
4
|
+
# Usage
|
5
|
+
## Installation
|
6
|
+
Add it to your Gemfile:
|
7
|
+
|
8
|
+
gem 'pntfr', '~>0.1.1'
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
To configure the Apple Push Notification Service just set the Hash of keys to be used:
|
12
|
+
```ruby
|
13
|
+
Pntfr.configure do |config|
|
14
|
+
config.apns= {
|
15
|
+
host: 'gateway.sandbox.push.apple.com',
|
16
|
+
pem: 'config/apns/development_push.keys.pem',
|
17
|
+
port: 2195,
|
18
|
+
pass: 'ThaPasswah',
|
19
|
+
}
|
20
|
+
end
|
21
|
+
```
|
22
|
+
To configure the Google Cloud Messaging
|
23
|
+
```ruby
|
24
|
+
Pntfr.configure do |config|
|
25
|
+
config.gcm= {:notification_key => 'SomeSecretKeySomeSecretKeySomeSecretKey'}
|
26
|
+
end
|
27
|
+
```
|
28
|
+
You will normally configure both at the same time:
|
29
|
+
```ruby
|
30
|
+
Pntfr.configure do |config|
|
31
|
+
config.apns= {
|
32
|
+
host: 'gateway.sandbox.push.apple.com',
|
33
|
+
pem: 'config/apns/development_push.keys.pem',
|
34
|
+
port: 2195,
|
35
|
+
pass: 'ThaPasswah',
|
36
|
+
}
|
37
|
+
config.gcm= {:notification_key => 'SomeSecretKeySomeSecretKeySomeSecretKey'}
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Sending messages
|
42
|
+
Pntfr suposes you have session objects with the `platform` and `push_id` attributes.
|
43
|
+
Also, and optionally, a `num_notifs` integer attribute will be automagically managed to
|
44
|
+
monitor Apple's badge in notifications.
|
45
|
+
|
46
|
+
The neutral model for the content of the messages is composed by a title and a description,
|
47
|
+
this maps directly to Android notification's `data` content wile is concatenated with a newline
|
48
|
+
for Apns notificaitons.
|
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.
|
54
|
+
|
55
|
+
Given you have a DeviceSession model in your application. Then to send a message to a device do:
|
56
|
+
```ruby
|
57
|
+
# get device session
|
58
|
+
session= DeviceSession.new(platform: Pntfr::Platforms::IOS, push_id: '...')
|
59
|
+
# send notification to the given user
|
60
|
+
Pntfr::Notifier.to(session).msg({:title => 'Some Title', :description => 'A description'}).notify
|
61
|
+
```
|
62
|
+
|
63
|
+
# Resources
|
64
|
+
- Depends on APNS gem: https://rubygems.org/gems/apns
|
65
|
+
- Depends on GCM gem: https://rubygems.org/gems/gcm
|
66
|
+
- Alternative, that supports more platforms but without a unified api: https://github.com/rpush/rpush
|
67
|
+
|
68
|
+
# Authors
|
69
|
+
|
70
|
+
- Oliver HV <https://github.com/tramuntanal>
|
71
|
+
|
72
|
+
Contributions are always welcome and greatly appreciated!
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/virtual_session/base'
|
2
|
+
|
3
|
+
module Pntfr
|
4
|
+
|
5
|
+
class Notifier
|
6
|
+
def self.to session
|
7
|
+
if Platforms.android? session.platform
|
8
|
+
Pntfr::VirtualSession::Android.new(session)
|
9
|
+
elsif Platforms.ios? session.platform
|
10
|
+
Pntfr::VirtualSession::Ios.new(session)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pntfr
|
2
|
+
module Platforms
|
3
|
+
ANDROID= 'ANDROID'
|
4
|
+
IOS= 'IOS'
|
5
|
+
def self.android? string
|
6
|
+
return false if string.nil? or string.empty?
|
7
|
+
ANDROID == string.upcase
|
8
|
+
end
|
9
|
+
def self.ios? string
|
10
|
+
return false if string.nil? or string.empty?
|
11
|
+
IOS == string.upcase
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# VirtualSession implementation for Android
|
3
|
+
#
|
4
|
+
|
5
|
+
module Pntfr
|
6
|
+
module VirtualSession
|
7
|
+
class Android < Pntfr::VirtualSession::Base
|
8
|
+
def initialize session
|
9
|
+
super
|
10
|
+
@notification_key= Pntfr.config.gcm[:notification_key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def msg content
|
14
|
+
@data= {
|
15
|
+
:title => content[:title],
|
16
|
+
:description => content[:description],
|
17
|
+
}
|
18
|
+
self
|
19
|
+
end
|
20
|
+
def notify
|
21
|
+
options = {data: @data}
|
22
|
+
if Pntfr.test_env?
|
23
|
+
Pntfr.add_delivery(@push_id, options)
|
24
|
+
else
|
25
|
+
gcm= GCM.new(@notification_key)
|
26
|
+
gcm.send_notification(@push_id, options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pntfr
|
2
|
+
module VirtualSession
|
3
|
+
class Base
|
4
|
+
def initialize session
|
5
|
+
@session= session
|
6
|
+
@push_id= @session.push_id
|
7
|
+
end
|
8
|
+
def msg content
|
9
|
+
raise 'not implemented!'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
require File.dirname(__FILE__) + '/android'
|
15
|
+
require File.dirname(__FILE__) + '/ios'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# VirtualSession implementation for iOS
|
3
|
+
#
|
4
|
+
module Pntfr
|
5
|
+
module VirtualSession
|
6
|
+
class Ios < Pntfr::VirtualSession::Base
|
7
|
+
def msg content
|
8
|
+
@alert= content[:title]
|
9
|
+
@alert+= "\n#{content[:description]}"
|
10
|
+
@sound= content[:sound]
|
11
|
+
badge= content[:badge]
|
12
|
+
@badge= content[:badge].to_i if badge
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify
|
17
|
+
n= {:alert => @alert, :sound => 'default'}
|
18
|
+
if @badge
|
19
|
+
n[:badge]= @badge
|
20
|
+
elsif @session.methods.include?(:num_notifs)
|
21
|
+
@session.num_notifs+= 1
|
22
|
+
n[:badge]= @session.num_notifs
|
23
|
+
end
|
24
|
+
n[:sound]= @sound if @sound
|
25
|
+
|
26
|
+
if Pntfr.test_env?
|
27
|
+
Pntfr.add_delivery(@push_id, n)
|
28
|
+
else
|
29
|
+
APNS.send_notification(@push_id, n)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/pntfr.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pntfr/version'
|
2
|
+
require 'pntfr/platforms'
|
3
|
+
require 'pntfr/notifier'
|
4
|
+
|
5
|
+
module Pntfr
|
6
|
+
def self.test_env?
|
7
|
+
ENV['ENV'] == 'test' or (defined?(Rails) and Rails.env.test?)
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :config
|
12
|
+
end
|
13
|
+
def self.configure
|
14
|
+
self.config ||= Configuration.new
|
15
|
+
yield(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :apns
|
20
|
+
attr_accessor :gcm
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@apns= {}
|
24
|
+
@gcm= {}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://www.netbeans.org/ns/project/1">
|
3
|
+
<type>org.netbeans.modules.ruby.rubyproject</type>
|
4
|
+
<configuration>
|
5
|
+
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
|
6
|
+
<name>Pntfr</name>
|
7
|
+
<source-roots>
|
8
|
+
<root id="src.dir"/>
|
9
|
+
</source-roots>
|
10
|
+
<test-roots>
|
11
|
+
<root id="test.src.dir"/>
|
12
|
+
</test-roots>
|
13
|
+
</data>
|
14
|
+
</configuration>
|
15
|
+
</project>
|
data/pntfr.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pntfr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pntfr'
|
8
|
+
spec.version = Pntfr::VERSION
|
9
|
+
spec.authors = ['oliver']
|
10
|
+
spec.email = ['oliver.hv@coditramuntana.com']
|
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
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "http://www.coditramuntana.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'apns', '~> 1.0', '>= 1.0.0'
|
22
|
+
spec.add_runtime_dependency 'gcm', '~> 0.0', '>= 0.0.9'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module Pntfr
|
3
|
+
module VirtualSession
|
4
|
+
class IosBadgeTest < Minitest::Test
|
5
|
+
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)
|
8
|
+
|
9
|
+
Pntfr::Notifier.to(session).msg({:title => 't', :description => 'd'}).notify
|
10
|
+
|
11
|
+
notifs= Pntfr.deliveries['1id2id3id4id5id']
|
12
|
+
notif= notifs.last
|
13
|
+
assert_equal 1, notif[:badge]
|
14
|
+
assert_equal 1, session.num_notifs
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Pntfr
|
2
|
+
class PlatformsTest < Minitest::Test
|
3
|
+
#
|
4
|
+
# ANDROID
|
5
|
+
#
|
6
|
+
def test_android_shoud_be_android
|
7
|
+
assert_equal 'ANDROID', Platforms::ANDROID
|
8
|
+
end
|
9
|
+
def test_checking_for_android_should_accept_all_lettercases
|
10
|
+
assert Platforms.android? 'ANDROID'
|
11
|
+
assert Platforms.android? 'android'
|
12
|
+
assert Platforms.android? 'AnDrOiD'
|
13
|
+
assert Platforms.android? 'aNdRoId'
|
14
|
+
end
|
15
|
+
def test_checking_for_wrong_android_platfoms_should_not_check
|
16
|
+
refute Platforms.android? nil
|
17
|
+
refute Platforms.android? ''
|
18
|
+
refute Platforms.android? 'ANDROI'
|
19
|
+
refute Platforms.android? 'ios'
|
20
|
+
refute Platforms.android? 'NDROID'
|
21
|
+
refute Platforms.android? 'qwertyu'
|
22
|
+
end
|
23
|
+
#
|
24
|
+
# IOS
|
25
|
+
#
|
26
|
+
def test_ios_shoud_be_ios
|
27
|
+
assert_equal 'IOS', Platforms::IOS
|
28
|
+
end
|
29
|
+
def test_checking_for_ios_should_accept_all_lettercases
|
30
|
+
assert Platforms.ios? 'IOS'
|
31
|
+
assert Platforms.ios? 'ios'
|
32
|
+
assert Platforms.ios? 'iOs'
|
33
|
+
assert Platforms.ios? 'IoS'
|
34
|
+
end
|
35
|
+
def test_checking_for_wrong_ios_platfoms_should_not_check
|
36
|
+
refute Platforms.ios? nil
|
37
|
+
refute Platforms.ios? ''
|
38
|
+
refute Platforms.ios? 'ANDROID'
|
39
|
+
refute Platforms.ios? 'is'
|
40
|
+
refute Platforms.ios? 'iso'
|
41
|
+
refute Platforms.ios? 'qwe'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Pntfr
|
2
|
+
class NotifierTest < Minitest::Test
|
3
|
+
def initialize method_name
|
4
|
+
super
|
5
|
+
Pntfr.configure {}
|
6
|
+
end
|
7
|
+
def setup
|
8
|
+
@PushSessionClass= Struct.new(:platform, :push_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# COMMON
|
13
|
+
#
|
14
|
+
def test_android_sessions_should_instantiate_android_virtual_sessions
|
15
|
+
session= @PushSessionClass.new(Pntfr::Platforms::ANDROID)
|
16
|
+
vsess= Pntfr::Notifier.to(session)
|
17
|
+
assert vsess.is_a?(Pntfr::VirtualSession::Android)
|
18
|
+
end
|
19
|
+
def test_ios_sessions_should_instantiate_ios_virtual_sessions
|
20
|
+
session= @PushSessionClass.new(Pntfr::Platforms::IOS)
|
21
|
+
vsess= Pntfr::Notifier.to(session)
|
22
|
+
assert vsess.is_a?(Pntfr::VirtualSession::Ios)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# ANDROID
|
27
|
+
#
|
28
|
+
def test_received_content_shoud_be_sent_to_gcm
|
29
|
+
push_id= 'ANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROIDANDROID'
|
30
|
+
session= @PushSessionClass.new(Pntfr::Platforms::ANDROID, push_id)
|
31
|
+
|
32
|
+
Pntfr::Notifier.to(session).msg({:title => 'Some Title', :description => 'A description'}).notify
|
33
|
+
|
34
|
+
notifs= Pntfr.deliveries[push_id]
|
35
|
+
refute_nil notifs, "A notification should have been delivered for #{push_id}"
|
36
|
+
notif= notifs.last
|
37
|
+
assert_equal "Some Title", notif[:data][:title]
|
38
|
+
assert_equal "A description", notif[:data][:description]
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# IOS
|
43
|
+
#
|
44
|
+
def test_received_content_shoud_be_ready_to_be_sent_to_apns
|
45
|
+
push_id= 'IOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSiosIOSios'
|
46
|
+
session= @PushSessionClass.new(Pntfr::Platforms::IOS, push_id)
|
47
|
+
|
48
|
+
Pntfr::Notifier.to(session).msg({:title => 'thatitle', :description => 'thadescription', :sound => 'click.aiff', :badge => 33}).notify
|
49
|
+
|
50
|
+
ios_notifs= Pntfr.deliveries[push_id]
|
51
|
+
refute_nil ios_notifs, "A notification should have been delivered for #{push_id}"
|
52
|
+
ios_notif= ios_notifs.last
|
53
|
+
assert_equal "thatitle\nthadescription", ios_notif[:alert]
|
54
|
+
assert_equal 'click.aiff', ios_notif[:sound]
|
55
|
+
assert_equal 33, ios_notif[:badge]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pntfr
|
2
|
+
class ConfigTest < Minitest::Test
|
3
|
+
def test_ios_params_should_have_been_taken
|
4
|
+
Pntfr.configure do |config|
|
5
|
+
config.apns= {
|
6
|
+
host: 'test-host',
|
7
|
+
pem: 'test-pem',
|
8
|
+
port: 'test-port',
|
9
|
+
pass: 'test-password',
|
10
|
+
}
|
11
|
+
end
|
12
|
+
apns= Pntfr.config.apns
|
13
|
+
assert_equal 'test-host', apns[:host]
|
14
|
+
assert_equal 'test-pem', apns[:pem]
|
15
|
+
assert_equal 'test-port', apns[:port]
|
16
|
+
assert_equal 'test-password', apns[:pass]
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_android_params_should_have_been_taken
|
20
|
+
Pntfr.configure do |config|
|
21
|
+
config.gcm= {:notification_key => 'SOME-TEST-KEY'}
|
22
|
+
end
|
23
|
+
gcm= Pntfr.config.gcm
|
24
|
+
assert_equal 'SOME-TEST-KEY', gcm[:notification_key]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'pntfr'
|
3
|
+
|
4
|
+
ENV['ENV']= 'test'
|
5
|
+
|
6
|
+
# require all test files
|
7
|
+
def add_to_path(d)
|
8
|
+
Dir.entries(d).each do |f|
|
9
|
+
next if f == '.' or f == '..'
|
10
|
+
file= File.join(d, f)
|
11
|
+
if File.directory?(file)
|
12
|
+
add_to_path(file)
|
13
|
+
elsif f.end_with?('test.rb')
|
14
|
+
require(file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
add_to_path(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
#
|
21
|
+
# Extend library to enable testing.
|
22
|
+
#
|
23
|
+
module Pntfr
|
24
|
+
@@deliveries= {}
|
25
|
+
def self.deliveries
|
26
|
+
@@deliveries
|
27
|
+
end
|
28
|
+
def self.add_delivery push_id, n
|
29
|
+
if @@deliveries.has_key?(push_id)
|
30
|
+
@@deliveries[push_id] << n
|
31
|
+
else
|
32
|
+
@@deliveries[push_id]= [n]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pntfr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- oliver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: apns
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: gcm
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.0.9
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.0.9
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.6'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.6'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
description:
|
82
|
+
email:
|
83
|
+
- oliver.hv@coditramuntana.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- ".gitignore"
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/pntfr.rb
|
95
|
+
- lib/pntfr/notifier.rb
|
96
|
+
- lib/pntfr/platforms.rb
|
97
|
+
- lib/pntfr/version.rb
|
98
|
+
- lib/pntfr/virtual_session/android.rb
|
99
|
+
- lib/pntfr/virtual_session/base.rb
|
100
|
+
- lib/pntfr/virtual_session/ios.rb
|
101
|
+
- nbproject/private/private.properties
|
102
|
+
- nbproject/private/rake-d.txt
|
103
|
+
- nbproject/project.properties
|
104
|
+
- nbproject/project.xml
|
105
|
+
- pntfr.gemspec
|
106
|
+
- test/pntfr/ios_badge_test.rb
|
107
|
+
- test/pntfr/platforms_test.rb
|
108
|
+
- test/pntfr/push_notifier_test.rb
|
109
|
+
- test/pntfr_configuration_test.rb
|
110
|
+
- test/test_helper.rb
|
111
|
+
homepage: http://www.coditramuntana.com
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Push notifier is a simple adapter for APNS and GCM gems, that way you can
|
135
|
+
use same api to send push notifications to both devices.
|
136
|
+
test_files:
|
137
|
+
- test/pntfr/ios_badge_test.rb
|
138
|
+
- test/pntfr/platforms_test.rb
|
139
|
+
- test/pntfr/push_notifier_test.rb
|
140
|
+
- test/pntfr_configuration_test.rb
|
141
|
+
- test/test_helper.rb
|