Class: Rsodx::Request
- Inherits:
-
Object
- Object
- Rsodx::Request
- Defined in:
- lib/rsodx/request.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(verb:, path:, request:) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
- #payload ⇒ Object
Constructor Details
#initialize(verb:, path:, request:) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 |
# File 'lib/rsodx/request.rb', line 5 def initialize(verb:, path:, request:) @verb = verb.to_s.upcase @path = path @request = request @parsed_payload = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/rsodx/request.rb', line 3 def path @path end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/rsodx/request.rb', line 3 def request @request end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
3 4 5 |
# File 'lib/rsodx/request.rb', line 3 def verb @verb end |
Instance Method Details
#headers ⇒ Object
12 13 14 |
# File 'lib/rsodx/request.rb', line 12 def headers @headers ||= Rsodx::Headers.new(request) end |
#params ⇒ Object
16 17 18 |
# File 'lib/rsodx/request.rb', line 16 def params request.params.transform_keys(&:to_sym).merge(payload) end |
#payload ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rsodx/request.rb', line 20 def payload return @parsed_payload if @parsed_payload request.body.rewind raw = request.body.read.strip if raw.empty? || raw == 'null' @parsed_payload = {} elsif raw.start_with?("{") && raw.end_with?("}") begin @parsed_payload = JSON.parse(raw, symbolize_names: true) rescue JSON::ParserError @parsed_payload = {} end else @parsed_payload = {} end end |