Using With HTTParty

Blog Projects

I have been playing around with different shortener APIs for Google Analytics URL shortener. HTTParty makes this all easy and gives warm fuzzy feeling. API requires free registration to get an API key. Other than that it is pretty straight forward to use.

require "rubygems"
require "httparty"

class Bitly
  include HTTParty
  base_uri ""

  @@login   = "username"
  @@api_key = "R_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  def self.shorten(url)

puts Bitly.shorten("")["data"]["url"]

Related articles: Using With HTTParty.

When asking a question include an URL to example page where the problem occurs. Even better is to make a Fiddle which demonstrates the problem. If you have longer code examples please use