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 =
["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.
10 11 12 13 |
# File 'lib/fdk/call.rb', line 10 def initialize(request:, response:) @request = request @response = response end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
8 9 10 |
# File 'lib/fdk/call.rb', line 8 def error @error end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/fdk/call.rb', line 7 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/fdk/call.rb', line 7 def response @response end |
Instance Method Details
#context ⇒ Object
15 16 17 |
# File 'lib/fdk/call.rb', line 15 def context @context ||= FDK::Context.new(headers_in, headers_out) end |
#error_response(error:) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/fdk/call.rb', line 55 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
31 32 33 |
# File 'lib/fdk/call.rb', line 31 def filtered_request_header request.header.reject { |k| FILTER_HEADERS.include? k } end |
#format_response_body(fn_return:) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/fdk/call.rb', line 43 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
50 51 52 53 |
# File 'lib/fdk/call.rb', line 50 def good_response response.status = 200 headers_out.each { |k, v| response[k] = v.join(",") } end |
#headers_in ⇒ Object
27 28 29 |
# File 'lib/fdk/call.rb', line 27 def headers_in @headers_in ||= FDK::InHeaders.new(filtered_request_header, nil) end |
#headers_out ⇒ Object
23 24 25 |
# File 'lib/fdk/call.rb', line 23 def headers_out @headers_out ||= FDK::OutHeaders.new({}, nil) end |
#input ⇒ Object
19 20 21 |
# File 'lib/fdk/call.rb', line 19 def input @input ||= ParsedInput.new(raw_input: request.body.to_s) end |