apnd 0.0.3 → 0.1.0
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 +32 -0
- data/lib/apnd/notification.rb +4 -4
- data/lib/apnd/version.rb +2 -2
- data/test/daemon_test.rb +3 -3
- data/test/notification_test.rb +24 -0
- metadata +2 -2
data/README.markdown
CHANGED
@@ -90,9 +90,41 @@ push notifications to APND.
|
|
90
90
|
)
|
91
91
|
|
92
92
|
|
93
|
+
## Prerequisites
|
94
|
+
|
95
|
+
You must have a valid Apple Push Notification Certificate for your iPhone
|
96
|
+
application. Obtain your APN certificate from the iPhone Provisioning Portal
|
97
|
+
at [developer.apple.com](http://developer.apple.com/).
|
98
|
+
|
99
|
+
|
100
|
+
## Requirements
|
101
|
+
|
102
|
+
* [EventMachine](http://github.com/eventmachine/eventmachine)
|
103
|
+
* [Daemons](http://github.com/ghazel/daemons)
|
104
|
+
* [JSON](http://github.com/flori/json)
|
105
|
+
|
106
|
+
Ruby must be compiled with OpenSSL support.
|
107
|
+
|
108
|
+
|
109
|
+
## Installation
|
110
|
+
|
111
|
+
RubyGems:
|
112
|
+
|
113
|
+
gem install apnd
|
114
|
+
|
115
|
+
Git:
|
116
|
+
|
117
|
+
git clone git://github.com/itspriddle/apnd.git
|
118
|
+
|
119
|
+
|
93
120
|
## Credit
|
94
121
|
|
95
122
|
APND is based on [apnserver](http://github.com/bpoweski/apnserver) and
|
96
123
|
[apn_on_rails](http://github.com/PRX/apn_on_rails). Either worked just how I
|
97
124
|
wanted, so I rolled my own using theirs as starting points. If APND doesn't
|
98
125
|
suit you, check them out instead.
|
126
|
+
|
127
|
+
|
128
|
+
## Copyright
|
129
|
+
|
130
|
+
Copyright (c) 2010 Joshua Priddle. See LICENSE for details.
|
data/lib/apnd/notification.rb
CHANGED
@@ -120,11 +120,11 @@ module APND
|
|
120
120
|
#
|
121
121
|
# Returns the Notification's aps hash as json
|
122
122
|
#
|
123
|
-
def
|
124
|
-
return @
|
123
|
+
def aps_json
|
124
|
+
return @aps_json if @aps_json
|
125
125
|
json = aps.to_json
|
126
126
|
raise APND::InvalidPayload.new(json) if json.size > 256
|
127
|
-
@
|
127
|
+
@aps_json = json
|
128
128
|
end
|
129
129
|
|
130
130
|
#
|
@@ -132,7 +132,7 @@ module APND
|
|
132
132
|
# to Apple
|
133
133
|
#
|
134
134
|
def to_bytes
|
135
|
-
@bytes ||= "\0\0 %s\0%s%s" % [hex_token,
|
135
|
+
@bytes ||= "\0\0 %s\0%s%s" % [hex_token, aps_json.length.chr, aps_json]
|
136
136
|
end
|
137
137
|
|
138
138
|
end
|
data/lib/apnd/version.rb
CHANGED
data/test/daemon_test.rb
CHANGED
data/test/notification_test.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
context "APND Notification" do
|
4
|
+
setup do
|
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
|
+
@notification = APND::Notification.new({
|
7
|
+
:token => 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2',
|
8
|
+
:alert => 'Red Alert, Numba One!'
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
test "returns a properly formatted hex_token" do
|
13
|
+
expected = %|\376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242|
|
14
|
+
assert_equal @notification.hex_token, expected
|
15
|
+
end
|
16
|
+
|
17
|
+
test "returns a properly formatted byte string for Apple" do
|
18
|
+
assert_equal @notification.to_bytes, @bytes
|
19
|
+
end
|
20
|
+
|
21
|
+
test "returns a Notification object when given valid byte string" do
|
22
|
+
notification = APND::Notification.parse(@bytes)
|
23
|
+
|
24
|
+
[:alert, :badge, :custom, :sound, :token, :hex_token, :to_bytes, :aps, :aps_json].each do |key|
|
25
|
+
assert_equal @notification.send(key), notification.send(key)
|
26
|
+
end
|
27
|
+
end
|
4
28
|
|
5
29
|
end
|