Class: Typhoeus::Response
- Inherits:
-
Object
- Object
- Typhoeus::Response
- Defined in:
- lib/typhoeus/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#effective_url ⇒ Object
readonly
Returns the value of attribute effective_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#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.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #headers_hash ⇒ Object
-
#initialize(params = {}) ⇒ Response
constructor
A new instance of Response.
- #modified? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/typhoeus/response.rb', line 9 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 |
Instance Attribute Details
#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 |
#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 |
#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 |
#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
#headers_hash ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/typhoeus/response.rb', line 21 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 |
#modified? ⇒ Boolean
45 46 47 |
# File 'lib/typhoeus/response.rb', line 45 def modified? @code != 304 end |
#success? ⇒ Boolean
41 42 43 |
# File 'lib/typhoeus/response.rb', line 41 def success? @code >= 200 && @code < 300 end |