Class: Rubicante::Website
- Inherits:
-
Object
- Object
- Rubicante::Website
- Defined in:
- lib/rubicante/website.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ Website
constructor
A new instance of Website.
-
#is_ok? ⇒ Boolean
Determines whether or not the site OK based on the HTTP Status code.
-
#response_code ⇒ Object
Performs and HTTP GET on the URL’s root (‘/’) and returns the HTTP Status code.
-
#wrong? ⇒ Boolean
Checks to see if the site is OK.
Constructor Details
#initialize(url) ⇒ Website
Returns a new instance of Website.
10 11 12 13 14 |
# File 'lib/rubicante/website.rb', line 10 def initialize(url) @url = url @log = Logging.logger[self] end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/rubicante/website.rb', line 8 def url @url end |
Instance Method Details
#is_ok? ⇒ Boolean
Determines whether or not the site OK based on the HTTP Status code
DETERMINING IF A SITE IS OK
When performing an HTTP GET on the root, if a 2xx (HTTP OK) or 3xx (HTTP Redirect) response is received, the method considers the site to be workinging nominally and returns true
However, if a 4xx (HTTP Client Error) or 5xx (HTTP Server Error) response is received, the method considers the site to be working abnormally and returns false
27 28 29 30 31 32 33 |
# File 'lib/rubicante/website.rb', line 27 def is_ok? result = false result = true if response_code.match(/^(2|3)/) return result end |
#response_code ⇒ Object
Performs and HTTP GET on the URL’s root (‘/’) and returns the HTTP Status code
37 38 39 40 41 42 43 |
# File 'lib/rubicante/website.rb', line 37 def response_code @log.debug "Retreiving HTTP Code for website '#{@url}'" result = Net::HTTP.get_response(@url, '/').code @log.debug "Received HTTP Code #{result} for website '#{@url}'" return result end |
#wrong? ⇒ Boolean
Checks to see if the site is OK. If it is not, it returns a Rubicante::WebsiteError
47 48 49 50 51 52 |
# File 'lib/rubicante/website.rb', line 47 def wrong? @log.debug "Checking website '#{@url}' for problems" if not self.is_ok? WebsiteError.new(@url, self.response_code) end end |