-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.rb
62 lines (51 loc) · 1.24 KB
/
app.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
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
require 'rubygems'
require 'sinatra/base'
require 'uri'
require 'birds'
class App < Sinatra::Base
set :erb, :format => :html5
set :app_file, __FILE__
include Birds
configure do
@birds = Birds.new
puts "configure "[email protected]
end
get '/' do
erb :index
end
get '/users' do
content_type :json
@birds.users.collect{ |u| { :name => "@"+u.twid, :link => "/user/#{u.twid}", :value => u.outgoing(:TWEETED).size }}.to_json
end
get '/user/:id' do |id|
# user with :KNOWS, :TWEETED, :USED
@user = @birds.user(id) # sunburst, social graph
erb :user
end
get '/tag/:id' do |id|
@tag = @birds.tag(id)
erb :tag
end
get '/admin/update' do
@birds.update_users(@birds.users).inspect
end
get '/info/:twids' do |twids|
@birds.sg_info(twids.split(',')).inspect
end
get '/tags' do
content_type :json
@birds.tags.collect{ |t| { :name => "#"+t.name, :link => "/tag/#{t.name}", :value => t.incoming(:TAGGED).size } }.to_json
end
post '/update' do
tag = @params["tag"]
@tags = []
if tag.kind_of? Array
@tags + tag
else
@tags << tag
end
@tags << "neo4j" unless @tags.include? "neo4j"
@added = @birds.update(@tags)
redirect "/"
end
end