rapnd 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -0
- data/VERSION +1 -1
- data/lib/rapnd/config.rb +34 -0
- data/lib/rapnd.rb +16 -0
- data/rapnd.gemspec +7 -4
- data/spec/config_spec.rb +29 -0
- data/spec/rapnd_spec.rb +23 -0
- metadata +30 -27
- data/README.rdoc +0 -19
data/README.markdown
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# rapnd
|
2
|
+
|
3
|
+
rapnd is an easy-to-use daemon that opens a persistent connection to the Apple Push Notification servers and sends notifications you specify to Apple.
|
4
|
+
|
5
|
+
It intentionally has very little in the way of model-level assumptions: this daemon is intended only to send notifications and does almost nothing to validate the content of the notifications (besides ensuring that the length is correct and a device_token is provided). Your models should validate that the messages they send to rapnd conform to the behavior you expect.
|
6
|
+
|
7
|
+
Each rapnd daemon operates on a separate resque queue, and multiple daemons can service one queue. Thus you can use rapnd with multiple Apple certs (if you have multiple applications you're trying to send notifications for) and, if you expect a lot of traffic, you can even have multiple daemons servicing one queue.
|
8
|
+
|
9
|
+
## Daemon usage
|
10
|
+
|
11
|
+
```
|
12
|
+
Usage: rapnd [options]
|
13
|
+
--cert=MANDATORY Location of the cert pem file
|
14
|
+
--password=OPTIONAL Password for the cert pem file
|
15
|
+
--redis_host=OPTIONAL Redis hostname
|
16
|
+
--redis_port=OPTIONAL Redis port
|
17
|
+
--environment=OPTIONAL Specify sandbox or production
|
18
|
+
--queue=OPTIONAL Name of the redis queue
|
19
|
+
--foreground Run in the foreground
|
20
|
+
--dir=OPTIONAL Directory to start in
|
21
|
+
--airbrake=OPTIONAL Airbrake API key
|
22
|
+
--help Show help
|
23
|
+
```
|
24
|
+
|
25
|
+
## Client usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'rapnd'
|
29
|
+
|
30
|
+
Rapnd.configure do |config|
|
31
|
+
config.redis_host = 'localhost'
|
32
|
+
config.redis_port = 6379
|
33
|
+
end
|
34
|
+
|
35
|
+
message = {:badge => 1, :alert => 'This is a test from rapnd!', :sound => 'flash.caf', :custom_properties => {:test_id => 1234, :happiness => true}}
|
36
|
+
queue_name = 'rapnd_queue'
|
37
|
+
|
38
|
+
Rapnd.queue(queue_name, message)
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing to rapnd
|
42
|
+
|
43
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
44
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
45
|
+
* Fork the project
|
46
|
+
* Start a feature/bugfix branch
|
47
|
+
* Commit and push until you are happy with your contribution
|
48
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
49
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
50
|
+
|
51
|
+
## Copyright
|
52
|
+
|
53
|
+
Copyright (c) 2012 Josh Symonds. See LICENSE.txt for further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rapnd/config.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rapnd
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def option(name, options = {})
|
6
|
+
defaults[name] = settings[name] = options[:default]
|
7
|
+
|
8
|
+
class_eval <<-RUBY
|
9
|
+
def #{name}
|
10
|
+
settings[#{name.inspect}]
|
11
|
+
end
|
12
|
+
|
13
|
+
def #{name}=(value)
|
14
|
+
settings[#{name.inspect}] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def #{name}?
|
18
|
+
#{name}
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
|
23
|
+
def defaults
|
24
|
+
@defaults ||= {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def settings
|
28
|
+
@settings ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
option :redis_host, :default => 'localhost'
|
32
|
+
option :redis_port, :default => 6879
|
33
|
+
end
|
34
|
+
end
|
data/lib/rapnd.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
require 'rapnd/daemon'
|
2
2
|
require 'rapnd/notification'
|
3
|
+
require 'rapnd/config'
|
4
|
+
require 'redis'
|
3
5
|
|
4
6
|
module Rapnd
|
7
|
+
extend self
|
5
8
|
|
9
|
+
def queue(queue_name, message)
|
10
|
+
self.redis.lpush(queue_name, Marshal.dump(message))
|
11
|
+
end
|
12
|
+
|
13
|
+
def redis
|
14
|
+
@redis ||= Redis.new(:host => Rapnd.config.redis_host, :port => Rapnd.config.redis_port)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
block_given? ? yield(Config) : Config
|
19
|
+
end
|
20
|
+
alias :config :configure
|
21
|
+
|
6
22
|
end
|
data/rapnd.gemspec
CHANGED
@@ -5,17 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rapnd"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Josh Symonds"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-21"
|
13
13
|
s.description = "redis APN daemon"
|
14
14
|
s.email = "veraticus@gmail.com"
|
15
15
|
s.executables = ["rapnd"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
18
|
-
"README.
|
18
|
+
"README.markdown"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
@@ -23,16 +23,19 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Gemfile",
|
24
24
|
"Gemfile.lock",
|
25
25
|
"LICENSE.txt",
|
26
|
-
"README.
|
26
|
+
"README.markdown",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"bin/rapnd",
|
30
30
|
"lib/rapnd.rb",
|
31
|
+
"lib/rapnd/config.rb",
|
31
32
|
"lib/rapnd/daemon.rb",
|
32
33
|
"lib/rapnd/notification.rb",
|
33
34
|
"rapnd.gemspec",
|
35
|
+
"spec/config_spec.rb",
|
34
36
|
"spec/daemon_spec.rb",
|
35
37
|
"spec/notification_spec.rb",
|
38
|
+
"spec/rapnd_spec.rb",
|
36
39
|
"spec/redis-test.conf",
|
37
40
|
"spec/spec_helper.rb"
|
38
41
|
]
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Rapnd::Config" do
|
4
|
+
it 'has a default value' do
|
5
|
+
Rapnd.config.redis_host.should == 'localhost'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'overrides a default value with an assigner' do
|
9
|
+
Rapnd.config.redis_host = 'testhost'
|
10
|
+
|
11
|
+
Rapnd.config.redis_host.should == 'testhost'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'overrides a default value with a block' do
|
15
|
+
Rapnd.config do |config|
|
16
|
+
config.redis_host = 'testhost'
|
17
|
+
end
|
18
|
+
|
19
|
+
Rapnd.config.redis_host.should == 'testhost'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'checks a value has been assigned' do
|
23
|
+
Rapnd.config.redis_host?.should be_true
|
24
|
+
|
25
|
+
Rapnd.config.redis_host = nil
|
26
|
+
|
27
|
+
Rapnd.config.redis_host?.should be_false
|
28
|
+
end
|
29
|
+
end
|
data/spec/rapnd_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Rapnd" do
|
4
|
+
before do
|
5
|
+
Rapnd.config do |config|
|
6
|
+
config.redis_host = 'localhost'
|
7
|
+
config.redis_port = 9876
|
8
|
+
end
|
9
|
+
|
10
|
+
@redis = Redis.new(:host => 'localhost', :port => 9876)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'enqueues a message' do
|
14
|
+
Rapnd.queue('test_queue', {:alert => 'Hi!'})
|
15
|
+
|
16
|
+
@redis.llen('test_queue').should == 1
|
17
|
+
Marshal.load(@redis.lpop('test_queue')).should == {:alert => 'Hi!'}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'gets a redis connection' do
|
21
|
+
Rapnd.redis.ping.should == "PONG"
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapnd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiredis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70356622859940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70356622859940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: redis
|
27
|
-
requirement: &
|
27
|
+
requirement: &70356623103620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.2.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70356623103620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &70356623099520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70356623099520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: daemons
|
49
|
-
requirement: &
|
49
|
+
requirement: &70356622733060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.1.6
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70356622733060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: i18n
|
60
|
-
requirement: &
|
60
|
+
requirement: &70356622728740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70356622728740
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: airbrake
|
71
|
-
requirement: &
|
71
|
+
requirement: &70356622742900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70356622742900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mocha
|
82
|
-
requirement: &
|
82
|
+
requirement: &70356622749900 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70356622749900
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70356622692640 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70356622692640
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: bundler
|
104
|
-
requirement: &
|
104
|
+
requirement: &70356622690300 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70356622690300
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: jeweler
|
115
|
-
requirement: &
|
115
|
+
requirement: &70356622697380 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70356622697380
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rcov
|
126
|
-
requirement: &
|
126
|
+
requirement: &70356622693920 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,7 +131,7 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70356622693920
|
135
135
|
description: redis APN daemon
|
136
136
|
email: veraticus@gmail.com
|
137
137
|
executables:
|
@@ -139,23 +139,26 @@ executables:
|
|
139
139
|
extensions: []
|
140
140
|
extra_rdoc_files:
|
141
141
|
- LICENSE.txt
|
142
|
-
- README.
|
142
|
+
- README.markdown
|
143
143
|
files:
|
144
144
|
- .document
|
145
145
|
- .rspec
|
146
146
|
- Gemfile
|
147
147
|
- Gemfile.lock
|
148
148
|
- LICENSE.txt
|
149
|
-
- README.
|
149
|
+
- README.markdown
|
150
150
|
- Rakefile
|
151
151
|
- VERSION
|
152
152
|
- bin/rapnd
|
153
153
|
- lib/rapnd.rb
|
154
|
+
- lib/rapnd/config.rb
|
154
155
|
- lib/rapnd/daemon.rb
|
155
156
|
- lib/rapnd/notification.rb
|
156
157
|
- rapnd.gemspec
|
158
|
+
- spec/config_spec.rb
|
157
159
|
- spec/daemon_spec.rb
|
158
160
|
- spec/notification_spec.rb
|
161
|
+
- spec/rapnd_spec.rb
|
159
162
|
- spec/redis-test.conf
|
160
163
|
- spec/spec_helper.rb
|
161
164
|
homepage: http://github.com/Veraticus/rapnd
|
@@ -173,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
176
|
version: '0'
|
174
177
|
segments:
|
175
178
|
- 0
|
176
|
-
hash: -
|
179
|
+
hash: -1178494822573940370
|
177
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
181
|
none: false
|
179
182
|
requirements:
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= rapnd
|
2
|
-
|
3
|
-
An extremely beta daemon that persists a connection to Apple's servers and sends messages to it, using redis for persistence.
|
4
|
-
|
5
|
-
== Contributing to rapnd
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2012 Josh Symonds. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|