Class: Rack::GoogleImage

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-middleware-google-image.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ GoogleImage

Returns a new instance of GoogleImage.



8
9
10
# File 'lib/rack-middleware-google-image.rb', line 8

def initialize(app, options = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/rack-middleware-google-image.rb', line 12

def call(env)
  status, headers, response = @app.call(env)

  if env['PATH_INFO'] =~ (/\/(.*)\.jpg$/)
    response = search_image(response, Rack::Utils::unescape($1))
    [status, headers, response]
  end

  [status, headers, response]
end