lib/awesome_bot/statuses.rb in awesome_bot-1.0.0 vs lib/awesome_bot/statuses.rb in awesome_bot-1.1.0
- old
+ new
@@ -2,20 +2,31 @@
module AwesomeBot
require 'faraday'
require 'parallel'
class << self
- def net_status(url)
+ def net_head_status(url)
+ Faraday.head(url).status
+ end
+
+ def net_get_status(url)
Faraday.get(url).status
end
- def statuses(links, threads, verbose, status_ok, status_other)
+ def net_status(url, head)
+ head ? net_head_status(url) : net_get_status(url)
+ end
+
+ def statuses(links, threads, head = false)
statuses = []
Parallel.each(links, in_threads: threads) do |u|
- status = net_status u
+ begin
+ status = net_status u, head
+ rescue => e
+ status = e
+ end
- print(status == 200 ? status_ok : status_other) if verbose
-
+ yield status, u
statuses.push('url' => u, 'status' => status)
end # Parallel
statuses
end