Class: Typhoeus::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
15
16
17
# File 'lib/typhoeus/response.rb', line 8

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def headers
  @headers
end

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/typhoeus/response.rb', line 3

def request
  @request
end

#requested_http_methodObject (readonly)

Returns the value of attribute requested_http_method.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def requested_http_method
  @requested_http_method
end

#requested_remote_methodObject (readonly)

Returns the value of attribute requested_remote_method.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def requested_remote_method
  @requested_remote_method
end

#requested_urlObject (readonly)

Returns the value of attribute requested_url.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def requested_url
  @requested_url
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def start_time
  @start_time
end

#timeObject (readonly)

Returns the value of attribute time.



4
5
6
# File 'lib/typhoeus/response.rb', line 4

def time
  @time
end

Instance Method Details

#headers_hashObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/typhoeus/response.rb', line 19

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