Class: Response::XML

Inherits:
Response show all
Defined in:
lib/response/xml.rb

Overview

XML response

Constant Summary collapse

HEADERS =
IceNine.deep_freeze('Content-Type' => 'application/xml; charset=UTF-8')

Constants inherited from Response

TEXT_PLAIN, Undefined

Instance Attribute Summary

Attributes inherited from Response

#body, #headers, #status

Class Method Summary collapse

Methods inherited from Response

#cache_control, #content_type, #last_modified, #merge_headers, #rack_array, #to_rack_response, #valid?, #with_body, #with_headers, #with_status

Class Method Details

.build(body) ⇒ Array

Build xml response with defaults

Examples:


# With defaults
response = Response::XML.build("<foo><bar>Hello</bar></foo>")
response.status  # => Response::Status::OK
response.headers # => { 'Content-Type' => 'application/xml; charset=UTF-8' }
response.body    # => "<foo><bar>Hello</bar></foo>"

# With overriding defaults
response = Response::HTML.build("<foo><bar>Hello</bar></foo>") do |response|
  response.with_status(Response::Status::NOT_FOUND)
end
response.status  # => Response::Status::NOT_FOUND
response.headers # => { 'Content-Type' => 'application/xml; charset=UTF-8' }
response.body    # => "<foo><bar>Hello</bar></foo>"

Parameters:

  • body (Object)

    rack compatible body

Returns:

  • (Array)

    rack compatible response array



32
33
34
# File 'lib/response/xml.rb', line 32

def self.build(body)
  super(Status::OK, HEADERS, body)
end