Sha256: da5fea5bf19f0c057f8ff9e527df42db1bdfb778e25d2e79a6d80a21ffb036b3

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

# Copyright (c) 2012, SoundCloud Ltd., Tobias Bielohlawek

require 'cgi'
require 'open-uri'

# Ping Search Engines to pull the latest update
module MassiveSitemap
  ENGINES_URLS = {
    :google => 'http://www.google.com/webmasters/tools/ping?sitemap=%s',
    :bing   => 'http://www.bing.com/webmaster/ping.aspx?siteMap=%s',
    :ask    => 'http://submissions.ask.com/ping?sitemap=%s',
  }

  def ping(url, engines = ENGINES_URLS.keys)
    url =  verify_and_escape(url)

    Array(engines).each do |engine|
      if engine_url = ENGINES_URLS[engine]
        open(engine_url % url)
      end
    end
  end
  module_function :ping

  private
  def verify_and_escape(url)
    schema, host, path = url.scan(/^(https?:\/\/)?(.+?)(\/.+)$/).flatten
    raise URI::InvalidURIError, url if path.to_s.empty?
    CGI::escape("#{schema || 'http://'}#{host}#{path}")
  end
  module_function :verify_and_escape
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_sitemap-2.0.0 lib/massive_sitemap/ping.rb
massive_sitemap-2.0.0.rc8 lib/massive_sitemap/ping.rb
massive_sitemap-2.0.0.rc7 lib/massive_sitemap/ping.rb