Sha256: 9b83b3c6aa3726e70cdc776489e5770bea428a7c87cf1e673d4dad4fa5dcde67

Contents?: true

Size: 1.61 KB

Versions: 21

Compression:

Stored size: 1.61 KB

Contents

require 'typhoeus/response/header'
require 'typhoeus/response/informations'
require 'typhoeus/response/status'
require 'typhoeus/response/cacheable'

module Typhoeus

  # This class represents the response.
  class Response
    include Response::Informations
    include Response::Status
    include Response::Cacheable

    # Remembers the corresponding request.
    #
    # @example Get request.
    #   request = Typhoeus::Request.get("www.example.com")
    #   response = request.run
    #   request == response.request
    #   #=> true
    #
    # @return [ Typhoeus::Request ]
    attr_accessor :request

    # The provided options, which contain all the
    # informations about the request.
    #
    # @return [ Hash ]
    attr_accessor :options

    # Set the handled response.
    attr_writer :handled_response

    # @api private
    attr_writer :mock

    # Create a new response.
    #
    # @example Create a response.
    #  Response.new
    #
    # @param [ Hash ] options The options hash.
    #
    # @return [ Response ] The new response.
    def initialize(options = {})
      @options = options
      @headers = Header.new(options[:headers]) if options[:headers]
    end

    # Returns whether this request is mocked
    # or not.
    #
    # @api private
    def mock
      defined?(@mock) ? @mock : options[:mock]
    end
    alias :mock? :mock

    # Returns the handled_response if it has
    # been defined; otherwise, returns the response
    #
    # @return [ Object ] The result of callbacks
    #   done on the response or the original response.
    def handled_response
      @handled_response || self
    end
  end
end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/lib/typhoeus/response.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/lib/typhoeus/response.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.3.0/lib/typhoeus/response.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.0/lib/typhoeus/response.rb
typhoeus-1.3.0 lib/typhoeus/response.rb
typhoeus-1.1.2 lib/typhoeus/response.rb
typhoeus-1.1.1 lib/typhoeus/response.rb
typhoeus-1.1.0 lib/typhoeus/response.rb
typhoeus-1.0.2 lib/typhoeus/response.rb
typhoeus-1.0.1 lib/typhoeus/response.rb
typhoeus-1.0.0 lib/typhoeus/response.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/typhoeus-0.8.0/lib/typhoeus/response.rb
typhoeus-0.8.0 lib/typhoeus/response.rb
typhoeus-0.7.3 lib/typhoeus/response.rb
typhoeus-0.7.2 lib/typhoeus/response.rb
typhoeus-0.7.1 lib/typhoeus/response.rb
typhoeus-0.7.0 lib/typhoeus/response.rb
typhoeus-0.7.0.pre1 lib/typhoeus/response.rb
typhoeus-0.6.9 lib/typhoeus/response.rb
typhoeus-0.6.8 lib/typhoeus/response.rb