Created
April 1, 2011 21:21
-
-
Save bmc/898883 to your computer and use it in GitHub Desktop.
Access goo.gl from Ruby
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
# Test of Goo.gl Ruby gem. Install via: | |
# | |
# $ gem install googl | |
# | |
# See | |
# http://code.google.com/apis/urlshortener/v1/getting_started.html#shorten | |
# for Goo.gl API info. | |
require 'rubygems' | |
require 'googl' | |
USE_AUTH = false | |
AUTH_USER = '[email protected]' | |
AUTH_PASSWORD = 'user_password' | |
ARGV.each do |url| | |
# Also supports client login authentication | |
if USE_AUTH | |
client = Googl.client(AUTH_USER, AUTH_PASSWORD) | |
shortened = client.shorten(url) | |
else | |
shortened = Googl.shorten url | |
end | |
puts("#{url} -> #{shortened.short_url}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment