Class: Linkey::Getter

Inherits:
Object
  • Object
show all
Defined in:
lib/linkey.rb

Class Method Summary collapse

Class Method Details

.check_for_brokenObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/linkey.rb', line 99

def self.check_for_broken
  puts "Checking"
  if @output.empty?
    puts 'URL\'s are good, All Done!'
    exit 0
  else
    puts "Buddy, you got a broken link"
    puts @output
    exit 1
  end
end

.make_request(page_path, base, status, status_code) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/linkey.rb', line 90

def self.make_request(page_path, base, status, status_code)
  if status != status_code
    puts "Status is NOT GOOD for #{base}#{page_path}, response is #{status}"
    @output << page_path
  else
    puts "Status is #{status} for #{base}#{page_path}"
  end
end

.status(urls, base, headers = {}, status_code = 200) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/linkey.rb', line 75

def self.status(urls, base, headers = {}, status_code = 200)
  @output = []
  puts "Checking..."

  Parallel.each(urls, :in_threads => 4) do |page_path|
    request = Faraday.new(:url => base, :ssl => { :verify => false }, :headers => headers[:headers]) do |faraday|
      faraday.use FaradayMiddleware::FollowRedirects
      faraday.adapter :typhoeus
    end
    status = request.get(page_path).status
    make_request(page_path, base, status, status_code)
  end
  check_for_broken
end