class Rack::DDEX

Constants

HEADERS

Public Instance Methods

call(env) click to toggle source
# File lib/rack/ddex.rb, line 9
def call(env)
  begin
    obj  = ::DDEX.read(env["rack.input"])
    json = JSON.dump(obj.to_hash)

    [200, HEADERS.merge("Content-Length" => json.bytesize.to_s), [json]]
  rescue => e
    code = e.is_a?(::DDEX::DDEXError) ? 400 : 500
    json = JSON.dump(:error => e.message)

    [code, HEADERS, [json]]
  end
end