pistachio 0.1.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/.document +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/config.ru +5 -0
- data/lib/pistachio.rb +41 -0
- data/pistachio.gemspec +77 -0
- data/test/helper.rb +15 -0
- data/test/rack/test_pistachio.rb +19 -0
- metadata +207 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.1)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rack (1.2.1)
|
10
|
+
rack-test (0.5.6)
|
11
|
+
rack (>= 1.0)
|
12
|
+
rake (0.8.7)
|
13
|
+
redis (2.1.1)
|
14
|
+
redis-namespace (0.10.0)
|
15
|
+
redis (< 3.0.0)
|
16
|
+
stash (1.0.0)
|
17
|
+
redis (~> 2.1.0)
|
18
|
+
redis-namespace (~> 0.10.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.0.0)
|
25
|
+
jeweler (~> 1.5.1)
|
26
|
+
rack (~> 1.2.0)
|
27
|
+
rack-test (~> 0.5.0)
|
28
|
+
stash (~> 1.0.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Tony Arcieri
|
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/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Pistachio
|
2
|
+
|
3
|
+
HTTP push middleware for Rack powered by Stash.
|
4
|
+
|
5
|
+
Need events delivered to an HTTP client in realtime? Perhaps you've
|
6
|
+
investigated solutions like Comet/Bayeux, BOSH, or WebSockets. Not happy
|
7
|
+
with those solutions and just want something simple?
|
8
|
+
|
9
|
+
Pistachio provides a simple HTTP long polling middleware for Rack, which is
|
10
|
+
backed by the Stash gem. Stash provides an abstract interface to data
|
11
|
+
structures servers, namely Redis. Servers like Redis provide a list data
|
12
|
+
type, which can easily be used as a message queue. Redis also supports a
|
13
|
+
"blocking pop" from a list, where clients will either receive the next
|
14
|
+
message in the list immediately, or if the list is empty Redis will block
|
15
|
+
until the next message is available (or a timeout occurs).
|
16
|
+
|
17
|
+
Pistachio combines this all into a single, easy-to-use Rack middleware for
|
18
|
+
delivering realtime push notification events to HTTP clients like web browsers.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2010 Tony Arcieri. See file LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "pistachio"
|
16
|
+
gem.homepage = "http://github.com/tarcieri/pistachio"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "HTTP push middleware for Rack powered by Stash"
|
19
|
+
gem.description = "Pistachio provides a simple HTTP long polling middleware for Rack which is backed by the Stash gem"
|
20
|
+
gem.email = "tony@medioh.com"
|
21
|
+
gem.authors = ["Tony Arcieri"]
|
22
|
+
|
23
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
+
gem.add_runtime_dependency "stash", ">= 1.0.0"
|
26
|
+
gem.add_runtime_dependency "rack", "~> 1.2.0"
|
27
|
+
|
28
|
+
gem.add_development_dependency 'rspec', '>= 2.1.0'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rake/testtask'
|
33
|
+
|
34
|
+
namespace :test do
|
35
|
+
Rake::TestTask.new(:rack) do |test|
|
36
|
+
test.libs << 'lib' << 'test'
|
37
|
+
test.pattern = 'test/rack/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => 'test:rack'
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "pistachio #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/config.ru
ADDED
data/lib/pistachio.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'stash'
|
3
|
+
|
4
|
+
class Pistachio
|
5
|
+
def initialize(connection_name, options = {})
|
6
|
+
unless connection_name == :default
|
7
|
+
raise ArgumentError, "only the default connection is supported, sorry"
|
8
|
+
end
|
9
|
+
|
10
|
+
opts = {
|
11
|
+
:path => '/push_messages',
|
12
|
+
:adapter => 'redis',
|
13
|
+
:host => 'localhost',
|
14
|
+
:timeout => 30
|
15
|
+
}.merge(options)
|
16
|
+
|
17
|
+
@path = opts[:path]
|
18
|
+
@timeout = opts[:timeout]
|
19
|
+
|
20
|
+
Stash.setup :default, opts
|
21
|
+
end
|
22
|
+
|
23
|
+
# Retrieve a Pistachio endpoint for the default connection
|
24
|
+
def [](endpoint)
|
25
|
+
Stash::List[endpoint]
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
request = Rack::Request.new(env)
|
30
|
+
result = request.path.match(/^#{@path}\/(\w+)$/)
|
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"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/pistachio.gemspec
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pistachio}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tony Arcieri"]
|
12
|
+
s.date = %q{2010-12-13}
|
13
|
+
s.description = %q{Pistachio provides a simple HTTP long polling middleware for Rack which is backed by the Stash gem}
|
14
|
+
s.email = %q{tony@medioh.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"config.ru",
|
28
|
+
"lib/pistachio.rb",
|
29
|
+
"pistachio.gemspec",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/rack/test_pistachio.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/tarcieri/pistachio}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{HTTP push middleware for Rack powered by Stash}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/rack/test_pistachio.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<stash>, ["~> 1.0.0"])
|
49
|
+
s.add_runtime_dependency(%q<rack>, ["~> 1.2.0"])
|
50
|
+
s.add_development_dependency(%q<rack-test>, ["~> 0.5.0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
53
|
+
s.add_runtime_dependency(%q<stash>, [">= 1.0.0"])
|
54
|
+
s.add_runtime_dependency(%q<rack>, ["~> 1.2.0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 2.1.0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<stash>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
59
|
+
s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
62
|
+
s.add_dependency(%q<stash>, [">= 1.0.0"])
|
63
|
+
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<stash>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
69
|
+
s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
72
|
+
s.add_dependency(%q<stash>, [">= 1.0.0"])
|
73
|
+
s.add_dependency(%q<rack>, ["~> 1.2.0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'rack/test'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'pistachio'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPistachio < Test::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
Pistachio.new :default, :adapter => :redis,
|
8
|
+
:namespace => 'test_pistachio'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_sending_messages
|
12
|
+
app[:lolendpoint] << 'ohai'
|
13
|
+
|
14
|
+
get "/push_messages/lolendpoint"
|
15
|
+
|
16
|
+
assert last_response.ok?
|
17
|
+
assert_equal "ohai", last_response.body
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pistachio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tony Arcieri
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-13 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
name: stash
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
prerelease: false
|
39
|
+
type: :runtime
|
40
|
+
name: rack
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 31
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 2
|
50
|
+
- 0
|
51
|
+
version: 1.2.0
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
name: rack-test
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 11
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 5
|
66
|
+
- 0
|
67
|
+
version: 0.5.0
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
prerelease: false
|
71
|
+
type: :development
|
72
|
+
name: bundler
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 23
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 0
|
82
|
+
- 0
|
83
|
+
version: 1.0.0
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
prerelease: false
|
87
|
+
type: :development
|
88
|
+
name: jeweler
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 1
|
95
|
+
segments:
|
96
|
+
- 1
|
97
|
+
- 5
|
98
|
+
- 1
|
99
|
+
version: 1.5.1
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
prerelease: false
|
103
|
+
type: :runtime
|
104
|
+
name: stash
|
105
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 23
|
111
|
+
segments:
|
112
|
+
- 1
|
113
|
+
- 0
|
114
|
+
- 0
|
115
|
+
version: 1.0.0
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
prerelease: false
|
119
|
+
type: :runtime
|
120
|
+
name: rack
|
121
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 31
|
127
|
+
segments:
|
128
|
+
- 1
|
129
|
+
- 2
|
130
|
+
- 0
|
131
|
+
version: 1.2.0
|
132
|
+
version_requirements: *id007
|
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
|
149
|
+
description: Pistachio provides a simple HTTP long polling middleware for Rack which is backed by the Stash gem
|
150
|
+
email: tony@medioh.com
|
151
|
+
executables: []
|
152
|
+
|
153
|
+
extensions: []
|
154
|
+
|
155
|
+
extra_rdoc_files:
|
156
|
+
- LICENSE
|
157
|
+
- README.rdoc
|
158
|
+
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.gemspec
|
169
|
+
- test/helper.rb
|
170
|
+
- test/rack/test_pistachio.rb
|
171
|
+
has_rdoc: true
|
172
|
+
homepage: http://github.com/tarcieri/pistachio
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 3
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
hash: 3
|
195
|
+
segments:
|
196
|
+
- 0
|
197
|
+
version: "0"
|
198
|
+
requirements: []
|
199
|
+
|
200
|
+
rubyforge_project:
|
201
|
+
rubygems_version: 1.3.7
|
202
|
+
signing_key:
|
203
|
+
specification_version: 3
|
204
|
+
summary: HTTP push middleware for Rack powered by Stash
|
205
|
+
test_files:
|
206
|
+
- test/helper.rb
|
207
|
+
- test/rack/test_pistachio.rb
|