Class: Rack::Gyazo::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/gyazo/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



4
5
6
# File 'lib/rack/gyazo/application.rb', line 4

def image
  @image
end

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/rack/gyazo/application.rb', line 4

def request
  @request
end

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/gyazo/application.rb', line 6

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')]
    end
  else
    [404, {'Content-Type' => 'text/plain'}, StringIO.new('file not found')]
  end
end