Class: HTTP::Response::Status
- Inherits:
-
Delegator
- Object
- Delegator
- HTTP::Response::Status
- Defined in:
- lib/http/response/status.rb,
lib/http/response/status/reasons.rb
Constant Summary collapse
- SYMBOLS =
Code to Symbol map
Hash[REASONS.map { |k, v| [k, symbolize(v)] }].freeze
- SYMBOL_CODES =
Reversed SYMBOLS map.
Hash[SYMBOLS.map { |k, v| [v, k] }].freeze
- REASONS =
Code to Reason map
{ 100 => "Continue", 101 => "Switching Protocols", 102 => "Processing", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 207 => "Multi-Status", 208 => "Already Reported", 226 => "IM Used", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 307 => "Temporary Redirect", 308 => "Permanent Redirect", 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 => "Payload Too Large", 414 => "URI Too Long", 415 => "Unsupported Media Type", 416 => "Range Not Satisfiable", 417 => "Expectation Failed", 421 => "Misdirected Request", 422 => "Unprocessable Entity", 423 => "Locked", 424 => "Failed Dependency", 426 => "Upgrade Required", 428 => "Precondition Required", 429 => "Too Many Requests", 431 => "Request Header Fields Too Large", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported", 506 => "Variant Also Negotiates", 507 => "Insufficient Storage", 508 => "Loop Detected", 510 => "Not Extended", 511 => "Network Authentication Required" }.each { |_, v| v.freeze }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Fixnum
readonly
Status code.
Class Method Summary collapse
-
.coerce(object) ⇒ Status
(also: [])
Coerces given value to Status.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(obj) ⇒ Object
-
#inspect ⇒ Object
Printable version of HTTP Status, surrounded by quote marks, with special characters escaped.
-
#reason ⇒ String?
Status message.
-
#to_s ⇒ String
String representation of HTTP status.
-
#to_sym ⇒ nil, Symbol
(also: #symbolize)
Symbolized #reason.
Instance Attribute Details
#code ⇒ Fixnum (readonly)
Returns status code.
73 74 75 |
# File 'lib/http/response/status.rb', line 73 def code @code end |
Class Method Details
.coerce(object) ⇒ Status Also known as: []
Coerces given value to Status.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/http/response/status.rb', line 20 def coerce(object) code = case when object.is_a?(String) then SYMBOL_CODES[symbolize object] when object.is_a?(Symbol) then SYMBOL_CODES[object] when object.is_a?(Numeric) then object.to_i end return new code if code fail Error, "Can't coerce #{object.class}(#{object}) to #{self}" end |
Instance Method Details
#__getobj__ ⇒ Object
117 118 119 |
# File 'lib/http/response/status.rb', line 117 def __getobj__ @code end |
#__setobj__(obj) ⇒ Object
113 114 115 |
# File 'lib/http/response/status.rb', line 113 def __setobj__(obj) @code = obj.to_i end |
#inspect ⇒ Object
Printable version of HTTP Status, surrounded by quote marks, with special characters escaped.
(see String#inspect)
101 102 103 |
# File 'lib/http/response/status.rb', line 101 def inspect "#<#{self.class} #{self}>" end |
#reason ⇒ String?
Returns status message.
77 78 79 |
# File 'lib/http/response/status.rb', line 77 def reason REASONS[code] end |
#to_s ⇒ String
Returns string representation of HTTP status.
82 83 84 |
# File 'lib/http/response/status.rb', line 82 def to_s "#{code} #{reason}".strip end |