Sha256: e28c263fa2e59169626db5a7dcc704c3c4fbd3b6f5b3b04df7d5b6bf41789559

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 Bytes

Contents

class App

  def call(env)
    @env = env
    params = env["rack.input"].gets
    @params = JSON.parse(params || '{}')
    header = {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json'
    }

    response = Rack::Response.new(
      json_response(params),
      status,
      header)
    response.finish
  end

  private

  def status
    path = @env['PATH_INFO']
    if path =~ /error$/
      @params['error_code'] || 500
    else
      200
    end
  end

  def json_response(params)
    hsh_params = @params
    keys = hsh_params.reduce([]) do |result, (key, value)|
      result << key
      if value.is_a?(Hash)
        result << value.keys
      end
      result
    end.flatten
    JSON.generate({
                       keys: keys,
                       fakeKey: true,
                       fake_key: false
                   })
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp-sparrow-0.0.16 spec/integration/apps/rack_app/app.rb
cp-sparrow-0.0.15 spec/integration/apps/rack_app/app.rb