lib/dynamic_sitemaps/pinger.rb in dynamic_sitemaps-2.0.0.beta vs lib/dynamic_sitemaps/pinger.rb in dynamic_sitemaps-2.0.0.beta2
- old
+ new
@@ -1,18 +1,19 @@
module DynamicSitemaps
class Pinger
class << self
- def ping_search_engines
- sitemap_urls = DynamicSitemaps.sitemap_ping_urls
- if sitemap_urls.any?
- puts "Pinging search engines..."
+ def ping_search_engines_with(sitemap_urls)
+ sitemap_urls = [sitemap_urls] unless sitemap_urls.is_a?(Array)
+ if sitemap_urls.any? && ping_for_environment?(Rails.env)
+ Logger.info "Pinging search engines..."
+
sitemap_urls.each do |url|
ping_search_engines_with_sitemap_url url
end
- puts "Done pinging search engines."
+ Logger.info "Done pinging search engines."
end
end
def ping_search_engines_with_sitemap_url(sitemap_url)
sitemap_url = CGI::escape(sitemap_url)
@@ -21,15 +22,19 @@
ping url
end
end
def ping(url)
- puts "Pinging #{url} ..."
+ Logger.info "Pinging #{url} ..."
begin
Net::HTTP.get(URI.parse(url))
rescue Exception => e
- puts "Failed to ping #{url} : #{e}"
+ Logger.warn "Failed to ping #{url} : #{e}"
end
+ end
+
+ def ping_for_environment?(env)
+ DynamicSitemaps.ping_environments.map(&:to_s).include?(env.to_s)
end
end
end
end
\ No newline at end of file