Module: Sfn::MockMacros::ApiGateway

Included in:
Sfn::MockMacros
Defined in:
lib/sfn/mock_macros/api_gateway.rb

Class Method Summary collapse

Class Method Details

.response(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sfn/mock_macros/api_gateway.rb', line 6

def self.response(data)
  data = [data] if data.is_a?(Hash)
  out_data = data.map do |val|
    if val.key?(:error)
      { Throw: { Error: val[:error], Cause: val[:cause] } }
    else
      val[:response] ||= val[:payload]
      val[:response] ||= val[:output]
      { Return: { Headers: val[:headers], ResponseBody: val[:response], StatusCode: val[:status],
                  StatusText: 'OK' } }
    end
  end
  out = {}
  out_data.each_with_index do |val, idx|
    out[idx.to_s] = val
  end
  out
end