Sha256: d4423c971c3263b4866db89cb37cfa3788d9fd24604a1074d879240cb8ef62c6

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

require 'rubygems'

require 'cgi'
require 'curb'

module GoogleBlogPingingService

  class Request
    SERVICE_URI = "http://blogsearch.google.com/ping"

    def initialize(name, uri, changes_url=nil)
      @params      = {
        'name' => name,
        'url'  => uri
      }
      @params['changesUrl'] = changes_url if changes_url
    end

    def query_string
      elements = []
      @params.keys.size.times do |i|
        elements << "#{@params.keys[i]}=#{CGI::escape(@params.values[i])}"
      end
      elements.join('&')
    end

    def perform
      c = Curl::Easy.new("#{SERVICE_URI}?#{query_string}") do |curl|
        curl.verbose = true
      end
      c.perform
      
      return c.body_str == 'Thanks for the ping.'
    end
  end

  def self.ping(name, uri, changes_url=nil)
    Request.new(name, uri, changes_url).perform
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teejayvanslyke-google-blog-pinging-service-0.1.0 lib/google-blog-pinging-service.rb