Class: Net::HTTPOK

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_grabber/http.rb

Overview

Success response class

Instance Method Summary collapse

Instance Method Details

#cookiesObject

Response Cookies



20
21
22
23
# File 'lib/tiny_grabber/http.rb', line 20

def cookies
  cookies = get_fields('set-cookie')
  cookies.map { |cookie| cookie.gsub(/\A([^;]+).*\Z/, '\1') }.join('&') if cookies
end

#headersObject

Response Headers



27
28
29
30
31
# File 'lib/tiny_grabber/http.rb', line 27

def headers
  header.to_hash.each_with_object({}) do |header_key, header_value|
    header_value[header_key] = header_value.first
  end
end

#ng(html_version = 4) ⇒ Object

Nokogiri object of response



10
11
12
13
14
15
16
# File 'lib/tiny_grabber/http.rb', line 10

def ng(html_version = 4)
  if html_version == 5
    Nokogiri::HTML5(body)
  else
    body.encoding.to_s != 'UTF-8' ? Nokogiri::HTML(body, 'UTF-8') : Nokogiri::HTML(body)
  end
end