bpoweski-apnserver 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,38 +1,38 @@
1
- h1. apnserver
1
+ h1. Apple Push Notification Server Toolkit
2
2
 
3
3
  * http://github.com/bpoweski/apnserver
4
4
 
5
- h2. DESCRIPTION:
5
+ h2. Description
6
6
 
7
7
  apnserver is a server and set of command line programs to send push notifications to the iPhone.
8
+ Apple recomends to maintain an open connection to the push notification service and refrain from
9
+ opening up and tearing down SSL connections reapeated. To solve this problem an intermediate
10
+ network server is introduced that queues are requests to the APN service and sends them via a
11
+ persistent connection.
8
12
 
9
13
 
10
- h2. FEATURES/PROBLEMS:
14
+ h2. APN Server Daemon
11
15
 
12
- * FIX (list of features or problems)
13
-
14
- h2. SYNOPSIS:
15
-
16
- Usagge: apnserverd [options] --pem /path/to/pem
17
16
 
18
17
  <pre>
19
18
  <code>
20
- --bind-address bind address (defaults to 0.0.0.0)</i>::
21
- bind address of the server daemon
22
-
19
+ Usage: apnserverd [options] --pem /path/to/pem
20
+ --bind-address bind address (defaults to 0.0.0.0)
21
+ bind address of the server daemon
22
+
23
23
  --proxy-port port
24
24
  the port that the daemon will listen on (defaults to 22195)
25
25
 
26
26
  --server server
27
- APN Server (defaults to gateway.push.apple.com)
27
+ APN Server (defaults to gateway.push.apple.com)
28
28
 
29
29
  --port port of the APN Server
30
30
  APN server port (defaults to 2195)
31
31
 
32
32
  --pem pem file path
33
- The PEM encoded private key and certificate.
34
- To export a PEM ecoded file execute
35
- # openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
33
+ The PEM encoded private key and certificate.
34
+ To export a PEM ecoded file execute
35
+ # openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
36
36
 
37
37
  --help
38
38
  usage message
@@ -43,19 +43,42 @@ Usagge: apnserverd [options] --pem /path/to/pem
43
43
  </code>
44
44
  </pre>
45
45
 
46
+ h2. APN Server Client
47
+
48
+ With the APN server client script you can send push notifications directly to
49
+ Apple's APN server over an SSL connection or to the above daemon using a plain socket.
50
+ To send a notification to Apple's APN server using SSL the *--pem* option must be used.
51
+
52
+ <pre>
53
+ <code>
54
+ Usage: apnsend [switches] (--b64-token | --hex-token) <token>
55
+ --server <localhost> the apn server defaults to a locally running apnserverd
56
+ --port <2195> the port of the apn server
57
+ --pem <path> the path to the pem file, if a pem is supplied the server
58
+ defaults to gateway.push.apple.com:2195
59
+ --alert <message> the message to send"
60
+ --sound <default> the sound to play, defaults to 'default'
61
+ --badge <number> the badge number
62
+ --custom <json string> a custom json string to be added to the main object
63
+ --b64-token <token> a base 64 encoded device token
64
+ --hex-token <token> a hex encoded device token
65
+ --help this message
66
+ </code>
67
+ </pre>
68
+
46
69
 
47
- h2. INSTALL:
70
+ h2. Installation
48
71
 
49
72
  To install apnserver execute the following gem command:
50
73
 
74
+ <pre>
51
75
  <code>
52
- </pre>
53
76
  $ gem install bpoweski-apnserver --source http://gems.github.com
54
- </pre>
55
77
  </code>
78
+ </pre>
56
79
 
57
80
 
58
- h2. LICENSE:
81
+ h2. License
59
82
 
60
83
  (The MIT License)
61
84
 
@@ -78,4 +101,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
78
101
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
79
102
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
80
103
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
81
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
104
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
data/apnserver.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apnserver}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Poweski"]
12
- s.date = %q{2009-09-15}
12
+ s.date = %q{2009-09-16}
13
13
  s.description = %q{A toolkit for proxying and sending Apple Push Notifications}
14
14
  s.email = %q{bpoweski@3factors.com}
15
15
  s.executables = ["apnsend", "apnserverd"]
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/apnserver/notification.rb",
29
29
  "lib/apnserver/payload.rb",
30
30
  "lib/apnserver/protocol.rb",
31
+ "lib/apnserver/sender.rb",
31
32
  "lib/apnserver/server.rb",
32
33
  "lib/apnserver/server_connection.rb",
33
34
  "test/test_client.rb",
data/bin/apnsend CHANGED
@@ -34,10 +34,7 @@ opts = GetoptLong.new(
34
34
  ["--help", "-h", GetoptLong::NO_ARGUMENT]
35
35
  )
36
36
 
37
- port = nil
38
- server = nil
39
37
  notification = ApnServer::Notification.new
40
- pem = nil
41
38
 
42
39
  opts.each do |opt, arg|
43
40
  case opt
@@ -45,11 +42,11 @@ opts.each do |opt, arg|
45
42
  usage
46
43
  exit
47
44
  when '--server'
48
- server = arg
45
+ ApnServer::Config.host = arg
49
46
  when '--port'
50
- port = arg
47
+ ApnServer::Config.port = arg.to_i
51
48
  when '--pem'
52
- pem = arg
49
+ ApnServer::Config.pem = arg
53
50
  when '--alert'
54
51
  notification.alert = arg
55
52
  when '--sound'
@@ -65,20 +62,9 @@ opts.each do |opt, arg|
65
62
  end
66
63
  end
67
64
 
68
-
69
65
  if notification.device_token.nil?
70
66
  usage
71
67
  exit
72
- end
73
-
74
- if pem.nil?
75
- @client = TCPSocket.new(server || 'localhost', port || 22195)
76
- @client.write(notification.to_bytes)
77
68
  else
78
- @client = ApnServer::Client.new(pem, server || 'gateway.push.apple.com', port || 2195)
79
- @client.connect!
80
- @client.write(notification)
69
+ notification.push
81
70
  end
82
-
83
-
84
-
@@ -3,11 +3,19 @@ require 'json'
3
3
 
4
4
  module ApnServer
5
5
 
6
+ class Config
7
+ class << self
8
+ attr_accessor :host, :port, :pem, :password
9
+ end
10
+ end
11
+
12
+
6
13
  class Notification
7
14
  include ApnServer::Payload
8
15
 
9
16
  attr_accessor :device_token, :alert, :badge, :sound, :custom
10
17
 
18
+
11
19
  def payload
12
20
  p = Hash.new
13
21
  [:badge, :alert, :sound, :custom].each do |k|
@@ -22,6 +30,17 @@ module ApnServer
22
30
  p
23
31
  end
24
32
 
33
+ def push
34
+ if Config.pem.nil?
35
+ socket = TCPSocket.new(Config.host || 'localhost', Config.port.to_i || 22195)
36
+ socket.write(notification.to_bytes)
37
+ else
38
+ client = ApnServer::Client.new(Config.pem, Config.host || 'gateway.push.apple.com', Config.port.to_i || 2195)
39
+ client.connect!
40
+ client.write(notification)
41
+ end
42
+ end
43
+
25
44
  def to_bytes
26
45
  json = json_payload
27
46
  [0, 0, device_token.size, device_token, 0, json.size, json].pack("ccca*cca*")
@@ -0,0 +1,6 @@
1
+ module ApnServer
2
+
3
+ module Sender
4
+
5
+ end
6
+ end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'stringio'
2
2
  require 'test/unit'
3
+ require 'rubygems'
3
4
  require File.dirname(__FILE__) + '/../lib/apnserver'
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.9
4
+ version: 0.0.10
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-15 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ files:
63
63
  - lib/apnserver/notification.rb
64
64
  - lib/apnserver/payload.rb
65
65
  - lib/apnserver/protocol.rb
66
+ - lib/apnserver/sender.rb
66
67
  - lib/apnserver/server.rb
67
68
  - lib/apnserver/server_connection.rb
68
69
  - test/test_client.rb