Sha256: f86aa462c5786044b96ce54d70202d8c2c24dfc0b1555fa5172060103e9a2e3b

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

module Typhoeus
  class Response
    attr_accessor :request
    attr_reader :code, :headers, :body, :time,
                :requested_url, :requested_remote_method,
                :requested_http_method, :start_time,
                :effective_url

    def initialize(params = {})
      @code                  = params[:code]
      @headers               = params[:headers]
      @body                  = params[:body]
      @time                  = params[:time]
      @requested_url         = params[:requested_url]
      @requested_http_method = params[:requested_http_method]
      @start_time            = params[:start_time]
      @request               = params[:request]
      @effective_url         = params[:effective_url]
    end

    def headers_hash
      headers.split("\n").map {|o| o.strip}.inject({}) do |hash, o|
        if o.empty?
          hash
        else
          i = o.index(":") || o.size
          key = o.slice(0, i)
          value = o.slice(i + 1, o.size)
          value = value.strip unless value.nil?
          if hash.has_key? key
            hash[key] = [hash[key], value].flatten
          else
            hash[key] = value
          end

          hash
        end
      end
    end

    def success?
      @code >= 200 && @code < 300
    end

    def modified?
      @code != 304
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
fblee-typhoeus-0.1.31 lib/typhoeus/response.rb
tech-angels-typhoeus-0.1.36 lib/typhoeus/response.rb
typhoeus-0.1.31 lib/typhoeus/response.rb
typhoeus-0.1.30 lib/typhoeus/response.rb
typhoeus-0.1.29 lib/typhoeus/response.rb
gravis-typhoeus-0.1.36 lib/typhoeus/response.rb
typhoeus-0.1.28 lib/typhoeus/response.rb
gravis-typhoeus-0.1.35 lib/typhoeus/response.rb
gravis-typhoeus-0.1.34 lib/typhoeus/response.rb
gravis-typhoeus-0.1.33 lib/typhoeus/response.rb
gravis-typhoeus-0.1.32 lib/typhoeus/response.rb
gravis-typhoeus-0.1.31 lib/typhoeus/response.rb
gravis-typhoeus-0.1.30 lib/typhoeus/response.rb
gravis-typhoeus-0.1.29 lib/typhoeus/response.rb
typhoeus-0.1.27 lib/typhoeus/response.rb
typhoeus-0.1.26 lib/typhoeus/response.rb
typhoeus-0.1.25 lib/typhoeus/response.rb