Class: ContentOMatic::Response
- Inherits:
-
Object
- Object
- ContentOMatic::Response
- Defined in:
- lib/content_o_matic/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#hpricot_doc ⇒ Object
Returns the value of attribute hpricot_doc.
-
#status ⇒ Object
Returns the value of attribute status.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #exception ⇒ Object
- #has_layout? ⇒ Boolean
- #html_body ⇒ Object
-
#initialize(url, status, body = '') ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(url, status, body = '') ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 |
# File 'lib/content_o_matic/response.rb', line 10 def initialize(url, status, body = '') self.url = url self.status = status.to_i self.body = body if success? self.hpricot_doc = Hpricot(self.body) end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/content_o_matic/response.rb', line 6 def body @body end |
#hpricot_doc ⇒ Object
Returns the value of attribute hpricot_doc.
8 9 10 |
# File 'lib/content_o_matic/response.rb', line 8 def hpricot_doc @hpricot_doc end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/content_o_matic/response.rb', line 5 def status @status end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/content_o_matic/response.rb', line 7 def url @url end |
Instance Method Details
#exception ⇒ Object
43 44 45 |
# File 'lib/content_o_matic/response.rb', line 43 def exception ContentOMatic::InvalidResponseError.new("URL: '#{self.url}' did not return a valid response! Status: '#{self.status}' Body: '#{self.body}'") unless self.success? end |
#has_layout? ⇒ Boolean
31 32 33 |
# File 'lib/content_o_matic/response.rb', line 31 def has_layout? return self.body != self.html_body end |
#html_body ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/content_o_matic/response.rb', line 35 def html_body unless @__doc_body @__doc_body = self.hpricot_doc.at('body') @__doc_body = @__doc_body.nil? ? self.body : @__doc_body.inner_html end return @__doc_body end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/content_o_matic/response.rb', line 19 def success? self.status == 200 end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/content_o_matic/response.rb', line 23 def to_s self.success? ? self.body : '' end |
#to_str ⇒ Object
27 28 29 |
# File 'lib/content_o_matic/response.rb', line 27 def to_str self.to_s end |