Class: ContentPreview::Router::Handlers::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/content-preview/router/handlers/default.rb

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/content-preview/router/handlers/default.rb', line 5

def self.call(env)
  req = Rack::Request.new(env)
  if req.get?
    [404, {'Content-Type' => 'text/html'}, StringIO.new('No content param found.')] if !req.params['url']
    result = ContentPreview::Parser.new.process(req.params["url"])
    if result
      [200, {'Content-Type' => 'text/json'}, StringIO.new(result.to_json)]
    else
      [404, {'Content-Type' => 'text/html'}, StringIO.new('The content you asked could not be found.')]
    end
  else
    [403, {'Content-Type' => 'text/html'}, StringIO.new('Unauthorized.')]
  end
end