Class: CMSScanner::WebSite
- Inherits:
-
Object
- Object
- CMSScanner::WebSite
- Defined in:
- lib/cms_scanner/web_site.rb
Overview
WebSite Implementation
Direct Known Subclasses
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #http_auth? ⇒ Boolean
-
#initialize(site_url) ⇒ WebSite
constructor
A new instance of WebSite.
-
#online? ⇒ Boolean
Checks if the remote website is up.
- #proxy_auth? ⇒ Boolean
-
#redirection(url = nil) ⇒ String
See if the remote url returns 30x redirect This method is recursive.
-
#url(path = nil) ⇒ String
Used for convenience.
- #url=(site_url) ⇒ Object
Constructor Details
#initialize(site_url) ⇒ WebSite
Returns a new instance of WebSite.
6 7 8 |
# File 'lib/cms_scanner/web_site.rb', line 6 def initialize(site_url) self.url = site_url.dup end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
4 5 6 |
# File 'lib/cms_scanner/web_site.rb', line 4 def uri @uri end |
Instance Method Details
#http_auth? ⇒ Boolean
37 38 39 |
# File 'lib/cms_scanner/web_site.rb', line 37 def http_auth? NS::Browser.get(url).code == 401 end |
#online? ⇒ Boolean
Checks if the remote website is up.
32 33 34 |
# File 'lib/cms_scanner/web_site.rb', line 32 def online? NS::Browser.get(url).code != 0 end |
#proxy_auth? ⇒ Boolean
42 43 44 |
# File 'lib/cms_scanner/web_site.rb', line 42 def proxy_auth? NS::Browser.get(url).code == 407 end |
#redirection(url = nil) ⇒ String
See if the remote url returns 30x redirect This method is recursive
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cms_scanner/web_site.rb', line 52 def redirection(url = nil) url ||= @uri.to_s response = NS::Browser.get(url) if response.code == 301 || response.code == 302 redirection = response.headers_hash['location'] # Let's check if there is a redirection in the redirection if (other_redirection = redirection(redirection)) redirection = other_redirection end end redirection end |
#url(path = nil) ⇒ String
Used for convenience
25 26 27 |
# File 'lib/cms_scanner/web_site.rb', line 25 def url(path = nil) @uri.join(path || '').to_s end |
#url=(site_url) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/cms_scanner/web_site.rb', line 10 def url=(site_url) # Add a trailing slash to the site url site_url << '/' if site_url[-1, 1] != '/' # Use the validator to ensure the site_url has a correct format OptParseValidator::OptURL.new([]).validate(site_url) @uri = Addressable::URI.parse(site_url) end |