class Wpxf::Net::HttpResponse

A response from a request made by a HttpClient.

Attributes

body[RW]

@return [String] the response body.

code[RW]

@return [Integer] the HTTP status code.

cookies[RW]

@return [Hash] a {CookieJar} with all returned cookies.

headers[RW]

@return [Hash] a hash of all returned headers.

timed_out[RW]

@return [Boolean] a boolean that indicates whether a request timed out.

Public Class Methods

new(res) click to toggle source

@param res [Object] a response to parse.

# File lib/wpxf/net/http_response.rb, line 8
def initialize(res)
  parse_typhoeus_response(res) if res.is_a? Typhoeus::Response
end

Public Instance Methods

parse_typhoeus_response(res) click to toggle source

Parse a Typhoeus response into the object. @param res [Typhoeus::Response] the response object to parse. @return [nil]

# 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.cookies = CookieJar.new.parse(res.headers['Set-Cookie']) if res.headers
end
timed_out?() click to toggle source

@return [Boolean] a boolean that indicates whether a request timed out.

# File lib/wpxf/net/http_response.rb, line 24
def timed_out?
  timed_out
end