Class: FDK::Call
- Inherits:
-
Object
- Object
- FDK::Call
- Defined in:
- lib/fdk/call.rb
Overview
Call represents a call to the target function or lambda
Constant Summary collapse
- FILTER_HEADERS =
%w[content-length te transfer-encoding upgrade trailer].freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #context ⇒ Object
- #error_response(error:) ⇒ Object
- #filtered_request_header ⇒ Object
- #format_response_body(fn_return:) ⇒ Object
- #good_response ⇒ Object
- #headers_in ⇒ Object
- #headers_out ⇒ Object
-
#initialize(request:, response:) ⇒ Call
constructor
A new instance of Call.
- #input ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize(request:, response:) ⇒ Call
Returns a new instance of Call.
27 28 29 30 |
# File 'lib/fdk/call.rb', line 27 def initialize(request:, response:) @request = request @response = response end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
25 26 27 |
# File 'lib/fdk/call.rb', line 25 def error @error end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
24 25 26 |
# File 'lib/fdk/call.rb', line 24 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
24 25 26 |
# File 'lib/fdk/call.rb', line 24 def response @response end |
Instance Method Details
#context ⇒ Object
32 33 34 |
# File 'lib/fdk/call.rb', line 32 def context @context ||= FDK::Context.new(headers_in, headers_out) end |
#error_response(error:) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/fdk/call.rb', line 72 def error_response(error:) response["content-type"] = "application/json" response.status = 502 response.body = { message: "An error occurred in the function", detail: error.to_s }.to_json end |
#filtered_request_header ⇒ Object
48 49 50 |
# File 'lib/fdk/call.rb', line 48 def filtered_request_header request.header.reject { |k| FILTER_HEADERS.include? k } end |
#format_response_body(fn_return:) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/fdk/call.rb', line 60 def format_response_body(fn_return:) return response.body = fn_return.to_s unless fn_return.respond_to?(:to_json) response.body = fn_return.to_json response["content-type"] = "application/json" unless response["content-type"] end |
#good_response ⇒ Object
67 68 69 70 |
# File 'lib/fdk/call.rb', line 67 def good_response response.status = 200 headers_out.each { |k, v| response[k] = v.join(",") } end |
#headers_in ⇒ Object
44 45 46 |
# File 'lib/fdk/call.rb', line 44 def headers_in @headers_in ||= FDK::InHeaders.new(filtered_request_header, nil) end |
#headers_out ⇒ Object
40 41 42 |
# File 'lib/fdk/call.rb', line 40 def headers_out @headers_out ||= FDK::OutHeaders.new({}, nil) end |
#input ⇒ Object
36 37 38 |
# File 'lib/fdk/call.rb', line 36 def input @input ||= ParsedInput.new(raw_input: request.body.to_s) end |