Sha256: 53f573ab547217fe28264f830f99423c65f6ae0c982dc015a3e8f5116cd5cb8f

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# Instances of Response are automatically created by Request, so you do
# not need to make them yourself. This is the object that will be passed
# to each of the callbacks for a Request object. For this reason, this
# object will be created if the request succeeds, or indeed fails.
class Response
  # Private initializer. This handles a native jquery requets object, so
  # this should all probably be private.
  def initialize(request)
    `self.$xhr = request`
  end

  # Returns the numeric status code for the response.
  #
  # @return [Numeric]
  def status
    `return self.$xhr.status;`
  end

  # Returns the string status message for the response.
  #
  # @return [String]
  def status_text
    `return self.$xhr.statusText;`
  end

  # Returns the response text from the request.
  #
  # @return [String]
  def text
    `return self.$xhr.responseText;`
  end

  # Returns `true` if the response represents a successfull request,
  # `false` otherwise.
  #
  # @return [true, false]
  def success?
    `return (self.$xhr.status >= 200 && self.$xhr.status < 300) ? Qtrue : Qfalse;`
  end

  # Returns `false` if the response was the result of an unsuccessful
  # request, `true` otherwise.
  #
  # @return [true, false]
  def failure?
    !success?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-0.3.2 gems/rquery/lib/rquery/response.rb
opal-0.3.1 gems/rquery/lib/rquery/response.rb
opal-0.3.0 gems/rquery/lib/rquery/response.rb