-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweetclock.rb
63 lines (52 loc) · 1.22 KB
/
tweetclock.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
require 'sinatra'
require 'eventmachine'
require 'em-http'
require 'json'
require 'sinatra/redis'
require 'active_support/core_ext'
require File.expand_path('../models/tweet_time.rb', __FILE__)
SECONDS_TTL = 12.hours
MINUTES_TTL = 9.days
configure :production do
disable :raise_errors
require 'newrelic_rpm'
require 'hoptoad_notifier'
HoptoadNotifier.configure do |config|
config.api_key = ENV['HOPTOAD_API_KEY']
end
use HoptoadNotifier::Rack
end
configure :development do
enable :show_exceptions
end
set :redis, ENV['REDISTOGO_URL']
# There's got to be a better way to do this.
get '/' do
File.read(File.join('public', 'index.html'))
end
get '/test' do
redis.get(Time.now.to_i - 5)
end
get '/*/id_at/*.*' do |api_version, posix_time, ext|
if api_version == '1'
tt = TweetTime.find(posix_time.to_i)
return if tt.nil?
case ext
when 'json'
content_type 'application/json', :charset => 'utf-8'
tt.to_json
when 'xml'
content_type 'application/xml', :charset => 'utf-8'
tt.to_xml
else
tt.id
end
end
end
get '/*/id_at/*' do |api_version, posix_time|
if api_version == '1'
tt = TweetTime.find(posix_time.to_i)
return if tt.nil?
tt.id
end
end