Sha256: 1c13253739161c54104201c8562a8f5b7243ccc0300a78342d652f33ce74fc58

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 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
    
    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]
    end
    
    def headers_hash
      headers.split("\n").map {|o| o.strip}.inject({}) do |hash, o|
        if o.empty?
          hash
        else
          o = o.split(":")
          key = o.first.strip
          value = o.last ? o.last.strip : nil
          if hash.has_key? key
            hash[key] = [hash[key], value].flatten
          else
            hash[key] = value
          end
          
          hash
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typhoeus-0.1.21 lib/typhoeus/response.rb
typhoeus-0.1.20 lib/typhoeus/response.rb