Class: ActiveScraper::ResponseObject::Basic
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveScraper::ResponseObject::Basic
- Defined in:
- lib/active_scraper/response_object/basic.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions.
-
#code ⇒ Object
readonly
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions.
-
#content_type ⇒ Object
readonly
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions.
-
#headers ⇒ Object
readonly
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(obj) ⇒ Basic
constructor
A new instance of Basic.
- #nil? ⇒ Boolean
Constructor Details
#initialize(obj) ⇒ Basic
Returns a new instance of Basic.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/active_scraper/response_object/basic.rb', line 10 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::CachedResponse) @body = obj.body @content_type = obj.content_type @headers = obj.headers @code = obj.code.to_i elsif obj.is_a?(StringIO) && obj.respond_to?(:meta) # OpenURI.open @body = obj.read @content_type = obj.content_type @headers = obj. @code = obj.status[0].to_i elsif obj.nil? # just do nothing else # other types have to raise an Error raise ArgumentError, 'Improper class type' end super(ActiveSupport::HashWithIndifferentAccess.new() ) def empty? @body.empty? end def nil? @body.nil? end # 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)
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions
8 9 10 |
# File 'lib/active_scraper/response_object/basic.rb', line 8 def body @body end |
#code ⇒ Object (readonly)
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions
8 9 10 |
# File 'lib/active_scraper/response_object/basic.rb', line 8 def code @code end |
#content_type ⇒ Object (readonly)
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions
8 9 10 |
# File 'lib/active_scraper/response_object/basic.rb', line 8 def content_type @content_type end |
#headers ⇒ Object (readonly)
I don’t really know what to name this but this is passed between the various classes, including the Fetcher, and is expected to behave the same in those interactions
8 9 10 |
# File 'lib/active_scraper/response_object/basic.rb', line 8 def headers @headers end |
Instance Method Details
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/active_scraper/response_object/basic.rb', line 40 def empty? @body.empty? end |
#nil? ⇒ Boolean
44 45 46 |
# File 'lib/active_scraper/response_object/basic.rb', line 44 def nil? @body.nil? end |