Class: LCBO::CrawlKit::Response
- Inherits:
-
Object
- Object
- LCBO::CrawlKit::Response
- Defined in:
- lib/lcbo/crawlkit/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_params ⇒ Object
readonly
Returns the value of attribute body_params.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #as_hash ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lcbo/crawlkit/response.rb', line 8 def initialize(response) params = HashExt.symbolize_keys(response) @code = params[:code] @uri = params[:uri] @http_method = params[:http_method] @time = params[:time] @query_params = params[:query_params] @body_params = params[:body_params] @body = self.class.normalize_encoding(params[:body]) ensure_success! end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def body @body end |
#body_params ⇒ Object (readonly)
Returns the value of attribute body_params.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def body_params @body_params end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def code @code end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def http_method @http_method end |
#query_params ⇒ Object (readonly)
Returns the value of attribute query_params.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def query_params @query_params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def response @response end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def time @time end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/lcbo/crawlkit/response.rb', line 5 def uri @uri end |
Class Method Details
.normalize_encoding(html) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/lcbo/crawlkit/response.rb', line 20 def self.normalize_encoding(html) if html.force_encoding('ISO-8859-1').valid_encoding? html.encode('UTF-8', 'ISO-8859-1') else html.encode('UTF-8') end.gsub("\r\n", "\n") end |
Instance Method Details
#as_hash ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/lcbo/crawlkit/response.rb', line 28 def as_hash { :code => code, :uri => uri, :http_method => http_method, :time => time, :query_params => query_params, :body_params => body_params, :body => body } end |