class Dox::Entities::Example
Attributes
desc[R]
name[R]
request[R]
request_schema[R]
response[R]
response_schema_fail[R]
response_schema_success[R]
Public Class Methods
new(details, request, response)
click to toggle source
# File lib/dox/entities/example.rb, line 13 def initialize(details, request, response) @desc = details[:description] @name = details[:resource_name].downcase @request_schema = details[:action_request_schema] @response_schema_success = details[:action_response_schema_success] @response_schema_fail = details[:action_response_schema_fail] @request = request @response = response end
Public Instance Methods
request_body()
click to toggle source
# File lib/dox/entities/example.rb, line 23 def request_body @request_body ||= format_content(request, request_content_type) end
request_fullpath()
click to toggle source
Rails 4 includes the body params in the request_fullpath
# File lib/dox/entities/example.rb, line 48 def request_fullpath if request.query_parameters.present? "#{request_path}?#{request_url_query_parameters}" else request_path end end
request_headers()
click to toggle source
# File lib/dox/entities/example.rb, line 39 def request_headers @request_headers ||= filter_headers(request) end
request_identifier()
click to toggle source
# File lib/dox/entities/example.rb, line 31 def request_identifier @desc end
response_body()
click to toggle source
# File lib/dox/entities/example.rb, line 27 def response_body @response_body ||= format_content(response, response_content_type) end
response_headers()
click to toggle source
# File lib/dox/entities/example.rb, line 35 def response_headers @response_headers ||= filter_headers(response) end
response_success?()
click to toggle source
# File lib/dox/entities/example.rb, line 43 def response_success? response.successful? end
Private Instance Methods
filter_headers(obj)
click to toggle source
# File lib/dox/entities/example.rb, line 82 def filter_headers(obj) headers_whitelist.map do |header| header_val = obj.headers[header] next if header_val.blank? [header, header_val] end.compact end
format_content(http_env, content_type)
click to toggle source
# File lib/dox/entities/example.rb, line 58 def format_content(http_env, content_type) formatter(content_type).new(http_env).format end
formatter(content_type)
click to toggle source
# File lib/dox/entities/example.rb, line 62 def formatter(content_type) case content_type when %r{application\/.*json} Dox::Formatters::Json when /xml/ Dox::Formatters::Xml when /multipart/ Dox::Formatters::Multipart else Dox::Formatters::Plain end end
headers_whitelist()
click to toggle source
# File lib/dox/entities/example.rb, line 91 def headers_whitelist @headers_whitelist ||= Dox.full_headers_whitelist end
request_path()
click to toggle source
Rails 5.0.2 returns “” for request.path
# File lib/dox/entities/example.rb, line 76 def request_path request.path.presence || request.fullpath.split('?')[0] end
request_url_query_parameters()
click to toggle source
# File lib/dox/entities/example.rb, line 95 def request_url_query_parameters CGI.unescape(request.query_parameters.to_query) end