Class: Dragonfly::SimpleEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/simple_endpoint.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SimpleEndpoint

Instance methods



8
9
10
11
# File 'lib/dragonfly/simple_endpoint.rb', line 8

def initialize(app)
  @app = app
  use_same_log_as(app)
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dragonfly/simple_endpoint.rb', line 13

def call(env)
  request = Rack::Request.new(env)

  case request.path_info
  when '', '/', app.url_path_prefix
    dragonfly_response
  else
    job = Job.from_path(request.path_info, app)
    job.validate_sha!(request['s']) if app.protect_from_dos_attacks
    Response.new(job, env).to_response
  end
rescue Serializer::BadString, Job::InvalidArray => e
  log.warn(e.message)
  [404, {'Content-Type' => 'text/plain'}, ['Not found']]
rescue Job::NoSHAGiven => e
  [400, {"Content-Type" => 'text/plain'}, ["You need to give a SHA parameter"]]
rescue Job::IncorrectSHA => e
  [400, {"Content-Type" => 'text/plain'}, ["The SHA parameter you gave (#{e}) is incorrect"]]
end

#required_params_for(job) ⇒ Object



33
34
35
# File 'lib/dragonfly/simple_endpoint.rb', line 33

def required_params_for(job)
  {'s' => job.sha}
end