class Shrine::Plugins::UploadEndpoint::App

  1. lib/shrine/plugins/upload_endpoint.rb
Superclass: Object

Rack application that accepts multipart POSt request to the root URL, calls #upload with the uploaded file, and returns the uploaded file information in JSON format.

Methods

Public Class

  1. new

Public Instance

  1. call

Public Class methods

new (options)

Writes given options to instance variables.

[show source]
# File lib/shrine/plugins/upload_endpoint.rb, line 143
def initialize(options)
  options.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

Public Instance methods

call (env)

Accepts a Rack env hash, routes POST requests to the root URL, and returns a Rack response triple.

If request isn't to the root URL, a 404 Not Found response is returned. If request verb isn't GET, a 405 Method Not Allowed response is returned.

[show source]
# File lib/shrine/plugins/upload_endpoint.rb, line 155
def call(env)
  request = Rack::Request.new(env)

  status, headers, body = catch(:halt) do
    error!(404, "Not Found") unless ["", "/"].include?(request.path_info)
    error!(405, "Method Not Allowed") unless request.post?

    handle_request(request)
  end

  headers["Content-Length"] = body.map(&:bytesize).inject(0, :+).to_s

  [status, headers, body]
end