jeremyw / tinify_urls forked from patientslikeme/tinify_urls

A Rails plugin that provides a simple API to shorten URLs using popular web services like bit.ly, tinyurl, snipurl, and is.gd.

This URL has Read+Write access

README.rdoc

TinifyUrls

A Rails plugin that makes it easy to convert long URLs to shorter ones using popular services like TinyURL, SnipURL, and is.gd.

Configuration

Uses TinyURL by default, but you can pass :bitly, :snipurl, or :is_gd to the Tinifier constructor, or override the default in an initializer. Note that bit.ly requires your login and API key:

  # config/initializers/tinifier.rb
  Tinifier.default_api = :bitly
  Tinifier.api_user    = 'bitlyapidemo'
  Tinifier.api_key     = 'R_0da49e0a9118ff35f52f629d2d71bf07'

Examples

  t = Tinifier.new # using TinyURL by default

  # shorten a single URL
  puts t.tinify_url('http://www.patientslikeme.com')

  # or shorten every URL in a string
  puts t.tinify_urls('Please visit http://www.patientslikeme.com to learn more.')

View helpers are also provided:

  <%= link_to tinify_url('http://www.patientslikeme.com', :snipurl) %>

You can also pass a block to implement custom URL shortening logic. A practical example is to cache URLs, avoiding extra expensive API invocations:

  <%= link_to tinify_url('http://www.patientslikeme.com') { |url| UrlCache.for_full_url(url) } %>

Copyright © 2009 PatientsLikeMe, Inc., released under the MIT license