-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.rb
37 lines (33 loc) · 856 Bytes
/
runner.rb
1
2
3
4
5
6
7
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
require 'rubygems'
require 'sinatra'
require 'eventmachine'
require 'twitter/json_stream'
require 'json'
require File.dirname(File.expand_path(__FILE__)) + '/lib/twitter'
streams = {}
set :haml, {:format => :html5}
before do
@env = request.env
@user = @env['REMOTE_ADDR'] + @env['HTTP_USER_AGENT']
end
get "/" do
streams[@user].stop if streams[@user]
@posts = []
haml :index
end
post "/hashtag/:hashtag" do
hashtag = params[:hashtag]
yml = YAML.load_file(File.dirname(File.expand_path(__FILE__)) + '/config/config.yml')
streams[@user] = TwitterStream.new(yml['auth'], hashtag) unless streams[@user]
@posts = []
1.times do
@posts << streams[@user].pool_data.deq
end
haml :index
end
get "/message/:hashtag" do
hashtag = params[:hashtag]
queue = streams[@user].pool_data.deq
queue[:hashtag] = hashtag
queue.to_json
end