Class: Wgit::Response
- Inherits:
-
Object
- Object
- Wgit::Response
- Defined in:
- lib/wgit/response.rb
Overview
Response class modeling a generic HTTP GET response.
Instance Attribute Summary collapse
-
#adapter_response ⇒ Object
The underlying HTTP adapter/library response object.
-
#body ⇒ Object
(also: #content, #to_s)
The HTML response body.
-
#headers ⇒ Object
The HTTP response headers.
-
#ip_address ⇒ Object
The servers IP address.
-
#redirections ⇒ Object
(also: #redirects)
readonly
The redirections of the response.
-
#status ⇒ Object
(also: #code)
The HTTP response status code.
-
#total_time ⇒ Object
(also: #crawl_duration)
readonly
The total crawl/network time for the response.
-
#url ⇒ Object
The HTTP request URL.
Instance Method Summary collapse
-
#add_total_time(time) ⇒ Float
Adds time to @total_time (incrementally).
-
#body_or_nil ⇒ String, NilClass
Returns the HTML response body or nil (if it's empty).
-
#failure? ⇒ Boolean
Returns whether or not a server response is absent.
-
#initialize ⇒ Response
constructor
Defaults some values and returns a "blank" Wgit::Response object.
-
#inspect ⇒ String
Overrides String#inspect to shorten the printed output of a Response.
-
#no_index? ⇒ Boolean
Returns whether or not Wgit is banned from indexing this site.
-
#not_found? ⇒ Boolean
Returns whether or not the response is 404 Not Found.
-
#ok? ⇒ Boolean
Returns whether or not the response is 200 OK.
-
#redirect? ⇒ Boolean
Returns whether or not the response is a 3xx Redirect.
-
#redirect_count ⇒ Integer
Returns the number of redirects this response has had.
-
#size ⇒ Integer
(also: #length)
Returns the size of the response body.
-
#success? ⇒ Boolean
Returns whether or not a server response is present.
Constructor Details
#initialize ⇒ Response
Defaults some values and returns a "blank" Wgit::Response object.
29 30 31 32 33 34 |
# File 'lib/wgit/response.rb', line 29 def initialize @body = "" @headers = {} @redirections = {} @total_time = 0.0 end |
Instance Attribute Details
#adapter_response ⇒ Object
The underlying HTTP adapter/library response object.
5 6 7 |
# File 'lib/wgit/response.rb', line 5 def adapter_response @adapter_response end |
#body ⇒ Object Also known as: content, to_s
The HTML response body.
8 9 10 |
# File 'lib/wgit/response.rb', line 8 def body @body end |
#headers ⇒ Object
The HTTP response headers.
11 12 13 |
# File 'lib/wgit/response.rb', line 11 def headers @headers end |
#ip_address ⇒ Object
The servers IP address.
14 15 16 |
# File 'lib/wgit/response.rb', line 14 def ip_address @ip_address end |
#redirections ⇒ Object (readonly) Also known as: redirects
The redirections of the response.
17 18 19 |
# File 'lib/wgit/response.rb', line 17 def redirections @redirections end |
#status ⇒ Object Also known as: code
The HTTP response status code.
20 21 22 |
# File 'lib/wgit/response.rb', line 20 def status @status end |
#total_time ⇒ Object (readonly) Also known as: crawl_duration
The total crawl/network time for the response.
23 24 25 |
# File 'lib/wgit/response.rb', line 23 def total_time @total_time end |
#url ⇒ Object
The HTTP request URL.
26 27 28 |
# File 'lib/wgit/response.rb', line 26 def url @url end |
Instance Method Details
#add_total_time(time) ⇒ Float
Adds time to @total_time (incrementally).
47 48 49 |
# File 'lib/wgit/response.rb', line 47 def add_total_time(time) @total_time += time || 0.0 end |
#body_or_nil ⇒ String, NilClass
Returns the HTML response body or nil (if it's empty).
62 63 64 |
# File 'lib/wgit/response.rb', line 62 def body_or_nil @body.empty? ? nil : @body end |
#failure? ⇒ Boolean
Returns whether or not a server response is absent.
69 70 71 |
# File 'lib/wgit/response.rb', line 69 def failure? !success? end |
#inspect ⇒ String
Overrides String#inspect to shorten the printed output of a Response.
39 40 41 |
# File 'lib/wgit/response.rb', line 39 def inspect "#<Wgit::Response url=\"#{@url}\" status=#{status}>" end |
#no_index? ⇒ Boolean
Returns whether or not Wgit is banned from indexing this site.
145 146 147 |
# File 'lib/wgit/response.rb', line 145 def no_index? headers.fetch(:x_robots_tag, "").downcase.strip == "noindex" end |
#not_found? ⇒ Boolean
Returns whether or not the response is 404 Not Found.
90 91 92 |
# File 'lib/wgit/response.rb', line 90 def not_found? @status == 404 end |
#ok? ⇒ Boolean
Returns whether or not the response is 200 OK.
97 98 99 |
# File 'lib/wgit/response.rb', line 97 def ok? @status == 200 end |
#redirect? ⇒ Boolean
Returns whether or not the response is a 3xx Redirect.
104 105 106 107 108 |
# File 'lib/wgit/response.rb', line 104 def redirect? return false unless @status @status.between?(300, 399) end |
#redirect_count ⇒ Integer
Returns the number of redirects this response has had.
113 114 115 |
# File 'lib/wgit/response.rb', line 113 def redirect_count @redirections.size end |
#size ⇒ Integer Also known as: length
Returns the size of the response body.
120 121 122 |
# File 'lib/wgit/response.rb', line 120 def size @body.size end |
#success? ⇒ Boolean
Returns whether or not a server response is present.
135 136 137 138 139 |
# File 'lib/wgit/response.rb', line 135 def success? return false unless @status @status.positive? end |