-
Notifications
You must be signed in to change notification settings - Fork 0
/
tl.rb
92 lines (75 loc) · 1.71 KB
/
tl.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'rubygems'
require 'sinatra'
require 'datamapper'
require 'json'
require 'cgi'
env = 'development'
db_conf = YAML.load(File.new("config/database.yml"))
DataMapper.setup(:default, db_conf[env])
class Liking
include DataMapper::Resource
property :id, Serial
property :who, String, :index => :unique, :length => 255
property :permalink, URI, :index => :unique, :length => 255
property :created_at, DateTime
end
DataMapper::Logger.new(STDOUT, :debug)
#DataMapper.auto_migrate!
post '/likings' do
@liking = Liking.new
@liking.who = params[:who]
@liking.permalink = params[:permalink]
@liking.created_at = Time.now
if @liking.save
status(201)
@liking.permalink.to_json
end
end
delete '/likings' do
@liking = Liking.first(:who => params[:who], :permalink => params[:permalink])
if @liking
@liking.destroy
status(204)
end
end
get '/likings' do
puts params.inspect
status(404) unless params[:p]
permalinks = params[:p].split(',')
response = {}
permalinks.each do |p|
#p = CGI::escape(p)
results = Liking.all(Liking.permalink => p)
unless results.empty?
b = Array.new
results.each do |r|
b << r.who
end
response[p] = b
end
end
mime :json, "application/json"
content_type :json
response.to_json unless response.empty?
end
get '/external.css' do
mime :css, 'text/css'
content_type :css
css = <<-EOD
div.twitterlikker_wrapper {
margin-top: 0.4em;
padding-top: 0.2em;
border-top: 1px solid #EEEEEE;
font-style: normal;
}
div.twitterlikker_wrapper a {
color: blue !important;
text-decoration: underline;
}
EOD
css
end
get '/client_version' do
content_type :text
'0.1'
end