Class: Linksta::Getter

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

Instance Method Summary collapse

Constructor Details

#initialize(paths, base, concurrency, status, headers) ⇒ Getter

Returns a new instance of Getter.



80
81
82
83
84
85
86
87
# File 'lib/linksta.rb', line 80

def initialize(paths, base, concurrency, status, headers)
  @paths       = paths
  @base        = base
  @headers     = headers
  @status      = status

  @hydra = Typhoeus::Hydra.new(:max_concurrency => concurrency)
end

Instance Method Details

#checkObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/linksta.rb', line 89

def check
  puts "Checking..."

  paths.each do |path|
    begin
      Typhoeus::Request.new(url(path), options).tap do |req|
        req.on_complete { |r| parse_response(r, status) }
        hydra.queue req
      end
    rescue URI::InvalidURIError
      puts "Error with URL #{path}, please check config."
    end
  end

  hydra.run
  check_for_broken
end