Simple weblogUpdates.ping client in Rails

Almost every Rails app I’ve worked on has had some kind of blog component. Not only are blogs an easy way to keep your site updated, but it also brings in search engine traffic. One of the best ways to get your blog indexed fairly quickly is by using ping services such as Technorati. These services come by after you ping them and read your RSS feed, indexing your content and ultimately getting your site out in front of a lot of people.

Luckily Rails comes with a built in XMLRPC client, so adding in ping functionality to your app is dead easy. Below is a snippet I use regularly. You can change out the listed services to include any of these ping services. I choose Technorati and Google first, and add in any others that might be more specific to the type of site I’m developing.

  def xmlrpc_ping
    services = ["http://rpc.technorati.com/rpc/ping","http://blogsearch.google.com/ping/RPC2"]
    services.each{|service|
      begin
        server = XMLRPC::Client.new2(service)
        server.call2('weblogUpdates.ping',"My Blog",'http://www.myblog.com')
      rescue => detail
        logger.info("ping failed for server #{service} (#{detail})")
      end
    }
  end

You may choose to set your ping service list and ping parameters in your environment file. Or, set it to pull from a database so you or your client can edit them through a browser.

  PING_SERVICES = ["http://rpc.technorati.com/rpc/ping","http://blogsearch.google.com/ping/RPC2"]
  PING_BLOG_NAME = 'My Blog'
  PING_BLOG_URL = 'http://www.myblog.com'

Then rewrite the method:

  def xmlrpc_ping
    PING_SERVICES.each{|service|
      begin
        server = XMLRPC::Client.new2(service)
        server.call2('weblogUpdates.ping',PING_BLOG_NAME,PING_BLOG_URL)
      rescue => detail
        logger.info("ping failed for server #{service} (#{detail})")
      end
    }
  end

0 Responses to “Simple weblogUpdates.ping client in Rails”


  1. No Comments

Leave a Reply