Module: Sinatra::RawQExtension

Defined in:
lib/rawq/templates/application.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rawq/templates/application.rb', line 19

def self.registered(app)
  app.use Rack::Auth::Basic, "Restricted Area" do |username, password|
    [username, password] == [app.username, app.password]
  end

  app.get "/" do
    send_file File.join(settings.public_folder, "index.html")
  end

  app.get "/media" do
    media = Media.all
    media.to_json :include => :sources
  end

  app.get "/media/:id" do
    begin
      media = Media.find(params[:id])
    rescue Mongoid::Errors::DocumentNotFound
      raise Sinatra::NotFound
    end
    media.to_json :include => :sources
  end

  app.get "/media/:id/:source_id" do
    begin
      media = Media.find(params[:id])
      source = media.sources.find(params[:source_id])
    rescue Mongoid::Errors::DocumentNotFound
      raise Sinatra::NotFound
    end
    send_file File.join(source.file), :type => source.mimetype
  end
end