Class: ContentOMatic::Response
- Inherits:
-
Object
- Object
- ContentOMatic::Response
- Defined in:
- lib/content_o_matic/response.rb
Instance Attribute Summary collapse
-
#body(normalize_assets = false) ⇒ Object
Returns the value of attribute body.
-
#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(normalize_assets = false) ⇒ 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.
9 10 11 12 13 |
# File 'lib/content_o_matic/response.rb', line 9 def initialize(url, status, body = '') self.url = url self.status = status.to_i self.body = body end |
Instance Attribute Details
#body(normalize_assets = false) ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/content_o_matic/response.rb', line 6 def body @body 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
62 63 64 |
# File 'lib/content_o_matic/response.rb', line 62 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
27 28 29 |
# File 'lib/content_o_matic/response.rb', line 27 def has_layout? return self.body != self.html_body end |
#html_body(normalize_assets = false) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/content_o_matic/response.rb', line 53 def html_body(normalize_assets = false) unless @__doc_body doc = Nokogiri::HTML(self.body(normalize_assets)) @__doc_body = doc.at('body') @__doc_body = @__doc_body.nil? ? self.body(normalize_assets) : @__doc_body.inner_html end return @__doc_body end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/content_o_matic/response.rb', line 15 def success? self.status == 200 end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/content_o_matic/response.rb', line 19 def to_s self.success? ? self.body : '' end |
#to_str ⇒ Object
23 24 25 |
# File 'lib/content_o_matic/response.rb', line 23 def to_str self.to_s end |