Created
January 24, 2012 06:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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