Class: HTTP::Response::Status

### Home Classes Methods

### In Files

- lib/http/response/status.rb
- lib/http/response/status/reasons.rb

### Parent

Delegator

### Methods

- ::[]
- ::coerce
- #__getobj__
- #__setobj__
- #inspect
- #reason
- #symbolize
- #to_s
- #to_sym

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Response::Status

### Constants

REASONS

  Code to Reason map

  @example Usage

      REASONS[400] # => "Bad Request"
      REASONS[414] # => "Request-URI Too Long"

  @return [Hash<Fixnum => String>]

SYMBOLS

  Code to Symbol map

  @example Usage

      SYMBOLS[400] # => :bad_request
      SYMBOLS[414] # => :request_uri_too_long
      SYMBOLS[418] # => :im_a_teapot

  @return [Hash<Fixnum => Symbol>]

SYMBOL_CODES

  Reversed {SYMBOLS} map.

  @example Usage

      SYMBOL_CODES[:bad_request]           # => 400
      SYMBOL_CODES[:request_uri_too_long]  # => 414
      SYMBOL_CODES[:im_a_teapot]           # => 418

  @return [Hash<Symbol => Fixnum>]

### Attributes

code[R]

@return [Fixnum] status code

### Public Class Methods

[](object) click to toggle source
Alias for: coerce
coerce(object) click to toggle source

Coerces given value to Status.

@example

    Status.coerce(:bad_request) # => Status.new(400)
    Status.coerce("400")        # => Status.new(400)
    Status.coerce(true)         # => raises HTTP::Error

@raise [Error] if coercion is impossible @param [Symbol, to_i] object @return [Status]

    # 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

Also aliased as: []

### Public Instance Methods

__getobj__() click to toggle source

    # File lib/http/response/status.rb, line 117
    def __getobj__
      @code
    end

__setobj__(obj) click to toggle source

    # File lib/http/response/status.rb, line 113
    def __setobj__(obj)
      @code = obj.to_i
    end

inspect() click to toggle source

Printable version of HTTP Status, surrounded by quote marks, with special characters escaped.

(see String#inspect)

    # File lib/http/response/status.rb, line 101
    def inspect
      "#<#{self.class} #{self}>"
    end

reason() click to toggle source

@see REASONS @return [String, nil] status message

    # File lib/http/response/status.rb, line 77
    def reason
      REASONS[code]
    end

symbolize() click to toggle source

@deprecated Will be removed in 1.0.0

Alias for: to_sym
to_s() click to toggle source

@return [String] string representation of HTTP status

    # File lib/http/response/status.rb, line 82
    def to_s
      "#{code} #{reason}".strip
    end

to_sym() click to toggle source

Symbolized {reason}

@return [nil] unless code is well-known (see REASONS) @return [Symbol]

    # File lib/http/response/status.rb, line 90
    def to_sym
      SYMBOLS[code]
    end

Also aliased as: symbolize

[Validate]

Generated with the Darkfish Rdoc Generator 2.