Class: VerifyRedirects::Verifier
- Inherits:
-
Object
- Object
- VerifyRedirects::Verifier
- Defined in:
- lib/verify_redirects/verifier.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #call(from_url, expected_to) ⇒ Object
-
#initialize ⇒ Verifier
constructor
A new instance of Verifier.
Constructor Details
#initialize ⇒ Verifier
Returns a new instance of Verifier.
12 13 14 |
# File 'lib/verify_redirects/verifier.rb', line 12 def initialize @results = [] end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
10 11 12 |
# File 'lib/verify_redirects/verifier.rb', line 10 def results @results end |
Instance Method Details
#call(from_url, expected_to) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/verify_redirects/verifier.rb', line 16 def call(from_url, expected_to) url = to_url(from_url) expected_redirect = remove_spaces(expected_to)&.force_encoding('UTF-8') puts "GET #{url}" if debug? response = Http.get(url) # Paths can contain scary characters: 'sa-far-du-ersatt\xE2\x80\xA6marens-flygstrul/' redirected_to = response.headers['Location']&.force_encoding('UTF-8') success = redirected_to == expected_redirect # if both are nil - no redirect is the success case Result.new( success: success, start_url: url, redirected_to: redirected_to, expected_redirect: expected_redirect ).tap { |r| @results << r } end |