Skip to content

Instantly share code, notes, and snippets.

@yannick
Created January 17, 2017 02:20
Show Gist options
  • Select an option

  • Save yannick/0ec549870c34d66633209f6563080681 to your computer and use it in GitHub Desktop.

Select an option

Save yannick/0ec549870c34d66633209f6563080681 to your computer and use it in GitHub Desktop.
class Gist
def initialize
@redis = H2O::Redis.new(:host => 'localhost', :port => 6379)
end
#ghetto parser
def query_params(q)
return Hash[q.split("&").map{|combo| combo.split("=") }]
end
def call(env)
if env["REQUEST_METHOD"] == "POST"
uuid = Time.now.to_i.to_s #fixme
@redis.set(uuid, env["rack.input"].read).join
ret = uuid
elsif env["REQUEST_METHOD"] == "GET"
qry = query_params(env["QUERY_STRING"])
ret = @redis.get(qry["id"]).join
end
[200,
{
"content-type" => "application/json",
},
[ret]
]
end
end
Gist.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment