bpoweski-apnserver 0.0.7 → 0.0.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/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gemspec.authors = ["Ben Poweski"]
12
12
  gemspec.add_dependency 'eventmachine'
13
13
  gemspec.add_dependency 'daemons'
14
+ gemspec.add_dependency 'json'
14
15
  gemspec.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
15
16
  end
16
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/apnserver.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apnserver}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
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"]
@@ -17,9 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- "History.txt",
21
- "Manifest.txt",
22
- "README.rdoc",
20
+ "README.rdoc",
23
21
  "Rakefile",
24
22
  "VERSION",
25
23
  "apnserver.gemspec",
@@ -58,12 +56,15 @@ Gem::Specification.new do |s|
58
56
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
57
  s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
60
58
  s.add_runtime_dependency(%q<daemons>, [">= 0"])
59
+ s.add_runtime_dependency(%q<json>, [">= 0"])
61
60
  else
62
61
  s.add_dependency(%q<eventmachine>, [">= 0"])
63
62
  s.add_dependency(%q<daemons>, [">= 0"])
63
+ s.add_dependency(%q<json>, [">= 0"])
64
64
  end
65
65
  else
66
66
  s.add_dependency(%q<eventmachine>, [">= 0"])
67
67
  s.add_dependency(%q<daemons>, [">= 0"])
68
+ s.add_dependency(%q<json>, [">= 0"])
68
69
  end
69
70
  end
data/bin/apnsend CHANGED
@@ -37,7 +37,6 @@ opts = GetoptLong.new(
37
37
  port = nil
38
38
  server = nil
39
39
  notification = ApnServer::Notification.new
40
- token = nil
41
40
  pem = nil
42
41
 
43
42
  opts.each do |opt, arg|
@@ -60,24 +59,26 @@ opts.each do |opt, arg|
60
59
  when '--custom'
61
60
  notification.custom = arg
62
61
  when '--b64-token'
63
- token = Base64::decode64(arg)
62
+ notification.device_token = Base64::decode64(arg)
64
63
  when '--hex-token'
65
- token = arg.unpack('H*')
64
+ notification.device_token = arg.unpack('H*')
66
65
  end
67
66
  end
68
67
 
69
68
 
70
- if token.nil?
69
+ if notification.device_token.nil?
71
70
  usage
72
71
  exit
73
72
  end
74
73
 
75
74
  if pem.nil?
76
75
  @client = TCPSocket.new(server || 'localhost', port || 22195)
76
+ @client.write(notification.to_bytes)
77
77
  else
78
78
  @client = ApnServer::Client.new(pem, server || 'gateway.push.apple.com', port || 2195)
79
+ @client.connect!
80
+ @client.write(notification)
79
81
  end
80
82
 
81
- @client.write(notification.to_bytes)
82
83
 
83
84
 
data/bin/apnserverd CHANGED
@@ -15,20 +15,32 @@ def usage
15
15
  puts " --help this message"
16
16
  end
17
17
 
18
+ def daemonize
19
+ Daemonize.daemonize('apnserverd', 'apnserverd')
20
+ @pid_file = '/var/run/apnserverd.pid'
21
+ open(@pid_file,"w") {|f| f.write(Process.pid) } # copied from mongrel
22
+ open(@pid_file,"w") do |f|
23
+ f.write(Process.pid)
24
+ File.chmod(0644, @pid_file)
25
+ end
26
+ end
27
+
18
28
  opts = GetoptLong.new(
19
29
  ["--bind-address", "-b", GetoptLong::REQUIRED_ARGUMENT],
20
30
  ["--proxy-port", "-P", GetoptLong::REQUIRED_ARGUMENT],
21
31
  ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT],
22
32
  ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT],
23
33
  ["--pem", "-c", GetoptLong::REQUIRED_ARGUMENT],
24
- ["--help", "-h", GetoptLong::NO_ARGUMENT]
34
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
35
+ ["--daemon", "-d", GetoptLong::NO_ARGUMENT]
25
36
  )
26
37
 
27
38
  bind_address = '0.0.0.0'
28
39
  proxy_port = 22195
29
- server = 'gateway.push.apple.com'
40
+ host = 'gateway.push.apple.com'
30
41
  port = 2295
31
42
  pem = nil
43
+ daemon = false
32
44
 
33
45
  opts.each do |opt, arg|
34
46
  case opt
@@ -37,13 +49,15 @@ opts.each do |opt, arg|
37
49
  when '--bind-address'
38
50
  bind_address = arg
39
51
  when '--proxy-port'
40
- proxy_port = arg.to_i
52
+ proxy_port = arg.to_i
41
53
  when '--server'
42
- server = arg
54
+ host = arg
43
55
  when '--port'
44
- port = arg
56
+ port = arg.to_i
45
57
  when '--pem'
46
58
  pem = arg
59
+ when '--daemon'
60
+ daemon = true
47
61
  end
48
62
  end
49
63
 
@@ -51,13 +65,9 @@ if pem.nil?
51
65
  usage
52
66
  exit 1
53
67
  else
54
- Daemonize.daemonize('apnserverd', 'apnserverd')
55
- @pid_file = '/var/run/apnserverd.pid'
56
- open(@pid_file,"w") {|f| f.write(Process.pid) } # copied from mongrel
57
- open(@pid_file,"w") do |f|
58
- f.write(Process.pid)
59
- File.chmod(0644, @pid_file)
60
- end
68
+ daemonize if daemon
61
69
  server = ApnServer::Server.new(pem, bind_address, proxy_port)
70
+ server.client.host = host
71
+ server.client.port = port
62
72
  server.start!
63
73
  end
@@ -18,7 +18,7 @@ module ApnServer
18
18
  @context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem))
19
19
  @context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.password)
20
20
 
21
- @sock = TCPSocket.new(self.host, self.port)
21
+ @sock = TCPSocket.new(self.host, self.port.to_i)
22
22
  @ssl = OpenSSL::SSL::SSLSocket.new(@sock, @context)
23
23
  @ssl.connect
24
24
 
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Poweski
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
35
45
  description: A toolkit for proxying and sending Apple Push Notifications
36
46
  email: bpoweski@3factors.com
37
47
  executables:
@@ -42,8 +52,6 @@ extensions: []
42
52
  extra_rdoc_files:
43
53
  - README.rdoc
44
54
  files:
45
- - History.txt
46
- - Manifest.txt
47
55
  - README.rdoc
48
56
  - Rakefile
49
57
  - VERSION
data/History.txt DELETED
@@ -1,4 +0,0 @@
1
- === 0.0.1 2009-09-10
2
-
3
- * 1 major enhancement:
4
- * Initial release
data/Manifest.txt DELETED
@@ -1,23 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README
5
- README.rdoc
6
- Rakefile
7
- bin/apns
8
- bin/apnserverd
9
- lib/apnserver.rb
10
- lib/apnserver/client.rb
11
- lib/apnserver/notification.rb
12
- lib/apnserver/payload.rb
13
- lib/apnserver/server.rb
14
- script/console
15
- script/console.cmd
16
- script/destroy
17
- script/destroy.cmd
18
- script/generate
19
- script/generate.cmd
20
- test/notification_test.rb
21
- test/payload_test.rb
22
- test/test_apnserver.rb
23
- test/test_helper.rb