Class: Raddocs::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/raddocs/models.rb

Overview

Documented response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Request

Returns a new instance of Request.

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • "request_headers" (Hash)

    Hash of request headers, not in rack format

  • "request_method" (String)
  • "request_path" (String)
  • "request_query_parameters" (Hash)

    Query parameters pulled from the request if a GET request

  • "request_body" (String)
  • "curl" (String)

    Formatted cURL request

  • "response_status" (String)
  • "response_headers" (Hash)

    Hash of response headers, not in rack format

  • "response_body" (String)


225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/raddocs/models.rb', line 225

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

Instance Attribute Details

#curlObject (readonly)

Returns the value of attribute curl.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def curl
  @curl
end

#request_bodyObject (readonly)

Returns the value of attribute request_body.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def request_body
  @request_body
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def request_method
  @request_method
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def request_path
  @request_path
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def response_body
  @response_body
end

#response_statusObject (readonly)

Returns the value of attribute response_status.



208
209
210
# File 'lib/raddocs/models.rb', line 208

def response_status
  @response_status
end

Instance Method Details

#curl?Boolean

Returns true if cURL command is present.

Returns:

  • (Boolean)

    true if cURL command is present



268
269
270
# File 'lib/raddocs/models.rb', line 268

def curl?
  !@curl.nil?
end

#request_body?Boolean

Returns true if request body is present.

Returns:

  • (Boolean)

    true if request body is present



257
258
259
# File 'lib/raddocs/models.rb', line 257

def request_body?
  !@request_body.nil?
end

#request_content_typeString

Request headers must be set

Returns:

  • (String)

    Content type of the request



263
264
265
# File 'lib/raddocs/models.rb', line 263

def request_content_type
  @request_headers["Content-Type"]
end

#request_headersObject

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



240
241
242
243
244
# File 'lib/raddocs/models.rb', line 240

def request_headers
  @request_headers.map do |header, value|
    "#{header}: #{value}"
  end.join("\n")
end

#request_query_parametersString

Returns joined query parameters, eg: “key=valuenkey=value”.

Returns:

  • (String)

    joined query parameters, eg: “key=valuenkey=value”



247
248
249
# File 'lib/raddocs/models.rb', line 247

def request_query_parameters
  @request_query_parameters.map { |k,v| "#{k}=#{v}" }.join("\n")
end

#request_query_parameters?Boolean

Returns true if request query parameters are present.

Returns:

  • (Boolean)

    true if request query parameters are present



252
253
254
# File 'lib/raddocs/models.rb', line 252

def request_query_parameters?
  !@request_query_parameters.empty?
end

#response?Boolean

Returns true if the response is present.

Returns:

  • (Boolean)

    true if the response is present



273
274
275
# File 'lib/raddocs/models.rb', line 273

def response?
  !@response_status.nil?
end

#response_body?Boolean

Returns true if response body is present.

Returns:

  • (Boolean)

    true if response body is present



285
286
287
# File 'lib/raddocs/models.rb', line 285

def response_body?
  !@response_body.nil?
end

#response_content_typeString

Response headers must be set

Returns:

  • (String)

    Content type of the response



291
292
293
# File 'lib/raddocs/models.rb', line 291

def response_content_type
  @response_headers["Content-Type"]
end

#response_headersObject

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



278
279
280
281
282
# File 'lib/raddocs/models.rb', line 278

def response_headers
  @response_headers.map do |header, value|
    "#{header}: #{value}"
  end.join("\n")
end