Class: Typhoeus::Response
- Inherits:
-
Object
- Object
- Typhoeus::Response
- Defined in:
- lib/typhoeus/response.rb
Instance Attribute Summary collapse
-
#app_connect_time ⇒ Object
readonly
Returns the value of attribute app_connect_time.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#connect_time ⇒ Object
readonly
Returns the value of attribute connect_time.
-
#curl_error_message ⇒ Object
readonly
Returns the value of attribute curl_error_message.
-
#curl_return_code ⇒ Object
readonly
Returns the value of attribute curl_return_code.
-
#effective_url ⇒ Object
readonly
Returns the value of attribute effective_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
- #headers_hash ⇒ Object
-
#mock ⇒ Object
Returns the value of attribute mock.
-
#name_lookup_time ⇒ Object
readonly
Returns the value of attribute name_lookup_time.
-
#pretransfer_time ⇒ Object
readonly
Returns the value of attribute pretransfer_time.
-
#primary_ip ⇒ Object
readonly
Returns the value of attribute primary_ip.
-
#redirect_count ⇒ Object
readonly
Returns the value of attribute redirect_count.
-
#request ⇒ Object
Returns the value of attribute request.
-
#requested_http_method ⇒ Object
readonly
Returns the value of attribute requested_http_method.
-
#requested_remote_method ⇒ Object
readonly
Returns the value of attribute requested_remote_method.
-
#requested_url ⇒ Object
readonly
Returns the value of attribute requested_url.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#start_transfer_time ⇒ Object
readonly
Returns the value of attribute start_transfer_time.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #http_version ⇒ Object
-
#initialize(params = {}) ⇒ Response
constructor
A new instance of Response.
-
#mock? ⇒ Boolean
Returns true if this is a mock response.
- #modified? ⇒ Boolean
- #status_message ⇒ Object
- #success? ⇒ Boolean
- #timed_out? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/typhoeus/response.rb', line 15 def initialize(params = {}) @code = params[:code] @curl_return_code = params[:curl_return_code] @curl_error_message = params[:curl_error_message] @status_message = params[:status_message] @http_version = params[:http_version] @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] @start_transfer_time = params[:start_transfer_time] @app_connect_time = params[:app_connect_time] @pretransfer_time = params[:pretransfer_time] @connect_time = params[:connect_time] @name_lookup_time = params[:name_lookup_time] @request = params[:request] @effective_url = params[:effective_url] @primary_ip = params[:primary_ip] @redirect_count = params[:redirect_count] @mock = params[:mock] || false # default @headers_hash = Header.new(params[:headers_hash]) if params[:headers_hash] end |
Instance Attribute Details
#app_connect_time ⇒ Object (readonly)
Returns the value of attribute app_connect_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def app_connect_time @app_connect_time end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def code @code end |
#connect_time ⇒ Object (readonly)
Returns the value of attribute connect_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def connect_time @connect_time end |
#curl_error_message ⇒ Object (readonly)
Returns the value of attribute curl_error_message.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def @curl_error_message end |
#curl_return_code ⇒ Object (readonly)
Returns the value of attribute curl_return_code.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def curl_return_code @curl_return_code end |
#effective_url ⇒ Object (readonly)
Returns the value of attribute effective_url.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def effective_url @effective_url end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def headers @headers end |
#headers_hash ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/typhoeus/response.rb', line 49 def headers_hash @headers_hash ||= begin headers.split("\n").map {|o| o.strip}.inject(Typhoeus::Header.new) do |hash, o| if o.empty? || o =~ /^HTTP\/[\d\.]+/ 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.key? key hash[key] = [hash[key], value].flatten else hash[key] = value end hash end end end end |
#mock ⇒ Object
Returns the value of attribute mock.
3 4 5 |
# File 'lib/typhoeus/response.rb', line 3 def mock @mock end |
#name_lookup_time ⇒ Object (readonly)
Returns the value of attribute name_lookup_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def name_lookup_time @name_lookup_time end |
#pretransfer_time ⇒ Object (readonly)
Returns the value of attribute pretransfer_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def pretransfer_time @pretransfer_time end |
#primary_ip ⇒ Object (readonly)
Returns the value of attribute primary_ip.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def primary_ip @primary_ip end |
#redirect_count ⇒ Object (readonly)
Returns the value of attribute redirect_count.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def redirect_count @redirect_count end |
#request ⇒ Object
Returns the value of attribute request.
3 4 5 |
# File 'lib/typhoeus/response.rb', line 3 def request @request end |
#requested_http_method ⇒ Object (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_method ⇒ Object (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_url ⇒ Object (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_time ⇒ Object (readonly)
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def start_time @start_time end |
#start_transfer_time ⇒ Object (readonly)
Returns the value of attribute start_transfer_time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def start_transfer_time @start_transfer_time end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/typhoeus/response.rb', line 4 def time @time end |
Instance Method Details
#http_version ⇒ Object
88 89 90 |
# File 'lib/typhoeus/response.rb', line 88 def http_version @http_version ||= first_header_line ? first_header_line[/HTTP\/(\S+)/, 1] : nil end |
#mock? ⇒ Boolean
Returns true if this is a mock response.
41 42 43 |
# File 'lib/typhoeus/response.rb', line 41 def mock? @mock end |
#modified? ⇒ Boolean
96 97 98 |
# File 'lib/typhoeus/response.rb', line 96 def modified? @code != 304 end |
#status_message ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/typhoeus/response.rb', line 71 def return @status_message if @status_message != nil # HTTP servers can choose not to include the explanation to HTTP codes. The RFC # states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4): # Except when responding to a HEAD request, the server SHOULD include an entity containing # an explanation of the error situation [...] # This means 'HTTP/1.1 404' is as valid as 'HTTP/1.1 404 Not Found' and we have to handle it. # Regexp doc: http://rubular.com/r/eAr1oVYsVa if first_header_line != nil and first_header_line[/\d{3} (.*)$/, 1] != nil @status_message = first_header_line[/\d{3} (.*)$/, 1].chomp else @status_message = nil end end |
#success? ⇒ Boolean
92 93 94 |
# File 'lib/typhoeus/response.rb', line 92 def success? @code >= 200 && @code < 300 end |
#timed_out? ⇒ Boolean
100 101 102 |
# File 'lib/typhoeus/response.rb', line 100 def timed_out? curl_return_code == 28 end |