Skip to content

Instantly share code, notes, and snippets.

@samography
Created January 24, 2012 06:18
Show Gist options
  • Select an option

  • Save samography/1668321 to your computer and use it in GitHub Desktop.

Select an option

Save samography/1668321 to your computer and use it in GitHub Desktop.
Quick and dirty Ruby script to shorten URLs via command line using Bitly
# Requires the bitly gem
# gem install bitly
require 'rubygems'
require 'bitly'
# Force gem to use latest bitly API version
Bitly.use_api_version_3
# Requires bitly.com account and API key (http://bitly.com/a/account)
bitly = Bitly.new("[username]", "[API key]")
# Ask for URL
puts "Long URL: "
longurl = gets.chomp.to_s
shorturl = bitly.shorten(longurl)
# Print Shortened URL
puts "Short URL: "
puts shorturl.short_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment