-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.rb
45 lines (37 loc) · 851 Bytes
/
web.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
require 'rubygems'
require 'sinatra'
require 'json'
require 'rest_client'
require 'lib/speech'
helpers do
def h(text)
Rack::Utils.escape_html(text)
end
def u(text)
Rack::Utils.escape(text)
end
end
configure do
set :speacker, Speech::ESpeekSpeechSource.new("http://speak.reality.hk/speech")
end
get '/' do
@user = params[:user] || "siuying"
tweets_json = RestClient.get "http://twitter.com/statuses/user_timeline.json?screen_name=#{u(@user)}", "User-Agent" => "SpeechTweet"
@tweets = JSON(tweets_json)
erb :index
end
get '/speech' do
options.speacker.speech(params[:content])
end
error SocketError do
"Failed to connect to speech server"
end
error RestClient::Unauthorized do
"Not Authorized, user protected? "
end
error Speech::SpeechSourceError do
"Speech server error "
end
error do
"Unexpected error"
end