Class: Wpxf::Net::HttpResponse
- Inherits:
-
Object
- Object
- Wpxf::Net::HttpResponse
- Defined in:
- lib/wpxf/net/http_response.rb
Overview
A response from a request made by a HttpClient.
Instance Attribute Summary collapse
-
#body ⇒ String
The response body.
-
#code ⇒ Integer
The HTTP status code.
-
#cookies ⇒ Hash
A CookieJar with all returned cookies.
-
#headers ⇒ Hash
A hash of all returned headers.
-
#timed_out ⇒ Boolean
A boolean that indicates whether a request timed out.
Instance Method Summary collapse
-
#initialize(res) ⇒ HttpResponse
constructor
A new instance of HttpResponse.
-
#parse_typhoeus_response(res) ⇒ nil
Parse a Typhoeus response into the object.
-
#timed_out? ⇒ Boolean
A boolean that indicates whether a request timed out.
Constructor Details
#initialize(res) ⇒ HttpResponse
Returns a new instance of HttpResponse
8 9 10 |
# File 'lib/wpxf/net/http_response.rb', line 8 def initialize(res) parse_typhoeus_response(res) if res.is_a? Typhoeus::Response end |
Instance Attribute Details
#body ⇒ String
Returns the response body.
32 33 34 |
# File 'lib/wpxf/net/http_response.rb', line 32 def body @body end |
#code ⇒ Integer
Returns the HTTP status code.
29 30 31 |
# File 'lib/wpxf/net/http_response.rb', line 29 def code @code end |
#cookies ⇒ Hash
Returns a CookieJar with all returned cookies.
41 42 43 |
# File 'lib/wpxf/net/http_response.rb', line 41 def @cookies end |
#headers ⇒ Hash
Returns a hash of all returned headers.
35 36 37 |
# File 'lib/wpxf/net/http_response.rb', line 35 def headers @headers end |
#timed_out ⇒ Boolean
Returns a boolean that indicates whether a request timed out.
38 39 40 |
# File 'lib/wpxf/net/http_response.rb', line 38 def timed_out @timed_out end |
Instance Method Details
#parse_typhoeus_response(res) ⇒ nil
Parse a Typhoeus response into the object.
15 16 17 18 19 20 21 |
# File 'lib/wpxf/net/http_response.rb', line 15 def parse_typhoeus_response(res) self.code = res.code self.body = res.body.nil? ? '' : res.body self.headers = res.headers self.timed_out = res.timed_out? || res.return_code == :couldnt_connect self. = CookieJar.new.parse(res.headers['Set-Cookie']) if res.headers end |
#timed_out? ⇒ Boolean
Returns a boolean that indicates whether a request timed out.
24 25 26 |
# File 'lib/wpxf/net/http_response.rb', line 24 def timed_out? timed_out end |