Using With Ruby and HTTParty

Google URL shortening service now has an API.

I had totally missed that Google recently opened the API of their URL shortening service. I love short and clean APIs. Accessing it using HTTParty is just few lines of code.

require "rubygems"
require "httparty"
require "json"

class Googl
  include HTTParty
  base_uri ""
  headers  "Content-Type" => "application/json"

  def self.shorten(url)
    post("/urlshortener/v1/url", :body => {:longUrl => url}.to_json)["id"]

puts Googl.shorten("")

Related articles: Using With HTTParty, Using With HTTParty.

Posted in Ruby  on 20 Feb 2011.