Skip to content

Instantly share code, notes, and snippets.

@thinkcreate
Created June 9, 2009 12:51
Show Gist options
  • Save thinkcreate/126460 to your computer and use it in GitHub Desktop.
Save thinkcreate/126460 to your computer and use it in GitHub Desktop.
Bitly client
class Bitly
include HTTParty
base_uri 'api.bit.ly'
default_params :version=>'2.0.1'
format :json
def initialize(login, key)
@auth = {:login => login, :apiKey => key}
end
def shorten(url)
options = {:longUrl => url}.merge(@auth)
self.class.get('/shorten', :query => options)['results'].values.first['shortUrl']
end
end
=begin
Usage:
bitly = Bitly.new('login','key')
bitly.shorten('http://railstips.org/2009/6/8/what-is-the-simplest-thing-that-could-possibly-work') #=> "http://bit.ly/EUrKW"
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment