Class: HyperSpec::Response
- Inherits:
-
Struct
- Object
- Struct
- HyperSpec::Response
- Defined in:
- lib/hyperspec.rb
Constant Summary collapse
- STATI =
{ # RFC 2616 - HTTP 1.1 ## Informational 100 => :continue, 101 => :switching_protocols, ## Successful 2xx 200 => :ok, 201 => :created, 202 => :accepted, 203 => :non_authoritative_information, 204 => :no_content, 205 => :reset_content, 206 => :partial_content, ## Redirection 3xx 300 => :multiple_choices, 301 => :moved_permanently, 302 => :found, 303 => :see_other, 304 => :not_modified, 305 => :use_proxy, # 306 => :(Unused), 307 => :temporary_redirect, ## Client Error 4xx, 400 => :bad_request, 401 => :unauthorized, 402 => :payment_required, 403 => :forbidden, 404 => :not_found, 405 => :method_not_allowed, 406 => :not_acceptable, 407 => :proxy_authentication_required, 408 => :request_timeout, 409 => :conflict, 410 => :gone, 411 => :length_required, 412 => :precondition_failed, 413 => :request_entity_too_large, 414 => :request_uri_too_long, 415 => :unsupported_media_type, 416 => :requested_range_not_satisfiable, 417 => :expectation_failed, ## Server Error 5xx 500 => :internal_server_error, 501 => :not_implemented, 502 => :bad_gateway, 503 => :service_unavailable, 504 => :gateway_timeout, 505 => :http_version_not_supported, # RFC 2324 418 => :im_a_teapot, # RFC 4918 - WebDav 207 => :multi_status, 422 => :unprocessable_entity, 423 => :locked, 424 => :failed_dependency, 507 => :insufficient_storage, # RFC 6585 - Additional HTTP Status Codes 428 => :precondition_required, 429 => :too_many_requests, 431 => :request_header_fields_too_large, 511 => :network_authentication_required, }
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
139 140 141 |
# File 'lib/hyperspec.rb', line 139 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
139 140 141 |
# File 'lib/hyperspec.rb', line 139 def headers @headers end |
#status_code ⇒ Object
Returns the value of attribute status_code
139 140 141 |
# File 'lib/hyperspec.rb', line 139 def status_code @status_code end |
Class Method Details
.from_net_http_response(http) ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'lib/hyperspec.rb', line 210 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_charset ⇒ Object
224 225 226 |
# File 'lib/hyperspec.rb', line 224 def content_charset (md = headers['Content-Type'].match(/;charset=(.*)/)) && md[1] end |
#content_type ⇒ Object
220 221 222 |
# File 'lib/hyperspec.rb', line 220 def content_type headers['Content-Type'].split(';').first end |
#status ⇒ Object
228 229 230 |
# File 'lib/hyperspec.rb', line 228 def status STATI[status_code] end |