apnd 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/Rakefile +4 -0
- data/bin/apnd-push +6 -6
- data/lib/apnd/daemon.rb +1 -1
- data/lib/apnd/daemon/protocol.rb +8 -6
- data/lib/apnd/notification.rb +3 -3
- data/lib/apnd/version.rb +1 -1
- data/test/{notification_test.rb → apnd_test.rb} +17 -5
- data/test/test_helper.rb +5 -0
- metadata +3 -4
- data/test/daemon_test.rb +0 -5
data/README.markdown
CHANGED
@@ -52,14 +52,14 @@ notifications to a running APND instance, or Apple directly. It is only
|
|
52
52
|
recommended to send notifications directly to Apple for testing purposes.
|
53
53
|
|
54
54
|
Usage:
|
55
|
-
apnd-push [OPTIONS] --token <token>
|
55
|
+
apnd-push [OPTIONS] --token <token>
|
56
56
|
|
57
57
|
Required Arguments:
|
58
58
|
--token [TOKEN] Set Notification's iPhone token to TOKEN
|
59
|
-
--alert [MESSAGE] Set Notification's alert to MESSAGE
|
60
59
|
|
61
60
|
Optional Arguments:
|
62
|
-
--
|
61
|
+
--alert [MESSAGE] Set Notification's alert to MESSAGE
|
62
|
+
--sound [SOUND] Set Notification's sound to SOUND
|
63
63
|
--badge [NUMBER] Set Notification's badge number to NUMBER
|
64
64
|
--custom [JSON] Set Notification's custom data to JSON
|
65
65
|
--host [HOST] Send Notification to HOST, usually the one running APND (default is 'localhost')
|
data/Rakefile
CHANGED
data/bin/apnd-push
CHANGED
@@ -8,7 +8,7 @@ require 'optparse'
|
|
8
8
|
|
9
9
|
help = <<HELP
|
10
10
|
Usage:
|
11
|
-
apnd-push [OPTIONS] --token <token>
|
11
|
+
apnd-push [OPTIONS] --token <token>
|
12
12
|
|
13
13
|
HELP
|
14
14
|
|
@@ -23,13 +23,13 @@ opts = OptionParser.new do |opt|
|
|
23
23
|
options[:token] = token
|
24
24
|
end
|
25
25
|
|
26
|
+
opt.separator "\nOptional Arguments:\n"
|
27
|
+
|
26
28
|
opt.on('--alert [MESSAGE]', "Set Notification's alert to MESSAGE") do |alert|
|
27
29
|
options[:alert] = alert
|
28
30
|
end
|
29
31
|
|
30
|
-
opt.
|
31
|
-
|
32
|
-
opt.on('--sound [SOUND]', "Set Notification's sound to SOUND (default is 'default')") do |sound|
|
32
|
+
opt.on('--sound [SOUND]', "Set Notification's sound to SOUND") do |sound|
|
33
33
|
options[:sound] = sound
|
34
34
|
end
|
35
35
|
|
@@ -74,8 +74,8 @@ begin
|
|
74
74
|
exit
|
75
75
|
end
|
76
76
|
|
77
|
-
unless options[:token]
|
78
|
-
raise OptionParser::MissingArgument, "must specify --token
|
77
|
+
unless options[:token]
|
78
|
+
raise OptionParser::MissingArgument, "must specify --token"
|
79
79
|
end
|
80
80
|
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
81
81
|
puts "#{$0}: #{$!.message}"
|
data/lib/apnd/daemon.rb
CHANGED
@@ -58,7 +58,7 @@ module APND
|
|
58
58
|
count.times do
|
59
59
|
@queue.pop do |notification|
|
60
60
|
begin
|
61
|
-
ohai "Sending notification"
|
61
|
+
ohai "Sending notification for #{notification.token}"
|
62
62
|
@apple.write(notification.to_bytes)
|
63
63
|
rescue Errno::EPIPE, OpenSSL::SSL::SSLError
|
64
64
|
ohai "Error, notification has been added back to the queue"
|
data/lib/apnd/daemon/protocol.rb
CHANGED
@@ -25,15 +25,17 @@ module APND
|
|
25
25
|
end
|
26
26
|
|
27
27
|
#
|
28
|
-
# Add incoming notification to the queue
|
28
|
+
# Add incoming notification(s) to the queue
|
29
29
|
#
|
30
30
|
def receive_data(data)
|
31
31
|
(@buffer ||= "") << data
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
@buffer.each_line do |line|
|
33
|
+
if notification = APND::Notification.valid?(line)
|
34
|
+
ohai "#{@address.last}:#{@address.first} added new Notification to queue"
|
35
|
+
queue.push(notification)
|
36
|
+
else
|
37
|
+
ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/apnd/notification.rb
CHANGED
@@ -81,8 +81,6 @@ module APND
|
|
81
81
|
#
|
82
82
|
def self.valid?(data)
|
83
83
|
parse(data)
|
84
|
-
rescue
|
85
|
-
false
|
86
84
|
end
|
87
85
|
|
88
86
|
#
|
@@ -119,6 +117,8 @@ module APND
|
|
119
117
|
end
|
120
118
|
|
121
119
|
notification
|
120
|
+
rescue
|
121
|
+
false
|
122
122
|
end
|
123
123
|
|
124
124
|
#
|
@@ -128,7 +128,7 @@ module APND
|
|
128
128
|
@token = params[:token]
|
129
129
|
@alert = params[:alert]
|
130
130
|
@badge = params[:badge]
|
131
|
-
@sound = params[:sound]
|
131
|
+
@sound = params[:sound]
|
132
132
|
@custom = params[:custom]
|
133
133
|
end
|
134
134
|
|
data/lib/apnd/version.rb
CHANGED
@@ -1,29 +1,41 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
context "APND
|
3
|
+
context "APND" do
|
4
4
|
setup do
|
5
5
|
@bytes = %|\000\000 \376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242\000;{"aps":{"sound":"default","alert":"Red Alert, Numba One!"}}|
|
6
6
|
@notification = APND::Notification.new({
|
7
7
|
:token => 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2',
|
8
|
-
:alert => 'Red Alert, Numba One!'
|
8
|
+
:alert => 'Red Alert, Numba One!',
|
9
|
+
:sound => 'default'
|
9
10
|
})
|
10
11
|
end
|
11
12
|
|
12
|
-
test "returns a
|
13
|
+
test "Notification returns a valid hex_token" do
|
13
14
|
expected = %|\376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242|
|
14
15
|
assert_equal @notification.hex_token, expected
|
15
16
|
end
|
16
17
|
|
17
|
-
test "returns a
|
18
|
+
test "Notification returns a valid byte string for Apple" do
|
18
19
|
assert_equal @notification.to_bytes, @bytes
|
19
20
|
end
|
20
21
|
|
21
|
-
test "returns a Notification
|
22
|
+
test "Notification.parse returns a Notification when given a valid string" do
|
22
23
|
notification = APND::Notification.parse(@bytes)
|
23
24
|
|
25
|
+
assert notification
|
26
|
+
|
24
27
|
[:alert, :badge, :custom, :sound, :token, :hex_token, :to_bytes, :aps, :aps_json].each do |key|
|
25
28
|
assert_equal @notification.send(key), notification.send(key)
|
26
29
|
end
|
30
|
+
|
31
|
+
assert ! APND::Notification.parse("I'm not a packet!")
|
32
|
+
end
|
33
|
+
|
34
|
+
test "Notification multiple apns to be sent" do
|
35
|
+
notifications = [@bytes, @bytes, @bytes].join("\n")
|
36
|
+
notifications.each_line do |line|
|
37
|
+
assert APND::Notification.valid?(line)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Priddle
|
@@ -81,8 +81,7 @@ files:
|
|
81
81
|
- lib/apnd/settings.rb
|
82
82
|
- lib/apnd/version.rb
|
83
83
|
- lib/apnd.rb
|
84
|
-
- test/
|
85
|
-
- test/notification_test.rb
|
84
|
+
- test/apnd_test.rb
|
86
85
|
- test/test_helper.rb
|
87
86
|
has_rdoc: true
|
88
87
|
homepage: http://github.com/itspriddle/apnd
|