Skip to content

Instantly share code, notes, and snippets.

@Busta117
Created November 12, 2010 04:46
Show Gist options
  • Save Busta117/673736 to your computer and use it in GitHub Desktop.
Save Busta117/673736 to your computer and use it in GitHub Desktop.
require "open-uri"
require "json"
class RuteoApp
def batman(env)
[200, {"Content-Type" => "text/plain"}, "El Guason"]
end
def superman(env)
[200, {"Content-Type" => "text/plain"}, "hola "]
[200, {"Content-Type" => "text/plain"}, "Lex Luthor"]
end
def algo(env)
key = "0AsTunpthKrMxdEp5R1loYjBBcVhNQWVEc1BUZmZ1QUE"
data_raw = open('http://spreadsheets.google.com/tq?key='+key+'&pub=1')
data = data_raw.read
data = data.split('(')[1].split(")")[0]
data = data.gsub("'", '"')
data = data.gsub(/([a-z]+):/, '"\1":')
result = JSON.parse(data)
puts "\n\n\n"
puts "\n\n\n"
puts"\n\n\n\n"
puts result["table"]["rows"][0]["c"].inspect
puts "\n\n\nchao"
[200, {"Content-Type" => "text/plain"}, "alohaaa"]
end
def call(env)
#Como obtener el URI...
p env["PATH_INFO"] # ej '/' '/favicon.ico' '/superman'
#Aquí es donde se debe hacer el ruteo
path = env["PATH_INFO"][1..-1]
case
when path == ""
[200, {"Content-Type" => "text/plain"}, "Hola Mundo!"]
when (self.respond_to? path)
self.send( path, env )
else
[200, {"Content-Type" => "text/plain"}, "Huh?"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment