Using Bit.ly With HTTParty

Blog Projects
ruby

I have been playing around with different shortener APIs for Google Analytics URL shortener. HTTParty makes this all easy and gives warm fuzzy feeling. Bit.ly 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 "api.bit.ly"

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

  def self.shorten(url)
    get("/v3/shorten?login=#{@@login}&apiKey=#{@@api_key}&longUrl=#{url}")
  end
end

puts Bitly.shorten("http://www.appelsiini.net/")["data"]["url"]

Related articles: Using Shrt.st With HTTParty.



When asking a question please include an URL to example page where the problem occurs. If you have longer code examples please use pastie.org.
CATEGORIES
Built using the awesome Flat UI Pro framework by Designmodo.

© 2013 Mika Tuupola.