8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/firehose/rack.rb', line 8
def call(env)
req = ::Rack::Request.new(env)
cid = req.params['cid']
path = req.path
method = req.request_method
case method
when 'GET'
EM.next_tick do
subscription = Firehose::Subscription.new(cid)
subscription.subscribe path do |payload|
subscription.unsubscribe
env['async.callback'].call([200, {}, [payload]])
end
end
Firehose::Rack::AsyncResponse
when 'PUT'
body = env['rack.input'].read
p [:put, path, body]
Firehose::Publisher.new.publish(path, body)
[202, {}, []]
else
[501, {}, ["#{method} not supported."]]
end
end
|