lib/rack/gyazo/application.rb in rack_gyazo-0.1.1 vs lib/rack/gyazo/application.rb in rack_gyazo-0.1.2

- old
+ new

@@ -1,11 +1,15 @@ module Rack module Gyazo - class Application + class Application + attr_reader :image, :request + def call(env) @env = env + load_request if request.path == "/uploads" && request.post? + load_image if !image.nil? image.upload [200, {'Content-Type' => 'text/plain'}, StringIO.new(image.url)] else [422, {'Content-Type' => 'text/plain'}, StringIO.new('imagedata not specified')] @@ -14,18 +18,16 @@ [404, {'Content-Type' => 'text/plain'}, StringIO.new('file not found')] end end protected - def request - @request ||= Rack::Request.new(@env) + def load_request + @request = Rack::Request.new(@env) end - def image + def load_image if request.params["imagedata"] - @image ||= ::Gyazo::Image.new(request.params["imagedata"]) - else - nil + @image = ::Gyazo::Image.new(request.params["imagedata"]) end end end end end