public
Description: tiny webapp I can use to get around stupid Panera blocking tinyurl.com
Homepage:
Clone URL: git://github.com/gdagley/panera.git
panera / panera.rb
100644 31 lines (27 sloc) 0.586 kb
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
require 'vendor/rack-0.4.0/lib/rack.rb'
require 'vendor/sinatra-0.3.1/lib/sinatra.rb'
require 'net/http'
require 'uri'
require 'config.rb'
 
def target_url(url)
  response = Net::HTTP.get_response(URI.parse(url))
  case response
    when Net::HTTPSuccess
      tinyurl
    when Net::HTTPRedirection
      response['location']
    else
      response.error!
  end
end
    
get '/' do
  erb :index
end
 
post '/' do
  tinyurl = params[:tinyurl]
  redirect '/' unless tinyurl
  redirect target_url(tinyurl)
end
 
get '/:id' do
  redirect target_url("http://tinyurl.com/#{params[:id]}")
end