class Fictium::ApiBlueprintExporter::ExampleFormatter
Protected Instance Methods
format_sections(example)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 6 def format_sections(example) [format_request(example), format_response(example)] end
Private Instance Methods
format_request(example)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 12 def format_request(example) return '' if example.request.blank? return '' if example.request[:body].blank? result = request_head(example) result += "\n #{example.description}\n" if example.description.present? result += parse_http_object(example.request) result end
format_response(example)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 22 def format_response(example) return '' if example.response.blank? result = response_head(example) result += parse_http_object(example.response) result end
parse_body(http_element)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 56 def parse_body(http_element) return "\n + Body" if http_element[:body].blank? <<~HEREDOC \x20 + Body ``` #{http_element[:body]} ``` HEREDOC end
parse_header(header)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 34 def parse_header(header) return '' if header.blank? mapped_headers = header.map do |key, value| " #{key}: #{value}" end <<~HEREDOC \x20 + Header #{mapped_headers.join("\n")} HEREDOC end
parse_http_object(http_object)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 30 def parse_http_object(http_object) "#{parse_header(http_object[:header])}#{parse_body(http_object)}" end
request_head(example)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 48 def request_head(example) "+ Request #{example.summary} \n" end
response_head(example)
click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter/example_formatter.rb, line 52 def response_head(example) "+ Response #{example.response[:status]} (#{example.response[:content_type]})\n" end