Class: HyperSpec::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/hyperspec.rb

Constant Summary collapse

STATI =
{
  # 2xx
  200 => :ok,
  201 => :created,

  # 4xx
  401 => :unauthorized,
  411 => :length_required,

  # WebDav extensions
  422 => :unprocessable_entity,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



130
131
132
# File 'lib/hyperspec.rb', line 130

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



130
131
132
# File 'lib/hyperspec.rb', line 130

def headers
  @headers
end

#status_codeObject

Returns the value of attribute status_code

Returns:

  • (Object)

    the current value of status_code



130
131
132
# File 'lib/hyperspec.rb', line 130

def status_code
  @status_code
end

Class Method Details

.from_net_http_response(http) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'lib/hyperspec.rb', line 144

def self.from_net_http_response(http)
  status_code = http.code.to_i
  body        = http.body

  headers =
    CaseInsensitiveHash.from_hash(http.to_hash)

  new(status_code, headers, body)
end

Instance Method Details

#content_charsetObject



158
159
160
# File 'lib/hyperspec.rb', line 158

def content_charset
  (md = headers['Content-Type'].match(/;charset=(.*)/)) && md[1]
end

#content_typeObject



154
155
156
# File 'lib/hyperspec.rb', line 154

def content_type
  headers['Content-Type'].split(';').first
end

#statusObject



162
163
164
# File 'lib/hyperspec.rb', line 162

def status
  STATI[status_code]
end