Class: OpenapiFirst::ResponseParser
- Inherits:
-
Object
- Object
- OpenapiFirst::ResponseParser
- Defined in:
- lib/openapi_first/response_parser.rb
Overview
Parse a response
Instance Method Summary collapse
-
#initialize(headers:, content_type:) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #parse(rack_response) ⇒ Object
Constructor Details
#initialize(headers:, content_type:) ⇒ ResponseParser
Returns a new instance of ResponseParser.
10 11 12 13 |
# File 'lib/openapi_first/response_parser.rb', line 10 def initialize(headers:, content_type:) @headers_parser = build_headers_parser(headers) @body_parser = ResponseBodyParsers[content_type] end |
Instance Method Details
#parse(rack_response) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/openapi_first/response_parser.rb', line 15 def parse(rack_response) ParsedResponse.new( body: @body_parser.call(read_body(rack_response)), headers: @headers_parser&.call(rack_response.headers) || {} ) end |