class Raddocs::Request

Documented response

@param attributes [Hash]

Attributes

curl[R]
request_body[R]
request_method[R]
request_path[R]
response_body[R]
response_status[R]

Public Class Methods

new(attributes) click to toggle source

@param attributes [Hash] @option attributes [Hash] “request_headers”

Hash of request headers, not in rack format

@option attributes [String] “request_method” @option attributes [String] “request_path” @option attributes [Hash] “request_query_parameters”

Query parameters pulled from the request if a GET request

@option attributes [String] “request_body” @option attributes [String] “curl” Formatted

cURL request

@option attributes [String] “response_status” @option attributes [Hash] “response_headers”

Hash of response headers, not in rack format

@option attributes [String] “response_body”

# File lib/raddocs/models.rb, line 249
def initialize(attributes)
  @attrs = attributes

  @request_headers = attributes.fetch("request_headers")
  @request_method = attributes.fetch("request_method")
  @request_path = attributes.fetch("request_path")
  @request_query_parameters = attributes.fetch("request_query_parameters", nil)
  @request_body = attributes.fetch("request_body", nil)
  @curl = attributes.fetch("curl", nil)
  @response_status = attributes.fetch("response_status")
  @response_headers = attributes.fetch("response_headers", {})
  @response_body = attributes.fetch("response_body", nil)
end

Public Instance Methods

curl?() click to toggle source

@return [Boolean] true if cURL command is present

# File lib/raddocs/models.rb, line 297
def curl?
  !@curl.nil?
end
request_body?() click to toggle source

@return [Boolean] true if request body is present

# File lib/raddocs/models.rb, line 281
def request_body?
  !@request_body.nil?
end
request_content_type() click to toggle source

Request headers must be set @return [String] Content type of the request

# File lib/raddocs/models.rb, line 292
def request_content_type
  @request_headers["Content-Type"]
end
request_headers() click to toggle source

There are unwanted indents if this was a simple each and output in haml

# File lib/raddocs/models.rb, line 264
def request_headers
  @request_headers.map do |header, value|
    "#{header}: #{value}"
  end.join("\n")
end
request_headers?() click to toggle source

@return [Boolean] true if request headers are present

# File lib/raddocs/models.rb, line 286
def request_headers?
  request_headers.length > 0
end
request_query_parameters() click to toggle source

@return [String] joined query parameters, eg: “key=valuenkey=value”

# File lib/raddocs/models.rb, line 271
def request_query_parameters
  @request_query_parameters.map { |k,v| "#{k}=#{v}" }.join("\n")
end
request_query_parameters?() click to toggle source

@return [Boolean] true if request query parameters are present

# File lib/raddocs/models.rb, line 276
def request_query_parameters?
  !@request_query_parameters.empty?
end
response?() click to toggle source

@return [Boolean] true if the response is present

# File lib/raddocs/models.rb, line 302
def response?
  !@response_status.nil?
end
response_body?() click to toggle source

@return [Boolean] true if response body is present

# File lib/raddocs/models.rb, line 314
def response_body?
  !@response_body.nil?
end
response_content_type() click to toggle source

Response headers must be set @return [String] Content type of the response

# File lib/raddocs/models.rb, line 325
def response_content_type
  @response_headers["Content-Type"]
end
response_headers() click to toggle source

There are unwanted indents if this was a simple each and output in haml

# File lib/raddocs/models.rb, line 307
def response_headers
  @response_headers.map do |header, value|
    "#{header}: #{value}"
  end.join("\n")
end
response_headers?() click to toggle source

@return [Boolean] true if response headers are present

# File lib/raddocs/models.rb, line 319
def response_headers?
  response_headers.length > 0
end