Class: Shrine::PresignEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/presign_endpoint.rb

Overview

Rack application that accepts GET request to the root URL, calls ‘#presign` on the specified storage, and returns that information in JSON format.

Constant Summary collapse

CONTENT_TYPE_JSON =
"application/json; charset=utf-8"
CONTENT_TYPE_TEXT =
"text/plain"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PresignEndpoint

Writes given options to instance variables.



67
68
69
70
71
# File 'lib/shrine/plugins/presign_endpoint.rb', line 67

def initialize(options)
  options.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

Instance Method Details

#call(env) ⇒ Object

Accepts a Rack env hash, routes GET 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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/shrine/plugins/presign_endpoint.rb', line 79

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.get?

    handle_request(request)
  end

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

  [status, headers, body]
end

#inspectObject Also known as: to_s



94
95
96
# File 'lib/shrine/plugins/presign_endpoint.rb', line 94

def inspect
  "#<#{@shrine_class}::PresignEndpoint(:#{@storage_key})>"
end