bpoweski-apnserver 0.0.12 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +58 -2
- data/VERSION +1 -1
- data/apnserver.gemspec +71 -0
- data/bin/apnsend +4 -0
- data/bin/apnserverd +3 -0
- data/bin/apnserverd.fedora.init +71 -0
- data/lib/apnserver/client.rb +1 -1
- data/lib/apnserver/protocol.rb +2 -2
- data/lib/apnserver/server.rb +1 -1
- data/lib/apnserver.rb +1 -0
- metadata +5 -3
- data/lib/apnserver/sender.rb +0 -6
data/README.textile
CHANGED
@@ -10,9 +10,13 @@ opening up and tearing down SSL connections reapeated. To solve this problem an
|
|
10
10
|
network server is introduced that queues are requests to the APN service and sends them via a
|
11
11
|
persistent connection.
|
12
12
|
|
13
|
+
h2. TODO
|
14
|
+
|
15
|
+
* Implement feedback service mechanism
|
16
|
+
* Investigate possible badge number issue
|
17
|
+
* Implement a robust logging mechanism for transactions
|
13
18
|
|
14
19
|
h2. APN Server Daemon
|
15
|
-
|
16
20
|
|
17
21
|
<pre>
|
18
22
|
<code>
|
@@ -66,6 +70,51 @@ Usage: apnsend [switches] (--b64-token | --hex-token) <token>
|
|
66
70
|
</code>
|
67
71
|
</pre>
|
68
72
|
|
73
|
+
To send a base64 encoded push notification via the command line execute the following:
|
74
|
+
|
75
|
+
<pre>
|
76
|
+
<code>
|
77
|
+
$ apnsend --server gateway.push.apple.com --port 2195 --pem key.pem \
|
78
|
+
--b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= --sound default \
|
79
|
+
--alert Hello
|
80
|
+
</code>
|
81
|
+
</pre>
|
82
|
+
|
83
|
+
h2. Sending Notifications from Ruby
|
84
|
+
|
85
|
+
To configure the client to send to the local apnserverd process configure the ApnServer client with the following.
|
86
|
+
|
87
|
+
<pre>
|
88
|
+
<code>
|
89
|
+
# configured for a using the apnserverd proxy
|
90
|
+
ApnServer::Config.host = 'localhost'
|
91
|
+
ApnServer::Config.port = 22195
|
92
|
+
</code>
|
93
|
+
</pre>
|
94
|
+
|
95
|
+
To configure the client to send directly to Apple's push notification server, bypassing the apnserverd process configure the following.
|
96
|
+
|
97
|
+
<pre>
|
98
|
+
<code>
|
99
|
+
ApnServer::Config.pem = '/path/to/pem'
|
100
|
+
ApnServer::Config.host = 'gateway.push.apple.com'
|
101
|
+
ApnServer::Config.port = 2195
|
102
|
+
</code>
|
103
|
+
</pre>
|
104
|
+
|
105
|
+
Finally within we can send a push notification using the following code
|
106
|
+
|
107
|
+
<pre>
|
108
|
+
<code>
|
109
|
+
notification = ApnServer::Notification.new
|
110
|
+
notification.device_token = Base64.decode64(apns_token) # if base64 encoded
|
111
|
+
notification.alert = message
|
112
|
+
notification.badge = 1
|
113
|
+
notification.sound = 'default'
|
114
|
+
notification.push
|
115
|
+
</code>
|
116
|
+
</pre>
|
117
|
+
|
69
118
|
|
70
119
|
h2. Installation
|
71
120
|
|
@@ -76,7 +125,14 @@ To install apnserver execute the following gem command:
|
|
76
125
|
$ gem install bpoweski-apnserver --source http://gems.github.com
|
77
126
|
</code>
|
78
127
|
</pre>
|
79
|
-
|
128
|
+
|
129
|
+
Adding apnserver to your Rails application
|
130
|
+
|
131
|
+
<pre>
|
132
|
+
<code>
|
133
|
+
config.gem "bpoweski-apnserver", :lib => 'apnserver', :source => "http://gems.github.com"
|
134
|
+
</code>
|
135
|
+
</pre>
|
80
136
|
|
81
137
|
h2. License
|
82
138
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.14
|
data/apnserver.gemspec
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{apnserver}
|
8
|
+
s.version = "0.0.14"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ben Poweski"]
|
12
|
+
s.date = %q{2009-09-17}
|
13
|
+
s.description = %q{A toolkit for proxying and sending Apple Push Notifications}
|
14
|
+
s.email = %q{bpoweski@3factors.com}
|
15
|
+
s.executables = ["apnsend", "apnserverd", "apnserverd.fedora.init"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"README.textile",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"apnserver.gemspec",
|
24
|
+
"bin/apnsend",
|
25
|
+
"bin/apnserverd",
|
26
|
+
"bin/apnserverd.fedora.init",
|
27
|
+
"lib/apnserver.rb",
|
28
|
+
"lib/apnserver/client.rb",
|
29
|
+
"lib/apnserver/notification.rb",
|
30
|
+
"lib/apnserver/payload.rb",
|
31
|
+
"lib/apnserver/protocol.rb",
|
32
|
+
"lib/apnserver/server.rb",
|
33
|
+
"lib/apnserver/server_connection.rb",
|
34
|
+
"test/test_client.rb",
|
35
|
+
"test/test_helper.rb",
|
36
|
+
"test/test_notification.rb",
|
37
|
+
"test/test_payload.rb",
|
38
|
+
"test/test_protocol.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/bpoweski/apnserver}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.5}
|
44
|
+
s.summary = %q{Apple Push Notification Server}
|
45
|
+
s.test_files = [
|
46
|
+
"test/test_client.rb",
|
47
|
+
"test/test_helper.rb",
|
48
|
+
"test/test_notification.rb",
|
49
|
+
"test/test_payload.rb",
|
50
|
+
"test/test_protocol.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<daemons>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
63
|
+
s.add_dependency(%q<daemons>, [">= 0"])
|
64
|
+
s.add_dependency(%q<json>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
68
|
+
s.add_dependency(%q<daemons>, [">= 0"])
|
69
|
+
s.add_dependency(%q<json>, [">= 0"])
|
70
|
+
end
|
71
|
+
end
|
data/bin/apnsend
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
|
4
|
+
require 'logger'
|
4
5
|
require 'getoptlong'
|
5
6
|
require 'rubygems'
|
6
7
|
gem 'bpoweski-apnserver'
|
@@ -8,6 +9,9 @@ require 'apnserver'
|
|
8
9
|
require 'base64'
|
9
10
|
require 'socket'
|
10
11
|
|
12
|
+
$logger = Logger.new(STDOUT)
|
13
|
+
|
14
|
+
|
11
15
|
def usage
|
12
16
|
puts "Usage: apnsend [switches] (--b64-token | --hex-token) <token>"
|
13
17
|
puts " --server <localhost> the apn server defaults to a locally running apnserverd"
|
data/bin/apnserverd
CHANGED
@@ -6,6 +6,8 @@ require 'rubygems'
|
|
6
6
|
require 'daemons'
|
7
7
|
require 'apnserver'
|
8
8
|
|
9
|
+
$logger = Logger.new(STDOUT)
|
10
|
+
|
9
11
|
def usage
|
10
12
|
puts "Usage: apnserverd [switches] --pem <path>"
|
11
13
|
puts " --bind-address [0.0.0.0] bind address of proxy"
|
@@ -58,6 +60,7 @@ opts.each do |opt, arg|
|
|
58
60
|
pem = arg
|
59
61
|
when '--daemon'
|
60
62
|
daemon = true
|
63
|
+
$logger = Logger.new('/var/log/apnserverd.log', 'weekly')
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# /etc/rc.d/init.d/apnserverd
|
4
|
+
# apnserverd This shell script takes care of starting and stopping
|
5
|
+
# the APN Server Proxy
|
6
|
+
#
|
7
|
+
# chkconfig: 345 20 80
|
8
|
+
# Author: Ben Poweski bpoweski@gmail.com
|
9
|
+
#
|
10
|
+
# Source function library.
|
11
|
+
. /etc/init.d/functions
|
12
|
+
|
13
|
+
NAME=apnserverd
|
14
|
+
APNSERVERD=/usr/bin/$NAME
|
15
|
+
PIDFILE=/var/run/$NAME.pid
|
16
|
+
|
17
|
+
if [ -f /etc/sysconfig/$NAME ]; then
|
18
|
+
. /etc/sysconfig/$NAME
|
19
|
+
fi
|
20
|
+
|
21
|
+
|
22
|
+
start() {
|
23
|
+
echo -n "Starting APN Server: "
|
24
|
+
if [ -f $PIDFILE ]; then
|
25
|
+
PID=`cat $PIDFILE`
|
26
|
+
echo $NAME already running: $PID
|
27
|
+
exit 2;
|
28
|
+
elif [ -f $PIDFILE ]; then
|
29
|
+
PID=`cat $PIDFILE`
|
30
|
+
echo $NAME already running: $PID
|
31
|
+
exit 2;
|
32
|
+
else
|
33
|
+
daemon $APNSERVERD $OPTIONS
|
34
|
+
RETVAL=$?
|
35
|
+
echo
|
36
|
+
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME
|
37
|
+
return $RETVAL
|
38
|
+
fi
|
39
|
+
|
40
|
+
}
|
41
|
+
|
42
|
+
stop() {
|
43
|
+
echo -n "Shutting down APN Server: "
|
44
|
+
echo
|
45
|
+
kill `cat $PIDFILE`
|
46
|
+
echo
|
47
|
+
rm -f /var/lock/subsys/$NAME
|
48
|
+
rm -f $PIDFILE
|
49
|
+
return 0
|
50
|
+
}
|
51
|
+
|
52
|
+
case "$1" in
|
53
|
+
start)
|
54
|
+
start
|
55
|
+
;;
|
56
|
+
stop)
|
57
|
+
stop
|
58
|
+
;;
|
59
|
+
status)
|
60
|
+
status $NAME
|
61
|
+
;;
|
62
|
+
restart)
|
63
|
+
stop
|
64
|
+
start
|
65
|
+
;;
|
66
|
+
*)
|
67
|
+
echo "Usage: {start|stop|status|restart}"
|
68
|
+
exit 1
|
69
|
+
;;
|
70
|
+
esac
|
71
|
+
exit $?
|
data/lib/apnserver/client.rb
CHANGED
@@ -31,7 +31,7 @@ module ApnServer
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def write(notification)
|
34
|
-
|
34
|
+
$logger.info "[#{host}:#{port}] Device: #{notification.device_token.unpack('H*')} sending #{notification.json_payload}"
|
35
35
|
@ssl.write(notification.to_bytes)
|
36
36
|
end
|
37
37
|
|
data/lib/apnserver/protocol.rb
CHANGED
@@ -3,11 +3,11 @@ module ApnServer
|
|
3
3
|
|
4
4
|
def post_init
|
5
5
|
@address = Socket.unpack_sockaddr_in(self.get_peername)
|
6
|
-
|
6
|
+
$logger.debug "[#{address.last}:#{address.first}] CONNECT"
|
7
7
|
end
|
8
8
|
|
9
9
|
def unbind
|
10
|
-
|
10
|
+
$logger.debug "[#{address.last}:#{address.first}] DISCONNECT"
|
11
11
|
end
|
12
12
|
|
13
13
|
def receive_data(data)
|
data/lib/apnserver/server.rb
CHANGED
@@ -11,7 +11,7 @@ module ApnServer
|
|
11
11
|
|
12
12
|
def start!
|
13
13
|
EventMachine::run do
|
14
|
-
|
14
|
+
$logger.info "Starting APN Server on #{bind_address}:#{port}"
|
15
15
|
|
16
16
|
EM.start_server(bind_address, port, ApnServer::ServerConnection) do |s|
|
17
17
|
s.queue = @queue
|
data/lib/apnserver.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bpoweski-apnserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Poweski
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,7 @@ email: bpoweski@3factors.com
|
|
47
47
|
executables:
|
48
48
|
- apnsend
|
49
49
|
- apnserverd
|
50
|
+
- apnserverd.fedora.init
|
50
51
|
extensions: []
|
51
52
|
|
52
53
|
extra_rdoc_files:
|
@@ -55,14 +56,15 @@ files:
|
|
55
56
|
- README.textile
|
56
57
|
- Rakefile
|
57
58
|
- VERSION
|
59
|
+
- apnserver.gemspec
|
58
60
|
- bin/apnsend
|
59
61
|
- bin/apnserverd
|
62
|
+
- bin/apnserverd.fedora.init
|
60
63
|
- lib/apnserver.rb
|
61
64
|
- lib/apnserver/client.rb
|
62
65
|
- lib/apnserver/notification.rb
|
63
66
|
- lib/apnserver/payload.rb
|
64
67
|
- lib/apnserver/protocol.rb
|
65
|
-
- lib/apnserver/sender.rb
|
66
68
|
- lib/apnserver/server.rb
|
67
69
|
- lib/apnserver/server_connection.rb
|
68
70
|
- test/test_client.rb
|