Class: ActiveScraper::AgnosticResponseObject
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveScraper::AgnosticResponseObject
- Defined in:
- app/models/active_scraper/agnostic_response_object.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(obj) ⇒ AgnosticResponseObject
constructor
A new instance of AgnosticResponseObject.
Constructor Details
#initialize(obj) ⇒ AgnosticResponseObject
Returns a new instance of AgnosticResponseObject.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/active_scraper/agnostic_response_object.rb', line 6 def initialize(obj) if obj.class == (HTTParty::Response) # use the Net::HTTPResponse instead obj = obj.response end response_obj = if obj.is_a?(Net::HTTPResponse) @body = obj.body @content_type = obj.content_type @headers = obj.each_header.inject({}){|h, (k, v)| h[k] = v; h } @code = obj.code.to_i elsif obj.is_a?(ActiveScraper::Request) @body = obj.body @content_type = obj.content_type @headers = obj.headers @code = obj.code.to_i else # this is probably not used @body = obj.to_s @headers = {} @content_type = nil @code = nil end super({}) # now set its values [:body, :headers, :content_type, :code].each do |a| self[a] = self.send(a) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'app/models/active_scraper/agnostic_response_object.rb', line 4 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'app/models/active_scraper/agnostic_response_object.rb', line 4 def code @code end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
4 5 6 |
# File 'app/models/active_scraper/agnostic_response_object.rb', line 4 def content_type @content_type end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'app/models/active_scraper/agnostic_response_object.rb', line 4 def headers @headers end |