Add link validation script using in-house logic

This commit is contained in:
Dave Machado 2017-07-11 00:21:32 -04:00
parent 2d3bace616
commit 80e8997d86
3 changed files with 86 additions and 4 deletions

33
build/validate_links.rb Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env ruby
require 'faraday'
require 'uri'
allowed_codes = [200, 302, 403]
args = ARGV
filename = args[0]
fail_flag = false
contents = File.open(filename, 'rb') { |f| f.read }
links = URI.extract(contents, ['http', 'https'])
dup = links.select{|element| links.count(element) > 1 }
if dup.uniq.length > 0
dup.uniq.each do |link|
if link.end_with?(')')
puts link[0...-1]
end
end
exit(1)
end
links.each do |link|
if link.end_with?(')')
link = link[0...-1]
end
res = Faraday.get(link)
if !allowed_codes.include?(res.status)
puts "(#{res.status}): #{link}"
fail_flag = true
end
end
if fail_flag
exit(1)
else
exit(0)
end