pistachio 0.1.0 → 0.9.0
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/Gemfile.lock +1 -0
- data/README.rdoc +36 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/config.ru +3 -1
- data/lib/pistachio.rb +23 -31
- data/lib/pistachio/middleware.rb +23 -0
- data/pistachio.gemspec +8 -7
- data/test/helper.rb +6 -3
- data/test/rack/test_pistachio.rb +2 -3
- metadata +148 -168
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -17,6 +17,42 @@ until the next message is available (or a timeout occurs).
|
|
17
17
|
Pistachio combines this all into a single, easy-to-use Rack middleware for
|
18
18
|
delivering realtime push notification events to HTTP clients like web browsers.
|
19
19
|
|
20
|
+
== Using Pistachio in your Rack application
|
21
|
+
|
22
|
+
Add the following to your config.ru file:
|
23
|
+
|
24
|
+
Pistachio.setup :default, :adapter => :redis,
|
25
|
+
:namespace => 'myapp_name',
|
26
|
+
:path => '/message_path'
|
27
|
+
|
28
|
+
use Pistachio::Middleware
|
29
|
+
|
30
|
+
This will configure Pistachio to talk to Redis, store its messages in the
|
31
|
+
'myapp_name' Redis namespace, and mount the Pistachio Rack middleware
|
32
|
+
under the /message_path path.
|
33
|
+
|
34
|
+
All messages must be sent to a given named endpoint. To send a message via
|
35
|
+
Pistachio within your Rack application, do:
|
36
|
+
|
37
|
+
Pistachio[:foobar] << "my totally awesome message"
|
38
|
+
|
39
|
+
Messages sent to the 'foobar' endpoint can be retrieved by making an HTTP GET
|
40
|
+
request to /message_path/foobar. This will return one of two HTTP statuses:
|
41
|
+
|
42
|
+
* 200: a message was retrieved successfully
|
43
|
+
* 504: the request timed out before a message was received
|
44
|
+
|
45
|
+
By default Pistachio uses a 30 second timeout. You can adjust this with the
|
46
|
+
':timeout' parameter to Pistachio.setup.
|
47
|
+
|
48
|
+
It's the responsibility of the client to hit the given message endpoint in a
|
49
|
+
loop. If the client gets a 504 response it should retry. Any other HTTP
|
50
|
+
responses should be considered errors, in which case it'd be good if the
|
51
|
+
client utilized exponential backoff to avoid hammering Pistachio when errors
|
52
|
+
are occurring.
|
53
|
+
|
54
|
+
No reference clients are presently available. Pull requests happily accepted!
|
55
|
+
|
20
56
|
== Copyright
|
21
57
|
|
22
58
|
Copyright (c) 2010 Tony Arcieri. See file LICENSE for further details.
|
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ Jeweler::Tasks.new do |gem|
|
|
25
25
|
gem.add_runtime_dependency "stash", ">= 1.0.0"
|
26
26
|
gem.add_runtime_dependency "rack", "~> 1.2.0"
|
27
27
|
|
28
|
-
gem.add_development_dependency '
|
28
|
+
gem.add_development_dependency 'rack-test', '>= 0.5.0'
|
29
29
|
end
|
30
30
|
Jeweler::RubygemsDotOrgTasks.new
|
31
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/config.ru
CHANGED
data/lib/pistachio.rb
CHANGED
@@ -1,41 +1,33 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'stash'
|
3
|
+
require 'pistachio/middleware'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Pistachio
|
6
|
+
class << self
|
7
|
+
attr_reader :path, :timeout
|
8
|
+
|
9
|
+
def setup(connection_name, options = {})
|
10
|
+
unless connection_name == :default
|
11
|
+
raise ArgumentError, "only the default connection is supported, sorry"
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
opts = {
|
15
|
+
:path => '/push_messages',
|
16
|
+
:adapter => 'redis',
|
17
|
+
:host => 'localhost',
|
18
|
+
:timeout => 30
|
19
|
+
}.merge(options)
|
16
20
|
|
17
|
-
|
18
|
-
|
21
|
+
@path = opts[:path]
|
22
|
+
@timeout = opts[:timeout]
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# Retrieve a Pistachio endpoint for the default connection
|
24
|
-
def [](endpoint)
|
25
|
-
Stash::List[endpoint]
|
26
|
-
end
|
24
|
+
Stash.setup :default, opts
|
25
|
+
true
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return unless result
|
32
|
-
|
33
|
-
endpoint = result[1]
|
34
|
-
begin
|
35
|
-
message = Stash::List[endpoint].bshift @timeout
|
36
|
-
[200, {'Content-Type' => 'text/plain'}, message]
|
37
|
-
rescue Stash::TimeoutError
|
38
|
-
[504, {'Content-Type' => 'text/plain'}, "Timeout waiting for response"]
|
28
|
+
# Retrieve a Pistachio endpoint for the default connection
|
29
|
+
def [](endpoint)
|
30
|
+
Stash::List[endpoint]
|
39
31
|
end
|
40
32
|
end
|
41
33
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pistachio
|
2
|
+
class Middleware
|
3
|
+
def initialize
|
4
|
+
# Matches messages that should be processed by Pistachio
|
5
|
+
@path_regex = /^#{Pistachio.path}\/(\w+)$/
|
6
|
+
@timeout = Pistachio.timeout
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
request = Rack::Request.new(env)
|
11
|
+
result = request.path.match(@path_regex)
|
12
|
+
return unless result
|
13
|
+
|
14
|
+
endpoint = result[1]
|
15
|
+
begin
|
16
|
+
message = Stash::List[endpoint].bshift @timeout
|
17
|
+
[200, {'Content-Type' => 'text/plain'}, message]
|
18
|
+
rescue Stash::TimeoutError
|
19
|
+
[504, {'Content-Type' => 'text/plain'}, "Timeout waiting for response"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/pistachio.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pistachio}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tony Arcieri"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-02-15}
|
13
13
|
s.description = %q{Pistachio provides a simple HTTP long polling middleware for Rack which is backed by the Stash gem}
|
14
14
|
s.email = %q{tony@medioh.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"config.ru",
|
28
28
|
"lib/pistachio.rb",
|
29
|
+
"lib/pistachio/middleware.rb",
|
29
30
|
"pistachio.gemspec",
|
30
31
|
"test/helper.rb",
|
31
32
|
"test/rack/test_pistachio.rb"
|
@@ -33,7 +34,7 @@ Gem::Specification.new do |s|
|
|
33
34
|
s.homepage = %q{http://github.com/tarcieri/pistachio}
|
34
35
|
s.licenses = ["MIT"]
|
35
36
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
37
38
|
s.summary = %q{HTTP push middleware for Rack powered by Stash}
|
38
39
|
s.test_files = [
|
39
40
|
"test/helper.rb",
|
@@ -44,7 +45,7 @@ Gem::Specification.new do |s|
|
|
44
45
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
46
|
s.specification_version = 3
|
46
47
|
|
47
|
-
if Gem::Version.new(Gem::
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
49
|
s.add_runtime_dependency(%q<stash>, ["~> 1.0.0"])
|
49
50
|
s.add_runtime_dependency(%q<rack>, ["~> 1.2.0"])
|
50
51
|
s.add_development_dependency(%q<rack-test>, ["~> 0.5.0"])
|
@@ -52,7 +53,7 @@ Gem::Specification.new do |s|
|
|
52
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
53
54
|
s.add_runtime_dependency(%q<stash>, [">= 1.0.0"])
|
54
55
|
s.add_runtime_dependency(%q<rack>, ["~> 1.2.0"])
|
55
|
-
s.add_development_dependency(%q<
|
56
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
56
57
|
else
|
57
58
|
s.add_dependency(%q<stash>, ["~> 1.0.0"])
|
58
59
|
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
@@ -61,7 +62,7 @@ Gem::Specification.new do |s|
|
|
61
62
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
62
63
|
s.add_dependency(%q<stash>, [">= 1.0.0"])
|
63
64
|
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
64
|
-
s.add_dependency(%q<
|
65
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
65
66
|
end
|
66
67
|
else
|
67
68
|
s.add_dependency(%q<stash>, ["~> 1.0.0"])
|
@@ -71,7 +72,7 @@ Gem::Specification.new do |s|
|
|
71
72
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
72
73
|
s.add_dependency(%q<stash>, [">= 1.0.0"])
|
73
74
|
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
74
|
-
s.add_dependency(%q<
|
75
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
data/test/helper.rb
CHANGED
@@ -10,6 +10,9 @@ end
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'rack/test'
|
12
12
|
|
13
|
-
$LOAD_PATH.unshift
|
14
|
-
$LOAD_PATH.unshift
|
15
|
-
require 'pistachio'
|
13
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
14
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
15
|
+
require 'pistachio'
|
16
|
+
|
17
|
+
Pistachio.setup :default, :adapter => :redis,
|
18
|
+
:namespace => 'test_pistachio'
|
data/test/rack/test_pistachio.rb
CHANGED
@@ -4,12 +4,11 @@ class TestPistachio < Test::Unit::TestCase
|
|
4
4
|
include Rack::Test::Methods
|
5
5
|
|
6
6
|
def app
|
7
|
-
Pistachio.new
|
8
|
-
:namespace => 'test_pistachio'
|
7
|
+
Pistachio::Middleware.new
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_sending_messages
|
12
|
-
|
11
|
+
Pistachio[:lolendpoint] << 'ohai'
|
13
12
|
|
14
13
|
get "/push_messages/lolendpoint"
|
15
14
|
|
metadata
CHANGED
@@ -1,151 +1,134 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pistachio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
version: 0.
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
|
-
- Tony Arcieri
|
12
|
+
- Tony Arcieri
|
14
13
|
autorequire:
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-02-15 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
- !ruby/object:Gem::Dependency
|
134
|
-
prerelease: false
|
135
|
-
type: :development
|
136
|
-
name: rspec
|
137
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
|
-
requirements:
|
140
|
-
- - ">="
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
hash: 11
|
143
|
-
segments:
|
144
|
-
- 2
|
145
|
-
- 1
|
146
|
-
- 0
|
147
|
-
version: 2.1.0
|
148
|
-
version_requirements: *id008
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: stash
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 1
|
28
|
+
- 0
|
29
|
+
- 0
|
30
|
+
version: 1.0.0
|
31
|
+
requirement: *id001
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rack
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 2
|
43
|
+
- 0
|
44
|
+
version: 1.2.0
|
45
|
+
requirement: *id002
|
46
|
+
prerelease: false
|
47
|
+
type: :runtime
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rack-test
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
- 5
|
57
|
+
- 0
|
58
|
+
version: 0.5.0
|
59
|
+
requirement: *id003
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 0
|
71
|
+
- 0
|
72
|
+
version: 1.0.0
|
73
|
+
requirement: *id004
|
74
|
+
prerelease: false
|
75
|
+
type: :development
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: jeweler
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 5
|
85
|
+
- 1
|
86
|
+
version: 1.5.1
|
87
|
+
requirement: *id005
|
88
|
+
prerelease: false
|
89
|
+
type: :development
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: stash
|
92
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 1
|
98
|
+
- 0
|
99
|
+
- 0
|
100
|
+
version: 1.0.0
|
101
|
+
requirement: *id006
|
102
|
+
prerelease: false
|
103
|
+
type: :runtime
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rack
|
106
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 1
|
112
|
+
- 2
|
113
|
+
- 0
|
114
|
+
version: 1.2.0
|
115
|
+
requirement: *id007
|
116
|
+
prerelease: false
|
117
|
+
type: :runtime
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: rack-test
|
120
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
- 5
|
127
|
+
- 0
|
128
|
+
version: 0.5.0
|
129
|
+
requirement: *id008
|
130
|
+
prerelease: false
|
131
|
+
type: :development
|
149
132
|
description: Pistachio provides a simple HTTP long polling middleware for Rack which is backed by the Stash gem
|
150
133
|
email: tony@medioh.com
|
151
134
|
executables: []
|
@@ -153,55 +136,52 @@ executables: []
|
|
153
136
|
extensions: []
|
154
137
|
|
155
138
|
extra_rdoc_files:
|
156
|
-
- LICENSE
|
157
|
-
- README.rdoc
|
139
|
+
- LICENSE
|
140
|
+
- README.rdoc
|
158
141
|
files:
|
159
|
-
- .document
|
160
|
-
- Gemfile
|
161
|
-
- Gemfile.lock
|
162
|
-
- LICENSE
|
163
|
-
- README.rdoc
|
164
|
-
- Rakefile
|
165
|
-
- VERSION
|
166
|
-
- config.ru
|
167
|
-
- lib/pistachio.rb
|
168
|
-
- pistachio.
|
169
|
-
-
|
170
|
-
- test/
|
142
|
+
- .document
|
143
|
+
- Gemfile
|
144
|
+
- Gemfile.lock
|
145
|
+
- LICENSE
|
146
|
+
- README.rdoc
|
147
|
+
- Rakefile
|
148
|
+
- VERSION
|
149
|
+
- config.ru
|
150
|
+
- lib/pistachio.rb
|
151
|
+
- lib/pistachio/middleware.rb
|
152
|
+
- pistachio.gemspec
|
153
|
+
- test/helper.rb
|
154
|
+
- test/rack/test_pistachio.rb
|
171
155
|
has_rdoc: true
|
172
156
|
homepage: http://github.com/tarcieri/pistachio
|
173
157
|
licenses:
|
174
|
-
- MIT
|
158
|
+
- MIT
|
175
159
|
post_install_message:
|
176
160
|
rdoc_options: []
|
177
161
|
|
178
162
|
require_paths:
|
179
|
-
- lib
|
163
|
+
- lib
|
180
164
|
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
-
none: false
|
182
165
|
requirements:
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
version: "0"
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
segments:
|
169
|
+
- 0
|
170
|
+
version: "0"
|
189
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
-
none: false
|
191
172
|
requirements:
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
version: "0"
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
version: "0"
|
198
178
|
requirements: []
|
199
179
|
|
200
180
|
rubyforge_project:
|
201
|
-
rubygems_version: 1.3.
|
181
|
+
rubygems_version: 1.3.6
|
202
182
|
signing_key:
|
203
183
|
specification_version: 3
|
204
184
|
summary: HTTP push middleware for Rack powered by Stash
|
205
185
|
test_files:
|
206
|
-
- test/helper.rb
|
207
|
-
- test/rack/test_pistachio.rb
|
186
|
+
- test/helper.rb
|
187
|
+
- test/rack/test_pistachio.rb
|