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
-
#homepage_res ⇒ Typhoeus::Response
As webmock does not support redirects mocking, coverage is ignored :nocov:.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #access_forbidden?(path = nil) ⇒ Boolean
- #homepage_url ⇒ String
- #http_auth?(path = nil) ⇒ Boolean
-
#initialize(site_url, opts = {}) ⇒ WebSite
constructor
A new instance of WebSite.
-
#online?(path = nil) ⇒ Boolean
Checks if the remote website is up.
- #proxy_auth?(path = nil) ⇒ Boolean
-
#redirection(url = nil) ⇒ String
As webmock does not support redirects mocking, coverage is ignored :nocov:.
-
#url(path = nil) ⇒ String
Used for convenience.
- #url=(site_url) ⇒ Object
Constructor Details
#initialize(site_url, opts = {}) ⇒ WebSite
Returns a new instance of WebSite.
8 9 10 11 |
# File 'lib/cms_scanner/web_site.rb', line 8 def initialize(site_url, opts = {}) self.url = site_url.dup @opts = opts end |
Instance Attribute Details
#homepage_res ⇒ Typhoeus::Response
As webmock does not support redirects mocking, coverage is ignored :nocov:
45 46 47 |
# File 'lib/cms_scanner/web_site.rb', line 45 def homepage_res @homepage_res ||= NS::Browser.get_and_follow_location(url) end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/cms_scanner/web_site.rb', line 4 def opts @opts end |
#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
#access_forbidden?(path = nil) ⇒ Boolean
74 75 76 |
# File 'lib/cms_scanner/web_site.rb', line 74 def access_forbidden?(path = nil) NS::Browser.get(url(path)).code == 403 end |
#homepage_url ⇒ String
51 52 53 |
# File 'lib/cms_scanner/web_site.rb', line 51 def homepage_url @homepage_url ||= homepage_res.effective_url end |
#http_auth?(path = nil) ⇒ Boolean
67 68 69 |
# File 'lib/cms_scanner/web_site.rb', line 67 def http_auth?(path = nil) NS::Browser.get(url(path)).code == 401 end |
#online?(path = nil) ⇒ Boolean
Checks if the remote website is up.
60 61 62 |
# File 'lib/cms_scanner/web_site.rb', line 60 def online?(path = nil) NS::Browser.get(url(path)).code != 0 end |
#proxy_auth?(path = nil) ⇒ Boolean
81 82 83 |
# File 'lib/cms_scanner/web_site.rb', line 81 def proxy_auth?(path = nil) NS::Browser.get(url(path)).code == 407 end |
#redirection(url = nil) ⇒ String
As webmock does not support redirects mocking, coverage is ignored :nocov:
91 92 93 94 95 96 97 98 99 |
# File 'lib/cms_scanner/web_site.rb', line 91 def redirection(url = nil) url ||= @uri.to_s return unless [301, 302].include?(NS::Browser.get(url).code) res = NS::Browser.get(url, followlocation: true) res.effective_url == url ? nil : res.effective_url end |
#url(path = nil) ⇒ String
Used for convenience
URI.encode is preferered over Addressable::URI.encode as it will encode leading # character: URI.encode(‘#t#’) => %23t%23 Addressable::URI.encode(‘#t#’) => #t%23
33 34 35 36 37 |
# File 'lib/cms_scanner/web_site.rb', line 33 def url(path = nil) return @uri.to_s unless path @uri.join(URI.encode(path)).to_s end |
#url=(site_url) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cms_scanner/web_site.rb', line 13 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).normalize end |