Skip to content

Instantly share code, notes, and snippets.

@bmc
Created April 1, 2011 21:21
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 bmc/898883 to your computer and use it in GitHub Desktop.
Save bmc/898883 to your computer and use it in GitHub Desktop.
Access goo.gl from Ruby
# 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 = 'some.user@gmail.com'
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