apnmachine 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem "em-synchrony"
4
4
  gem "daemons"
5
5
  gem "activesupport", ">= 3.0.0"
6
6
  gem "redis", ">= 2.2.0"
7
+ gem "hiredis", ">= 0.3.1"
7
8
  gem "i18n"
8
9
 
9
10
  # Add dependencies to develop your gem here.
@@ -1,4 +1,4 @@
1
- h1. Apple Push Notification Server Toolkit
1
+ h1. Apn Server & Library for Ruby
2
2
 
3
3
  * http://github.com/jnak/apnmachine
4
4
 
@@ -20,18 +20,18 @@ h2. Remaining Tasks
20
20
  * Implement feedback service mechanism
21
21
  * Write real tests
22
22
 
23
- h2. APN Server Daemon
23
+ h2. ApnMachine Daemon
24
24
 
25
25
  To start ApnMachine, tell it where is your redis server and the complete path to your PEM file.
26
26
  That's it.
27
27
 
28
28
  <pre>
29
29
  <code>
30
- Usage: apnmachined [options] --pem /path/to/pem
31
- --address bind address (defaults to 127.0.0.1)
30
+ Usage: apnmachined [options] --pem /full/path/to/pem
31
+ --redis-host bind address (defaults to 127.0.0.1)
32
32
  address of your redis server
33
33
 
34
- --port port
34
+ --redis-port port
35
35
  the port of your redis server (defaults to)
36
36
 
37
37
  --apn-address server
@@ -105,28 +105,6 @@ Adding apnmachine to your Rails application
105
105
 
106
106
  h2. License
107
107
 
108
+ The MIT License - Copyright (c) 2012 Julien Nakache
108
109
  Widely Inspired from groupme/em-apn and bpoweski/apnserver
109
110
 
110
- (The MIT License)
111
-
112
- Copyright (c) 2012 Julien Nakache
113
-
114
- Permission is hereby granted, free of charge, to any person obtaining
115
- a copy of this software and associated documentation files (the
116
- 'Software'), to deal in the Software without restriction, including
117
- without limitation the rights to use, copy, modify, merge, publish,
118
- distribute, sublicense, and/or sell copies of the Software, and to
119
- permit persons to whom the Software is furnished to do so, subject to
120
- the following conditions:
121
-
122
- The above copyright notice and this permission notice shall be
123
- included in all copies or substantial portions of the Software.
124
-
125
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
126
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
127
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
128
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
129
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
130
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
131
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
132
-
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ end
12
12
  require 'rake'
13
13
 
14
14
  require 'jeweler'
15
+ require './lib/apnmachine/version.rb'
15
16
  Jeweler::Tasks.new do |gem|
16
17
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
18
  gem.name = "apnmachine"
@@ -21,6 +22,7 @@ Jeweler::Tasks.new do |gem|
21
22
  gem.description = %Q{An APN server & library in which EventMachine daemons maintain a persistent connection to Apple servers and Redis acts as the glue with your Apps. See Readme for more info :)}
22
23
  gem.email = "julien.nakache@gmail.com"
23
24
  gem.authors = ["Julien Nakache"]
25
+ gem.version = ApnMachine::VERSION
24
26
  # dependencies defined in Gemfile
25
27
  end
26
28
  Jeweler::RubygemsDotOrgTasks.new
@@ -4,37 +4,28 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{apnmachine}
8
- s.version = "0.1.0"
7
+ s.name = "apnmachine"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Julien Nakache}]
12
- s.date = %q{2012-02-21}
13
- s.description = %q{An APN server & library in which EventMachine daemons maintain a persistent connection to Apple servers and Redis acts as the glue with your Apps. See Readme for more info :)}
14
- s.email = %q{julien.nakache@gmail.com}
15
- s.executables = [%q{apnmachined}]
11
+ s.authors = ["Julien Nakache"]
12
+ s.date = "2012-02-21"
13
+ s.description = "An APN server & library in which EventMachine daemons maintain a persistent connection to Apple servers and Redis acts as the glue with your Apps. See Readme for more info :)"
14
+ s.email = "julien.nakache@gmail.com"
15
+ s.executables = ["apnmachined"]
16
16
  s.extra_rdoc_files = [
17
- "LICENSE.txt",
18
17
  "README.textile"
19
18
  ]
20
19
  s.files = [
21
- ".DS_Store",
22
- ".document",
23
20
  "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE.txt",
26
21
  "README.textile",
27
22
  "Rakefile",
28
- "VERSION",
29
23
  "apnmachine.gemspec",
30
24
  "bin/apnmachined",
31
- "lib/.DS_Store",
32
25
  "lib/apnmachine.rb",
33
- "lib/apnmachine/.DS_Store",
34
26
  "lib/apnmachine/config.rb",
35
27
  "lib/apnmachine/notification.rb",
36
28
  "lib/apnmachine/server.rb",
37
- "lib/apnmachine/server/.DS_Store",
38
29
  "lib/apnmachine/server/client.rb",
39
30
  "lib/apnmachine/server/error_response.rb",
40
31
  "lib/apnmachine/server/response.rb",
@@ -44,11 +35,11 @@ Gem::Specification.new do |s|
44
35
  "test/helper.rb",
45
36
  "test/test_apnmachine.rb"
46
37
  ]
47
- s.homepage = %q{http://github.com/jnak/apnmachine}
48
- s.licenses = [%q{MIT}]
49
- s.require_paths = [%q{lib}]
50
- s.rubygems_version = %q{1.8.5}
51
- s.summary = %q{An APN server & library built on top of Redis and EventMachine}
38
+ s.homepage = "http://github.com/jnak/apnmachine"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.17"
42
+ s.summary = "An APN server & library built on top of Redis and EventMachine"
52
43
 
53
44
  if s.respond_to? :specification_version then
54
45
  s.specification_version = 3
@@ -58,6 +49,7 @@ Gem::Specification.new do |s|
58
49
  s.add_runtime_dependency(%q<daemons>, [">= 0"])
59
50
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
60
51
  s.add_runtime_dependency(%q<redis>, [">= 2.2.0"])
52
+ s.add_runtime_dependency(%q<hiredis>, [">= 0.3.1"])
61
53
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
62
54
  s.add_development_dependency(%q<shoulda>, [">= 0"])
63
55
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -69,6 +61,7 @@ Gem::Specification.new do |s|
69
61
  s.add_dependency(%q<daemons>, [">= 0"])
70
62
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
71
63
  s.add_dependency(%q<redis>, [">= 2.2.0"])
64
+ s.add_dependency(%q<hiredis>, [">= 0.3.1"])
72
65
  s.add_dependency(%q<i18n>, [">= 0"])
73
66
  s.add_dependency(%q<shoulda>, [">= 0"])
74
67
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -81,6 +74,7 @@ Gem::Specification.new do |s|
81
74
  s.add_dependency(%q<daemons>, [">= 0"])
82
75
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
83
76
  s.add_dependency(%q<redis>, [">= 2.2.0"])
77
+ s.add_dependency(%q<hiredis>, [">= 0.3.1"])
84
78
  s.add_dependency(%q<i18n>, [">= 0"])
85
79
  s.add_dependency(%q<shoulda>, [">= 0"])
86
80
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
3
 
3
4
  require 'getoptlong'
4
5
  require 'daemons'
@@ -7,7 +8,7 @@ require 'apnmachine/server'
7
8
 
8
9
  def usage
9
10
  puts "Usage: apnmchined [switches] --pem <path>"
10
- puts " --redis-address [127.0.0.1] bind address of proxy"
11
+ puts " --redis-host [127.0.0.1] bind address of proxy"
11
12
  puts " --redis-port [6379] port proxy listens on"
12
13
  puts " --server <gateway.push.apple.com> the apn server to send messages to"
13
14
  puts " --log </var/log/apnmachined.log the path to store the log"
@@ -26,19 +27,23 @@ def daemonize
26
27
  end
27
28
 
28
29
  opts = GetoptLong.new(
29
- ["--redis-address", "-b", GetoptLong::REQUIRED_ARGUMENT],
30
+ ["--redis-host", "-a", GetoptLong::REQUIRED_ARGUMENT],
30
31
  ["--redis-port", "-p", GetoptLong::REQUIRED_ARGUMENT],
31
- ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT],
32
+ ["--apn-host", "-b", GetoptLong::REQUIRED_ARGUMENT],
33
+ ["--apn-port", "-q", GetoptLong::REQUIRED_ARGUMENT],
32
34
  ["--log", "-l", GetoptLong::REQUIRED_ARGUMENT],
33
- ["--pem", "-c", GetoptLong::REQUIRED_ARGUMENT],
35
+ ["--pem", "-c", GetoptLong::REQUIRED_ARGUMENT],
36
+ ["--pem-passphrase", "-s", GetoptLong::REQUIRED_ARGUMENT],
34
37
  ["--daemon", "-d", GetoptLong::NO_ARGUMENT],
35
38
  ["--help", "-h", GetoptLong::NO_ARGUMENT]
36
39
  )
37
40
 
38
- redis_address = '127.0.0.1'
41
+ redis_host = '127.0.0.1'
39
42
  redis_port = 6379
40
- host = 'gateway.push.apple.com'
43
+ apn_host = 'gateway.push.apple.com'
44
+ apn_port = 2195
41
45
  pem = nil
46
+ pem_passphrase = nil
42
47
  daemon = false
43
48
  log = STDOUT
44
49
 
@@ -47,18 +52,22 @@ opts.each do |opt, arg|
47
52
  when '--help'
48
53
  usage
49
54
  exit 1
50
- when '--redis-address'
51
- redis_address = arg
52
- when '--port'
55
+ when '--redis-host'
56
+ redis_host = arg
57
+ when '--redis-port'
53
58
  redis_port = arg.to_i
54
- when '--server'
59
+ when '--apn_host'
55
60
  if arg == 'sandbox'
56
- host = 'gateway.sandbox.push.apple.com'
61
+ apn_host = 'gateway.sandbox.push.apple.com'
57
62
  else
58
- raise 'Wrong --server option. Pass "sandbox" as option to override production servers'
63
+ apn_host = arg
59
64
  end
65
+ when '--apn-port'
66
+ apn_port = arg
60
67
  when '--pem'
61
68
  pem = arg
69
+ when '--pem-passphrase'
70
+ pem_passphrase = arg
62
71
  when '--daemon'
63
72
  daemon = true
64
73
  when '--log'
@@ -71,6 +80,6 @@ if pem.nil?
71
80
  exit 1
72
81
  else
73
82
  daemonize if daemon
74
- server = ApnMachine::Server::Server.new(pem, redis_address, redis_port, log)
83
+ server = ApnMachine::Server::Server.new(pem, pem_passphrase, redis_host, redis_port, apn_host, apn_port, log)
75
84
  server.start!
76
85
  end
@@ -3,5 +3,4 @@ require 'active_support/ordered_hash'
3
3
  require 'active_support/json'
4
4
  require 'logger'
5
5
  require 'apnmachine/config'
6
- require 'apnmachine/notification'
7
-
6
+ require 'apnmachine/notification'
@@ -1,4 +1,3 @@
1
- require 'openssl'
2
1
  require 'em-synchrony'
3
2
  require 'redis/connection/synchrony'
4
3
  require 'redis'
@@ -1,17 +1,17 @@
1
1
  module ApnMachine
2
2
  module Server
3
3
  class Client
4
- attr_accessor :pem, :host, :port, :password, :key, :cert, :close_callback
4
+ attr_accessor :pem, :apn_host, :apn_port, :password, :key, :cert, :close_callback
5
5
 
6
- def initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil)
7
- @pem, @host, @port, @password = pem, host, port, pass
6
+ def initialize(pem, password = nil, apn_host = 'gateway.push.apple.com', apn_port = 2195)
7
+ @pem, @pasword, @apn_host, @apn_port = pem, password, apn_host, apn_port
8
8
  end
9
9
 
10
10
  def connect!
11
11
  raise "The path to your pem file is not set." unless @pem
12
12
  raise "The path to your pem file does not exist!" unless File.exist?(@pem)
13
13
  @key, @cert = @pem, @pem
14
- @connection = EM.connect(host, port, ApnMachine::Server::ServerConnection, self)
14
+ @connection = EM.connect(apn_host, apn_port, ApnMachine::Server::ServerConnection, self)
15
15
  end
16
16
 
17
17
  def disconnect!
@@ -3,10 +3,9 @@ module ApnMachine
3
3
  class Server
4
4
  attr_accessor :client, :bind_address, :port, :redis
5
5
 
6
- def initialize(pem, redis_address, redis_port, log = '/apnmachined.log')
7
- @client = ApnMachine::Server::Client.new(pem)
8
- @bind_address, @port = bind_address, redis_port
9
- @redis = Redis.new
6
+ def initialize(pem, pem_passphrase = nil, redis_host = '127.0.0.1', redis_port = 6379, apn_host = 'gateway.push.apple.com', apn_port = 2195, log = '/apnmachined.log')
7
+ @client = ApnMachine::Server::Client.new(pem, pem_passphrase, apn_host, apn_port)
8
+ @redis = Redis.new(:host => redis_host, :port => redis_port)
10
9
 
11
10
  #set logging options
12
11
  if log == STDOUT
@@ -15,6 +14,8 @@ module ApnMachine
15
14
  @flog = File.open(log, File::WRONLY | File::APPEND)
16
15
  Config.logger = Logger.new(@flog, 'daily')
17
16
  else
17
+ require 'fileutils'
18
+ p log
18
19
  FileUtils.mkdir_p(File.dirname(log))
19
20
  @flog = File.open(log, File::WRONLY | File::APPEND | File::CREAT)
20
21
  Config.logger = Logger.new(@flog, 'daily')
@@ -1,3 +1,3 @@
1
1
  module ApnMachine
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: apnmachine
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Julien Nakache
@@ -57,30 +57,41 @@ dependencies:
57
57
  prerelease: false
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
- name: i18n
60
+ name: hiredis
61
61
  requirement: &id005 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: "0"
66
+ version: 0.3.1
67
67
  type: :runtime
68
68
  prerelease: false
69
69
  version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
71
- name: shoulda
71
+ name: i18n
72
72
  requirement: &id006 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: "0"
78
- type: :development
78
+ type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: *id006
81
81
  - !ruby/object:Gem::Dependency
82
- name: rdoc
82
+ name: shoulda
83
83
  requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: rdoc
94
+ requirement: &id008 !ruby/object:Gem::Requirement
84
95
  none: false
85
96
  requirements:
86
97
  - - ~>
@@ -88,10 +99,10 @@ dependencies:
88
99
  version: "3.12"
89
100
  type: :development
90
101
  prerelease: false
91
- version_requirements: *id007
102
+ version_requirements: *id008
92
103
  - !ruby/object:Gem::Dependency
93
104
  name: bundler
94
- requirement: &id008 !ruby/object:Gem::Requirement
105
+ requirement: &id009 !ruby/object:Gem::Requirement
95
106
  none: false
96
107
  requirements:
97
108
  - - ~>
@@ -99,10 +110,10 @@ dependencies:
99
110
  version: 1.0.0
100
111
  type: :development
101
112
  prerelease: false
102
- version_requirements: *id008
113
+ version_requirements: *id009
103
114
  - !ruby/object:Gem::Dependency
104
115
  name: jeweler
105
- requirement: &id009 !ruby/object:Gem::Requirement
116
+ requirement: &id010 !ruby/object:Gem::Requirement
106
117
  none: false
107
118
  requirements:
108
119
  - - ~>
@@ -110,10 +121,10 @@ dependencies:
110
121
  version: 1.8.3
111
122
  type: :development
112
123
  prerelease: false
113
- version_requirements: *id009
124
+ version_requirements: *id010
114
125
  - !ruby/object:Gem::Dependency
115
126
  name: simplecov
116
- requirement: &id010 !ruby/object:Gem::Requirement
127
+ requirement: &id011 !ruby/object:Gem::Requirement
117
128
  none: false
118
129
  requirements:
119
130
  - - ">="
@@ -121,7 +132,7 @@ dependencies:
121
132
  version: "0"
122
133
  type: :development
123
134
  prerelease: false
124
- version_requirements: *id010
135
+ version_requirements: *id011
125
136
  description: An APN server & library in which EventMachine daemons maintain a persistent connection to Apple servers and Redis acts as the glue with your Apps. See Readme for more info :)
126
137
  email: julien.nakache@gmail.com
127
138
  executables:
@@ -129,26 +140,17 @@ executables:
129
140
  extensions: []
130
141
 
131
142
  extra_rdoc_files:
132
- - LICENSE.txt
133
143
  - README.textile
134
144
  files:
135
- - .DS_Store
136
- - .document
137
145
  - Gemfile
138
- - Gemfile.lock
139
- - LICENSE.txt
140
146
  - README.textile
141
147
  - Rakefile
142
- - VERSION
143
148
  - apnmachine.gemspec
144
149
  - bin/apnmachined
145
- - lib/.DS_Store
146
150
  - lib/apnmachine.rb
147
- - lib/apnmachine/.DS_Store
148
151
  - lib/apnmachine/config.rb
149
152
  - lib/apnmachine/notification.rb
150
153
  - lib/apnmachine/server.rb
151
- - lib/apnmachine/server/.DS_Store
152
154
  - lib/apnmachine/server/client.rb
153
155
  - lib/apnmachine/server/error_response.rb
154
156
  - lib/apnmachine/server/response.rb
@@ -170,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
172
  requirements:
171
173
  - - ">="
172
174
  - !ruby/object:Gem::Version
173
- hash: -105431761613938155
175
+ hash: 1561694125246031221
174
176
  segments:
175
177
  - 0
176
178
  version: "0"
@@ -183,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
185
  requirements: []
184
186
 
185
187
  rubyforge_project:
186
- rubygems_version: 1.8.5
188
+ rubygems_version: 1.8.17
187
189
  signing_key:
188
190
  specification_version: 3
189
191
  summary: An APN server & library built on top of Redis and EventMachine
data/.DS_Store DELETED
Binary file
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1,41 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- activesupport (3.0.9)
5
- daemons (1.1.4)
6
- em-synchrony (1.0.0)
7
- eventmachine (>= 1.0.0.beta.1)
8
- eventmachine (1.0.0.beta.4)
9
- git (1.2.5)
10
- i18n (0.6.0)
11
- jeweler (1.8.3)
12
- bundler (~> 1.0)
13
- git (>= 1.2.5)
14
- rake
15
- rdoc
16
- json (1.6.5)
17
- multi_json (1.0.4)
18
- rake (0.9.2.2)
19
- rdoc (3.12)
20
- json (~> 1.4)
21
- redis (2.2.2)
22
- shoulda (2.11.3)
23
- simplecov (0.5.4)
24
- multi_json (~> 1.0.3)
25
- simplecov-html (~> 0.5.3)
26
- simplecov-html (0.5.3)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- activesupport (>= 3.0.0)
33
- bundler (~> 1.0.0)
34
- daemons
35
- em-synchrony
36
- i18n
37
- jeweler (~> 1.8.3)
38
- rdoc (~> 3.12)
39
- redis (>= 2.2.0)
40
- shoulda
41
- simplecov
@@ -1,20 +0,0 @@
1
- Copyright (c) 2012 Julien Nakache
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
Binary file
Binary file