mwotton-apnd 0.1.8
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.
- data/README.markdown +193 -0
- data/Rakefile +31 -0
- data/bin/apnd +35 -0
- data/lib/apnd.rb +33 -0
- data/lib/apnd/#notification.rb# +193 -0
- data/lib/apnd/cli.rb +195 -0
- data/lib/apnd/daemon.rb +78 -0
- data/lib/apnd/daemon/apple_connection.rb +84 -0
- data/lib/apnd/daemon/protocol.rb +54 -0
- data/lib/apnd/daemon/server_connection.rb +15 -0
- data/lib/apnd/errors.rb +22 -0
- data/lib/apnd/feedback.rb +65 -0
- data/lib/apnd/notification.rb +189 -0
- data/lib/apnd/settings.rb +205 -0
- data/lib/apnd/version.rb +11 -0
- data/test/apnd_test.rb +104 -0
- data/test/test_helper.rb +27 -0
- metadata +144 -0
data/lib/apnd/version.rb
ADDED
data/test/apnd_test.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class APNDTest < Test::Unit::TestCase
|
4
|
+
@@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\":{\"alert\":\"Red Alert, Numba One!\",\"badge\":10,\"sound\":\"default\"},\"location\":\"New York\"}|
|
5
|
+
|
6
|
+
context "APND Notification" do
|
7
|
+
setup do
|
8
|
+
@notification = APND::Notification.new({
|
9
|
+
:token => 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2',
|
10
|
+
:alert => 'Red Alert, Numba One!',
|
11
|
+
:sound => 'default',
|
12
|
+
:badge => 10,
|
13
|
+
:custom => { 'location' => 'New York' }
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
should "allow initialization with options hash" do
|
18
|
+
[:token, :alert, :sound, :badge, :custom].each do |key|
|
19
|
+
assert_not_nil @notification.send(key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
should "parse a raw packet" do
|
24
|
+
notification = APND::Notification.parse(@@bytes)
|
25
|
+
|
26
|
+
assert notification
|
27
|
+
|
28
|
+
[:alert, :badge, :custom, :sound, :token, :hex_token, :to_bytes, :aps, :aps_json].each do |key|
|
29
|
+
assert_equal @notification.send(key), notification.send(key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise InvalidPayload if custom hash is too large" do
|
34
|
+
assert_raise APND::Errors::InvalidPayload do
|
35
|
+
notification = @notification.dup
|
36
|
+
notification.custom = {
|
37
|
+
'lorem' => "Hi! " * 200
|
38
|
+
}
|
39
|
+
APND::Notification.parse(notification.to_bytes)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "instances" do
|
44
|
+
should "return a valid hex_token" do
|
45
|
+
expected = %|\376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242|
|
46
|
+
assert_equal @notification.hex_token, expected
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return a valid byte string" do
|
50
|
+
assert_equal @notification.to_bytes, @@bytes
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "APND Daemon" do
|
59
|
+
context "Protocol" do
|
60
|
+
setup do
|
61
|
+
@daemon = TestDaemon.new
|
62
|
+
end
|
63
|
+
|
64
|
+
should "add valid notification to queue" do
|
65
|
+
@daemon.receive_data(@@bytes)
|
66
|
+
@daemon.unbind
|
67
|
+
assert_equal 1, @daemon.queue.size
|
68
|
+
end
|
69
|
+
|
70
|
+
should "receive multiple Notifications in a single packet" do
|
71
|
+
@daemon.receive_data([@@bytes, @@bytes, @@bytes].join("\n"))
|
72
|
+
@daemon.unbind
|
73
|
+
assert_equal 3, @daemon.queue.size
|
74
|
+
end
|
75
|
+
|
76
|
+
should "raise InvalidNotificationHeader parsing a bad packet" do
|
77
|
+
assert_raise APND::Errors::InvalidNotificationHeader do
|
78
|
+
APND::Notification.parse("I'm not a packet!")
|
79
|
+
end
|
80
|
+
assert_equal 0, @daemon.queue.size
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
context "newlines" do
|
85
|
+
should "be able to parse a notification with an embedded newline character" do
|
86
|
+
@newline_notification = APND::Notification.new({
|
87
|
+
# :token => 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2',
|
88
|
+
:token => '74b2a2197d7727a70f939de05a4c7fe8bd4a7d960a77ef4701a80cb7b293ee23',
|
89
|
+
:alert => 'Red Alert, Numba One!',
|
90
|
+
:sound => 'default',
|
91
|
+
:badge => 10,
|
92
|
+
:custom => { 'location' => 'New York' }
|
93
|
+
})
|
94
|
+
@daemon.receive_data(@newline_notification.to_bytes)
|
95
|
+
@daemon.unbind
|
96
|
+
assert_equal 1, @daemon.queue.size
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'turn'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'apnd'
|
11
|
+
|
12
|
+
class TestDaemon
|
13
|
+
include APND::Daemon::Protocol
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@queue = []
|
17
|
+
@address = [123, '10.10.10.1']
|
18
|
+
end
|
19
|
+
|
20
|
+
def queue
|
21
|
+
@queue
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Silence APND.logger in testing
|
27
|
+
def APND.logger(*args); end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mwotton-apnd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joshua Priddle
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-22 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: eventmachine
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 59
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 12
|
33
|
+
- 10
|
34
|
+
version: 0.12.10
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: json
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 6
|
50
|
+
version: 1.4.6
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: daemons
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 1
|
65
|
+
- 0
|
66
|
+
version: 1.1.0
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
description: " APND (Apple Push Notification Daemon) is a ruby library to send Apple Push\n Notifications to iPhones.\n"
|
84
|
+
email: jpriddle@nevercraft.net
|
85
|
+
executables:
|
86
|
+
- apnd
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- README.markdown
|
91
|
+
files:
|
92
|
+
- Rakefile
|
93
|
+
- README.markdown
|
94
|
+
- bin/apnd
|
95
|
+
- lib/apnd/#notification.rb#
|
96
|
+
- lib/apnd/cli.rb
|
97
|
+
- lib/apnd/daemon/apple_connection.rb
|
98
|
+
- lib/apnd/daemon/protocol.rb
|
99
|
+
- lib/apnd/daemon/server_connection.rb
|
100
|
+
- lib/apnd/daemon.rb
|
101
|
+
- lib/apnd/errors.rb
|
102
|
+
- lib/apnd/feedback.rb
|
103
|
+
- lib/apnd/notification.rb
|
104
|
+
- lib/apnd/settings.rb
|
105
|
+
- lib/apnd/version.rb
|
106
|
+
- lib/apnd.rb
|
107
|
+
- test/apnd_test.rb
|
108
|
+
- test/test_helper.rb
|
109
|
+
has_rdoc: true
|
110
|
+
homepage: http://github.com/itspriddle/apnd
|
111
|
+
licenses: []
|
112
|
+
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options:
|
115
|
+
- --charset=UTF-8
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.3.7
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: "APND: Apple Push Notification Daemon sends Apple Push Notifications to iPhones"
|
143
|
+
test_files: []
|
144
|
+
|