Skip to content

Instantly share code, notes, and snippets.

@mfojtik
Created May 3, 2011 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfojtik/953252 to your computer and use it in GitHub Desktop.
Save mfojtik/953252 to your computer and use it in GitHub Desktop.
Using bit.ly API to shorten URL
class Bitly
attr_reader :client
def initialize(username, password)
@username, @password = username, password
@client = RestClient::Resource.new('http://api.bitly.com/v3')
end
def shorten(url)
params = default_params.merge(:longUrl => url)
JSON::parse(@client['shorten'].post(params))['data']['url']
end
private
def default_params
{
:format => 'json',
:login => @username,
:apiKey => @password
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment