Skip to content

Commit

Permalink
Merge pull request #7 from indyarocks/main_private_method
Browse files Browse the repository at this point in the history
fixed the private method access
  • Loading branch information
indyarocks authored May 30, 2023
2 parents 28dfde8 + 6aed9b6 commit 04f4160
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/spec/reports/
/tmp/
/vendor/bundle
/.idea

# rspec failure tracking
.rspec_status
47 changes: 24 additions & 23 deletions lib/final_redirect_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,34 @@ def self.final_redirect_url(url, options={})
final_url
end

private
def self.is_valid_url?(url)
url.to_s.match? URI::regexp(['http', 'https'])
end
class << self
def self.is_valid_url?(url)
url.to_s.match? URI::regexp(['http', 'https'])
end

def self.get_final_redirect_url(url, limit = 10)
return url if limit <= 0
uri = URI.parse(url)
response = ::Net::HTTP.get_response(uri)
if response.class == Net::HTTPOK
return uri
else
redirect_location = response['location']
location_uri = URI.parse(redirect_location)
if location_uri.host.nil?
redirect_location = uri.scheme + '://' + uri.host + redirect_location
def self.get_final_redirect_url(url, limit = 10)
return url if limit <= 0
uri = URI.parse(url)
response = ::Net::HTTP.get_response(uri)
if response.class == Net::HTTPOK
return uri
else
redirect_location = response['location']
location_uri = URI.parse(redirect_location)
if location_uri.host.nil?
redirect_location = uri.scheme + '://' + uri.host + redirect_location
end
warn "redirected to #{redirect_location}"
get_final_redirect_url(redirect_location, limit - 1)
end
warn "redirected to #{redirect_location}"
get_final_redirect_url(redirect_location, limit - 1)
end
end

def self.url_string_from_uri(uri)
url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
if uri.fragment
url_str = url_str + "##{uri.fragment}"
def self.url_string_from_uri(uri)
url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
if uri.fragment
url_str = url_str + "##{uri.fragment}"
end
url_str
end
url_str
end
end

0 comments on commit 04f4160

Please sign in to comment.