Class: TreatanyoneCommonApi::Handler::Request
- Inherits:
-
Object
- Object
- TreatanyoneCommonApi::Handler::Request
- Defined in:
- lib/treatanyone_common_api/handler/request.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns a Hash with symbolized, snakecase keys or nil NOTE: this is not the handler argument context (event:, context: <– not this one).
-
#headers ⇒ Object
readonly
Returns a Hash with string keys or nil.
Instance Method Summary collapse
-
#initialize(args) ⇒ Request
constructor
A new instance of Request.
-
#params ⇒ Object
Returns a Hash with symbolized, snakecase keys.
-
#query_params ⇒ Object
Returns a Hash with symbolized, snakecase keys.
Constructor Details
#initialize(args) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 |
# File 'lib/treatanyone_common_api/handler/request.rb', line 6 def initialize(args) @event = args @context = args['requestContext'] @headers = args['headers'] @params = args['body'] @params = JSON.parse(@params) if @params.is_a? String @query_params = args['queryStringParameters'] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns a Hash with symbolized, snakecase keys or nil NOTE: this is not the handler argument context (event:, context: <– not this one)
17 18 19 |
# File 'lib/treatanyone_common_api/handler/request.rb', line 17 def context @context end |
#headers ⇒ Object (readonly)
Returns a Hash with string keys or nil
20 21 22 |
# File 'lib/treatanyone_common_api/handler/request.rb', line 20 def headers @headers end |
Instance Method Details
#params ⇒ Object
Returns a Hash with symbolized, snakecase keys
23 24 25 26 27 |
# File 'lib/treatanyone_common_api/handler/request.rb', line 23 def params return {} if @params.nil? @params.transform_keys { |key| snakecase(key).to_sym } end |
#query_params ⇒ Object
Returns a Hash with symbolized, snakecase keys
30 31 32 33 34 |
# File 'lib/treatanyone_common_api/handler/request.rb', line 30 def query_params return {} if @query_params.nil? @query_params.transform_keys { |key| snakecase(key).to_sym } end |