mirror of
https://github.com/public-apis/public-apis.git
synced 2025-05-10 07:36:47 +02:00
Add link validation script using in-house logic
This commit is contained in:
parent
2d3bace616
commit
80e8997d86
3 changed files with 86 additions and 4 deletions
33
build/validate_links.rb
Executable file
33
build/validate_links.rb
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue