Class: JSONAPIonify::Api::Server::MockResponse
- Inherits:
-
Object
- Object
- JSONAPIonify::Api::Server::MockResponse
- Defined in:
- lib/jsonapionify/api/server/mock_response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #http_string ⇒ Object
-
#initialize(status, headers, body) ⇒ MockResponse
constructor
A new instance of MockResponse.
Constructor Details
#initialize(status, headers, body) ⇒ MockResponse
Returns a new instance of MockResponse.
7 8 9 10 11 |
# File 'lib/jsonapionify/api/server/mock_response.rb', line 7 def initialize(status, headers, body) @status = status @body = body.is_a?(Rack::BodyProxy) ? body.body : body @headers = Rack::Utils::HeaderHash.new headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/jsonapionify/api/server/mock_response.rb', line 5 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/jsonapionify/api/server/mock_response.rb', line 5 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/jsonapionify/api/server/mock_response.rb', line 5 def status @status end |
Instance Method Details
#http_string ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jsonapionify/api/server/mock_response.rb', line 20 def http_string # HTTP/1.1 200 OK # Date: Fri, 31 Dec 1999 23:59:59 GMT # Content-Type: text/html # Content-Length: 1354 # # <body> [].tap do |lines| lines << "HTTP/1.1 #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}" headers.each do |k, v| lines << "#{k.split('-').map(&:capitalize).join('-')}: #{v}" end lines << '' lines << body if body.present? end.join("\n") end |