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 CHANGED
@@ -18,6 +18,7 @@ GEM
18
18
  redis-namespace (~> 0.10.0)
19
19
 
20
20
  PLATFORMS
21
+ java
21
22
  ruby
22
23
 
23
24
  DEPENDENCIES
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 'rspec', '>= 2.1.0'
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
1
+ 0.9.0
data/config.ru CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'bundler/setup'
2
- require File.expand_path('../lib/pistachio', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+
4
+ require 'pistachio'
3
5
 
4
6
  Bundler.setup :default
5
7
  run Pistachio.new
data/lib/pistachio.rb CHANGED
@@ -1,41 +1,33 @@
1
1
  require 'rack'
2
2
  require 'stash'
3
+ require 'pistachio/middleware'
3
4
 
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
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
- opts = {
11
- :path => '/push_messages',
12
- :adapter => 'redis',
13
- :host => 'localhost',
14
- :timeout => 30
15
- }.merge(options)
14
+ opts = {
15
+ :path => '/push_messages',
16
+ :adapter => 'redis',
17
+ :host => 'localhost',
18
+ :timeout => 30
19
+ }.merge(options)
16
20
 
17
- @path = opts[:path]
18
- @timeout = opts[:timeout]
21
+ @path = opts[:path]
22
+ @timeout = opts[:timeout]
19
23
 
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
24
+ Stash.setup :default, opts
25
+ true
26
+ end
27
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"]
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.1.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{2010-12-13}
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.7}
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::VERSION) >= Gem::Version.new('1.2.0') then
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<rspec>, [">= 2.1.0"])
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<rspec>, [">= 2.1.0"])
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<rspec>, [">= 2.1.0"])
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(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
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'
@@ -4,12 +4,11 @@ class TestPistachio < Test::Unit::TestCase
4
4
  include Rack::Test::Methods
5
5
 
6
6
  def app
7
- Pistachio.new :default, :adapter => :redis,
8
- :namespace => 'test_pistachio'
7
+ Pistachio::Middleware.new
9
8
  end
10
9
 
11
10
  def test_sending_messages
12
- app[:lolendpoint] << 'ohai'
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
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.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: 2010-12-13 00:00:00 -07:00
17
+ date: 2011-02-15 00:00:00 -07:00
19
18
  default_executable:
20
19
  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
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.gemspec
169
- - test/helper.rb
170
- - test/rack/test_pistachio.rb
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
- - !ruby/object:Gem::Version
185
- hash: 3
186
- segments:
187
- - 0
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
- - !ruby/object:Gem::Version
194
- hash: 3
195
- segments:
196
- - 0
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.7
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