Created
May 22, 2009 05:09
-
-
Save rmanalan/115937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) | |
require 'sinatra' | |
require 'haml' | |
class UrlShortener < Sinatra::Base | |
set :environment, :production | |
configure :production do | |
set :hostname, "c.us.oracle.com" | |
end | |
configure :development do | |
set :hostname, "c" | |
set :app_file, __FILE__ | |
set :reload, true | |
end | |
use_in_file_templates! | |
get "/" do | |
pass unless request.host == options.hostname | |
haml :index | |
end | |
get '/:id' do | |
pass unless request.host == options.hostname | |
begin | |
redirect Url.find(params[:id].to_i(36)).url | |
rescue | |
redirect "http://connect.oraclecorp.com" | |
end | |
end | |
post '/' do | |
pass unless request.host == options.hostname | |
url = Url.create! params | |
"http://" + options.hostname + "/" + url.id.to_s(36) | |
end | |
end | |
__END__ | |
@@ layout | |
!!! XML | |
!!! | |
%html | |
%head | |
%title URL Shortener Service » Oracle Connect | |
%link{:rel => 'stylesheet', :href => '/stylesheets/screen.css', :type => 'text/css'} | |
%body.container | |
= yield | |
@@ index | |
%h2{:style => "margin-top:1em"} Welcome to Oracle Connect's URL Shortener Service | |
%h3 A super quick, super simple URL shortener | |
%p | |
To shorten a URL, all you have to do is send a POST request to | |
=link_to 'http://c.us.oracle.com','http://c.us.oracle.com' | |
with the url parameter in the request. In return, you'll recieve | |
the shortened URL in the response body. This service is provided by | |
and maintained by the | |
="#{link_to 'AppsLab', 'http://theappslab.com'}." | |
For questions or comments, please email us at | |
="#{link_to 'oracleappslab_ww@oracle.com','mailto:oracleappslab_ww@oracle.com'}." | |
%p | |
=link_to "Go back to Oracle Connect", "http://connect.oraclecorp.com" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment